rescript-lang / rescript-lang/rescript

Emitted JS / Gentype double-escapes output

Aperta
#8,088 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
OCaml
Stelle
7.5k
Fork
485
Merge medio
1g 2h
PR unite (30g)
55

Descrizione

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:

https://github.com/rescript-lang/rescript/blob/14721cb26f727e20fa834dbcce28fb439ad2e006/compiler/gentype/TranslateTypeDeclarations.ml#L48

This existing test with an escaped double-quote \" in the @as annotation

https://github.com/rescript-lang/rescript/blob/14721cb26f727e20fa834dbcce28fb439ad2e006/tests/gentype_tests/typescript-react-example/src/Records.res#L125-L139

Results it being double-escaped in the generated typescript types and javascript:

https://github.com/rescript-lang/rescript/blob/14721cb26f727e20fa834dbcce28fb439ad2e006/tests/gentype_tests/typescript-react-example/src/Records.gen.tsx#L51-L58

https://github.com/rescript-lang/rescript/blob/14721cb26f727e20fa834dbcce28fb439ad2e006/tests/gentype_tests/typescript-react-example/src/Records.res.js#L106-L115


There's also a parser bug:

https://github.com/illusionalsagacity/rescript-compiler/blob/3293dcb812e416afccb0900df933bbbb533578f2/tests/gentype_tests/typescript-react-example/src/Records.res#L125-L142

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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da compiler/gentype/TranslateTypeDeclarations.ml, intorno alla riga 48, poi esamina i casi @as in tests/gentype_tests/typescript-react-example/src/Records.res e i relativi output generati .gen.tsx e .res.js. Esegui il test gentype esistente e riproduci entrambi i casi di virgolette con escape. Il lavoro è completato quando il JavaScript e il TypeScript generati non eseguono un doppio escape del valore e il parser accetta l'identificatore esotico.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, ocaml, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.