syntax
syntax copied to clipboard
Whitespace in strings is literally interpreted when converting from ReasonML to ReScript
Here is some code from my ReasonML project:
let f = input =>
switch (input) {
| Some(value) =>
if (someCondition(value)) {
"\t";
} else if (someOtherCondition(value)) {
"\n";
} else {
"\n\n";
}
| None => "\n\n"
};
(playground link of the same).
After converting to ReScript, the return values within the if branches are translated literally - but the one within the final switch branch is not:
let f = input =>
switch input {
| Some(value) =>
if someCondition(value) {
" "
} else if someOtherCondition(value) {
"
"
} else {
"
"
}
| None => "\n\n"
}
This caused quite a tricky bug in my app. It's not usually compiled on windows but we do compile it there in CI, and this resulted in \n becoming \r\n. It isn't the only place we use those characters and none of the others broke, suggesting the problem is specific to if branches.