Repository navigation
Conversation
Escape control and non-ASCII code units as `\uXXXX` in string literals emitted by `ExpressionPrinter` to match TypeScript's `escapeNonAsciiString` behavior on synthesized string literals. Add an i18n named placeholder test case (`// i18n(ph=...)`) to the preprocessor goldens and remove the `\uXXXX` normalization from `ngp_emit_normalizer`.
JeanMeche
requested review from
crisbeto and
mattrbeck
and removed request for
crisbeto
October 18, 2026 06:47
crisbeto
reviewed
Oct 18, 2026
| * Prints `value` as a single-quoted string literal, escaping control and non-ASCII code units | ||
| * as `\uXXXX` to match TypeScript's `escapeNonAsciiString` on synthesized string literals. | ||
| */ | ||
| function escapeStringLiteral(value: string): string { |
Member
There was a problem hiding this comment.
How was this happening in ngtsc? Is there something we can reuse?
|
|
||
| override visitLiteralMapExpr(ast: o.LiteralMapExpr, ctx: EmitterVisitorContext): void { | ||
| withSpan(ctx, ast.sourceSpan, () => super.visitLiteralMapExpr(ast, ctx)); | ||
| withSpan(ctx, ast.sourceSpan, () => { |
Member
There was a problem hiding this comment.
Maybe instead of overriding the entire method, we can have a method on the super class that lets us customize how keys are escaped?
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.
Summary
Escapes non-ASCII characters as
\uXXXXin string literals emitted byngp'sExpressionPrinterto match TypeScript'sescapeNonAsciiStringbehavior on synthesized string literals, adds an i18n named placeholder test case (// i18n(ph=...)) to the preprocessor goldens, and removes the\uXXXXnormalization fromngp_emit_normalizer.Changes
EmitterVisitorinpackages/compiler-cli/preprocessor/src/output_ast_printer.tsto escape control (\u0000-\u001f) and non-ASCII (\u0080-\uffff) code units as\uXXXXin emitted string literals (LiteralExpr, quoted keys inLiteralMapExpr, and string URLs inDynamicImportExpr).LocalizeNamedPlaceholderCmpwith{{ valueA // i18n(ph="PH_A") }}and{{ valueB // i18n(ph="PH B") }}tocomponent_localize/source.mdand updatedcomponent_localize/golden.md,component_localize/golden.opt.md, andutf16_semantics/golden.md.\uXXXXdecoding fromnormalizeNgpSourceMapSegmentandnormalizeNgpEmitForComparisoninpackages/compiler-cli/src/ngtsc/testing/src/ngp_emit_normalizer.ts.