rescript-lang / rescript-lang/rescript
Emitted JS / Gentype double-escapes output
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 7.5k
- Forks
- 485
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 55
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:
This existing test with an escaped double-quote \" in the @as annotation
Results it being double-escaped in the generated typescript types and javascript:
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at compiler/gentype/TranslateTypeDeclarations.ml around line 48, then inspect the @as cases in tests/gentype_tests/typescript-react-example/src/Records.res and their generated .gen.tsx and .res.js outputs. Run the existing gentype test and reproduce both escaped-quote cases. Done means the generated JavaScript and TypeScript do not double-escape the value and the parser accepts the exotic identifier.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, ocaml, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100