Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Emitted JS / Gentype double-escapes output

Aberta
#8,088 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
55/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
javascript, ocaml, typescript
Domínio
compilers

Direção de pesquisa

Comece em compiler/gentype/TranslateTypeDeclarations.ml, por volta da linha 48, e depois inspecione os casos @as em tests/gentype_tests/typescript-react-example/src/Records.res e suas saídas geradas .gen.tsx e .res.js. Execute o teste existente de gentype e reproduza os dois casos de aspas escapadas. Está concluído quando o JavaScript e o TypeScript gerados não fizerem escape duplo do valor e o parser aceitar o identificador exótico.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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?
Linguagem predominante
OCaml
Estrelas
7.5k
Forks
485
Merge médio
1d 4h
PRs com merge (30d)
50

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rescript-lang/rescript

Todas as issues de rescript-lang/rescript

Issues semelhantes

Mais issues de Compilers

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.