Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

bsc.exe on master complains about invalid escape codes in strings while 9.1.4 is fine #473

Closed
kevinbarabash opened this issue Dec 4, 2021 · 3 comments · Fixed by rescript-lang/rescript#5391

Comments

@kevinbarabash
Copy link
Contributor

The following code:

let a = "This prints \"Hello, world!\""

works fine using the published 9.1.4 version, but produces the following error when running bsc.exe compiled from master:

./darwin/bsc.exe test2.res

  We've found a bug for you!
  test2.res:1:9-39

  1 │ let a = "This prints \"Hello, world!\""
  2 │ 

  Offset: 13, Invalid escape code: "

The same happens with escaped single quotes as well.

This also happens for byte escape codes. The following code:

let a = "\000\000\246\255\247\255\
   \000\001\002\003\004\005"

works fine with 9.1.4, but produces the follow error when running bsc.exe compiled from master:

./darwin/bsc.exe test_bytes.res

  We've found a bug for you!
  test_bytes.res:1:9-2:28

  1 │ let a = "\000\000\246\255\247\255\
  2 │    \000\001\002\003\004\005"
  3 │ 

  Offset: 9, Invalid escape code: 2
@kevinbarabash kevinbarabash changed the title Escaping (double) quotes doesn't work on master but does work in the 9.1.2 bsc.exe on master complains about invalid escape codes in strings while 9.1.2 is fine Dec 4, 2021
@kevinbarabash kevinbarabash changed the title bsc.exe on master complains about invalid escape codes in strings while 9.1.2 is fine bsc.exe on master complains about invalid escape codes in strings while 9.1.4 is fine Dec 4, 2021
@bobzhang bobzhang transferred this issue from rescript-lang/rescript Dec 30, 2021
@cknitt
Copy link
Member

cknitt commented May 8, 2022

I just built rescript from master with the latest version of the syntax module and ran into this, too.

@ryyppy This is a regression that we need to fix for the next release. Could you label it as such?

Looking at the AST, "Hello, \"world\"!" currently gives us

PConst_string ("Hello, \\\"world\\\"!",Some "js")

whereas

`Hello, "world"!`

gives us

PConst_string ("Hello, \"world\"!",Some "js")

@IwanKaramazow
Copy link
Contributor

@cknitt I think I know what the problem is. Will add it here to this issue

@cknitt
Copy link
Member

cknitt commented May 8, 2022

@IwanKaramazow Great! Thanks a lot!

IwanKaramazow pushed a commit to rescript-lang/rescript that referenced this issue May 24, 2022
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.
IwanKaramazow pushed a commit to rescript-lang/rescript that referenced this issue May 24, 2022
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.
cristianoc pushed a commit to rescript-lang/rescript that referenced this issue May 26, 2022
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.
mununki pushed a commit to mununki/rescript-compiler that referenced this issue Jul 15, 2022
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.
anmonteiro pushed a commit to melange-re/melange that referenced this issue Jan 11, 2023
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.
anmonteiro pushed a commit to melange-re/melange that referenced this issue Jan 11, 2023
Fixes rescript-lang/syntax#473

The [ecmascript spec](https://tc39.es/ecma262/#prod-CharacterEscapeSequence) states that both `SingleEscapeCharacter` and `NonEscapeCharacter` are valid escape sequences.
Previously escape sequences containing a `NonEscapeCharacter`, any regular char like `a` in`"\a"`, would throw the "Invalid escape code" error.
ReScript strings should have the same semantics as JS.

Co-authored-by: Maxim <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants