Skip to content

feat(compiler): Support braced Unicode escapes in template string literals - #67269

Closed
kbrilla wants to merge 4 commits into
angular:mainfrom
kbrilla:feat/braced-unicode-escapes-upstream
Closed

kbrilla wants to merge 4 commits into
angular:mainfrom
kbrilla:feat/braced-unicode-escapes-upstream

Conversation

@kbrilla

@kbrilla kbrilla commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Braced Unicode escapes in Angular template string literals

Scope (feature-only)

This PR adds support for ES6 braced Unicode escapes in Angular template expression string literals:

  • {{ '\u{4f60}' }} -> 你 (CJK character)
  • {{ '\u{1F600}' }} -> 😀 (emoji, above U+FFFF)
  • {{ '\u4f60' }} -> still works (traditional 4-digit form)

Additional validated sequence example:

  • \u{48}\u{65}\u{6C}\u{6C}\u{6F} -> Hello

Working example:
image

What changed

  • Extended expression lexer string escape handling to support both:
    • \uXXXX
    • \u{...}
  • Added code point handling above BMP (> 0xFFFF) via String.fromCodePoint(...).
  • Added parser tests for:
    • CJK braced escape (你)
    • Emoji braced escape (😀)
    • Legacy 4-digit escape compatibility
    • Multi-escape sequence producing Hello

Character mapping

Character Name / Description ✅ Braced Escape (\u{...}) 🛠️ Standard / Surrogate Pair
H Latin Capital H \u{48} \u0048
e Latin Small E \u{65} \u0065
l Latin Small L \u{6C} \u006C
o Latin Small O \u{6F} \u006F
🚀 Rocket \u{1F680} \uD83D\uDE80 (Pair)
💎 Gem Stone \u{1F48E} \uD83D\uDC8E (Pair)
🧩 Puzzle Piece \u{1F9E9} \uD83E\uDDE9 (Pair)
𓃰 Elephant (Hieroglyph) \u{130F0} \uD80C\uDCF0 (Pair)

Key takeaways

  • The Why: Standard \uXXXX is limited to 16 bits (65,536 combinations). Modern Unicode extends to 21-bit code points (astral planes) used by many emoji and historic scripts.
  • Braced Escapes: \u{...} is the modern ES6 form. It directly expresses code points without manual surrogate math or zero-padding.
  • Surrogate Pairs: Legacy UTF-16 workaround where one non-BMP code point is encoded as two 16-bit units (high + low surrogate).

Tests run

  • pnpm bazel test //packages/compiler/test:test --test_filter=".*unicode braced escapes.*" --test_output=errors (passed)
  • pnpm bazel test //packages/compiler/test:test --test_output=errors (passed)

Notes

AI disclosure

AI assisted with implementation and drafting under user direction; all changes were reviewed and validated with local tests before opening this PR.

@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler labels Feb 25, 2026
@ngbot ngbot Bot added this to the Backlog milestone Feb 25, 2026
@kbrilla
kbrilla force-pushed the feat/braced-unicode-escapes-upstream branch 2 times, most recently from f18c605 to 1b1fbee Compare February 25, 2026 03:15
@kbrilla
kbrilla force-pushed the feat/braced-unicode-escapes-upstream branch from 1b1fbee to 5c4e599 Compare February 25, 2026 03:17
@kbrilla
kbrilla force-pushed the feat/braced-unicode-escapes-upstream branch from 5c4e599 to 07e183e Compare February 25, 2026 03:19
@kbrilla
kbrilla marked this pull request as ready for review February 25, 2026 03:22
@kbrilla kbrilla changed the title WIP: support braced Unicode escapes in template string literals Support braced Unicode escapes in template string literals Feb 25, 2026
@pullapprove
pullapprove Bot requested a review from thePunderWoman February 25, 2026 04:09
@kbrilla kbrilla changed the title Support braced Unicode escapes in template string literals feat(compiler): Support braced Unicode escapes in template string literals Feb 25, 2026
@kbrilla
kbrilla requested a review from JeanMeche February 25, 2026 20:12
@JeanMeche

JeanMeche commented Feb 26, 2026 •

Copy link
Copy Markdown
Member

Thanks for the contribution — we do like the feature in isolation. That said, it doesn’t quite fit with the overall direction of Angular right now. The PR patches something we’re planning to remove and delegate to another parser instead. This is an area we may revisit later as we rethink the compiler stack for ts-go support.

Really appreciate the effort!

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Mar 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: compiler Issues related to `ngc`, Angular's template compiler detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support braced Unicode escapes

2 participants