syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Differences between escapes in ReScript strings and JavaScript strings

Open kevinbarabash opened this issue 4 years ago • 0 comments

The following escapes differ from standard JS strings:

  • \o escape does nothing in JavaScript strings, "\o123" is interpreted as "o123" in JS
  • decimal escapes in ReScript, e.g. \123, in non-strict mode JS these are treated as octal escapes and in strict-mode JS they are forbidden

For the first one, we should remove any checking we were doing around whether the \o was a valid octal escape. JS treats unknown escapes by stripping the leading \ from the escaped char. I proposed we do the same.

For the second one, we could support JS-style octal escapes in ReScript strings, but I think that might lead to confusion if someone is switching between Ml syntax and Res syntax. If we follow the strict-mode behaviour and only allow \0 then this shouldn't be an issue.

kevinbarabash avatar Dec 05 '21 01:12 kevinbarabash