Skip to content

fix(metadata): fold number consts in a template literal's interpolations - #603

Open
Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/template-literal-number-const
Open

Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/template-literal-number-const

Conversation

@Rush

@Rush Rush commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

A number in an inline template's interpolation left the component uncompiled:

const WIDTH = 150;
@Component({ selector: 'e-cmp', template: `<canvas style="width: ${WIDTH}px"></canvas>` })

#286 made string consts work; number consts and literals still weren't folded. Like ngtsc's partial evaluator, a ${...} interpolation can now also be a number literal or a same-file number const (negative ones included), converted as JavaScript converts a number to a string (oxc_syntax's ToJsString). Chained consts work too (const SIZE = `${WIDTH}px`).

The number consts are only used for template-literal interpolation: the string-const map used for host bindings, selectors and the rest is unchanged.

tests/template_literal_number_const_test.rs compares the consts of two components with @angular/compiler-cli 21.0.1's: [[1, "box", 2, "width", "150px", "height", "80px"]] and [[2, "width", "150px", "margin", "-2px", "opacity", "0.5"]]. Both fail without the change.

`template: \`<canvas style="width: ${WIDTH}px"></canvas>\`` with
`const WIDTH = 150` left the component uncompiled: only string consts were
folded (voidzero-dev#286). Like ngtsc's partial evaluator, a `${...}` interpolation can now
also be a number literal or a same-file number const (`-2` included), converted
as JavaScript converts numbers to strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant