Repository navigation
Template literals with substitutions process their escape sequences - #539
Merged
Merged
Conversation
The text around a substitution was taken as written (`rawText`) instead
of with its escapes processed (`text`): `${n}\n${n}` held the four
characters 1, \, n, 1, so two-line labels showed a literal "\n". Tagged
templates passed the tag the same unprocessed strings, and a template
literal type kept them too, so "hi\tyou" did not match `hi\t${Name}`.
Reported in docs/bugs/native-ts-graphics-findings.md (issue 4).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Escape sequences in the text around a substitution were kept as written:
A template without substitutions and a string literal were fine. Reported in
docs/bugs/native-ts-graphics-findings.md, issue 4 (docs/bugs/ntg_template_literal_escape.ts): ImGui labels showed a literal\n.The same mistake was in two more places:
tag\x\ty${n}``).type Greeting = `hi\t${Name}`kept the backslash, soconst g: Greeting = "hi\tyou"failed to compile withcan't cast from literal type: '"hi\09you"' to '"hi\tyou"'.Fix
Use the template node's
text(escapes processed by the scanner) instead ofrawTextfor the head and every span, inmlirGen(TemplateLiteralLikeNode),mlirGen(TaggedTemplateExpression)andgetTemplateLiteralType/getTemplateLiteralSpan. In JavaScript a tag's strings are the processed ones (the raw ones arestrings.raw, which tslang doesn't provide), so the tag now gets what JavaScript would give it.Testing
00template_literal_escapes.ts(compile + JIT + rc/none corpus) covers escapes in the head, middle and tail,\x41/B, escaped backticks, a tagged template and a template literal type. The current release fails withassertion failed: middle escape(and the type case doesn't compile).docs/bugs/ntg_template_literal_escape.tsnow prints 3, 3, 3.🤖 Generated with Claude Code