-
Notifications
You must be signed in to change notification settings - Fork 476
Description
Thank you for filing! Check list:
- Is it a bug? Usage questions should often be asked in the forum instead.
- Concise, focused, friendly issue title & description.
- A minimal, reproducible example.
- OS and browser versions, if relevant.
- Is it already fixed in master? Instructions
When using the @as attribute with a value containing escape sequences (e.g., @as("with\"dquote")), the generated JavaScript incorrectly double-escapes the string. Additionally the parser can't handle exotic identifiers with a \".
I found this while looking at #8086 and removing String.escaped from this line:
| | Some s -> s |> String.escaped |
This existing test with an escaped double-quote \" in the @as annotation
rescript/tests/gentype_tests/typescript-react-example/src/Records.res
Lines 125 to 139 in 14721cb
| @genType | |
| type myRecBsAs = { | |
| @as("jsValid0") | |
| valid: string, | |
| @as("type") | |
| type_: string, | |
| @as("the-key") | |
| theKey: string, | |
| @as("with\"dquote") | |
| withDQuote: string, | |
| @as("with'squote") | |
| withSQuote: string, | |
| @as("1number") | |
| number1: string, | |
| } |
Results it being double-escaped in the generated typescript types and javascript:
| export type myRecBsAs = { | |
| readonly jsValid0: string; | |
| readonly type: string; | |
| readonly "the-key": string; | |
| readonly "with\\\"dquote": string; | |
| readonly "with'squote": string; | |
| readonly "1number": string | |
| }; |
rescript/tests/gentype_tests/typescript-react-example/src/Records.res.js
Lines 106 to 115 in 14721cb
| function testMyRecBsAs(x) { | |
| return [ | |
| x.jsValid0, | |
| x.type, | |
| x["the-key"], | |
| x["with\\\"dquote"], | |
| x["with'squote"], | |
| x["1number"] | |
| ]; | |
| } |
There's also a parser bug:
Error in @tests/gentype-react-example:
Syntax error!
/rescript-compiler/tests/gentype_tests/typescript-react-example/src/Records.res:135:11-17
133 ┆ @as("with\"dquote")
134 ┆ withDQuote: string,
135 ┆ \"with\"dquote2": string,
136 ┆ @as("with'squote")
137 ┆ withSQuote: string,
Did you forget a `,` here?