Repository navigation
fix(metadata): fold number consts in a template literal's interpolations #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Brooooooklyn
merged 1 commit into
voidzero-dev:main
from
encharm:fix/template-literal-number-const
Oct 22, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
crates/oxc_angular_compiler/tests/template_literal_number_const_test.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //! A `${...}` interpolation in an inline template can be a number, a literal or | ||
| //! a same-file `const` (`const WIDTH = 150`), as well as a string: ngtsc's | ||
| //! partial evaluator folds it as JavaScript converts the number to a string. | ||
| //! Before, the component was left uncompiled. The expected `consts` are | ||
| //! `@angular/compiler-cli` 21.0.1's for the same components. | ||
|
|
||
| use oxc_allocator::Allocator; | ||
| use oxc_angular_compiler::{TransformOptions, transform_angular_file}; | ||
|
|
||
| fn compile(source: &str) -> String { | ||
| let allocator = Allocator::default(); | ||
| let result = transform_angular_file( | ||
| &allocator, | ||
| "test.ts", | ||
| source, | ||
| Some(&TransformOptions::default()), | ||
| None, | ||
| ); | ||
| assert!(!result.has_errors(), "Should not have errors: {:?}", result.diagnostics); | ||
| result.code.chars().filter(|c| !c.is_whitespace()).collect() | ||
| } | ||
|
|
||
| #[test] | ||
| fn number_consts_in_a_template_literal() { | ||
| let code = compile( | ||
| r#" | ||
| import { Component } from '@angular/core'; | ||
| const WIDTH = 150; | ||
| const HEIGHT = 80; | ||
| const CLS = 'box'; | ||
| @Component({ selector: 'e-cmp', template: `<canvas class="${CLS}" style="width: ${WIDTH}px; height: ${HEIGHT}px;"></canvas>` }) | ||
| export class ECmp {} | ||
| "#, | ||
| ); | ||
| assert!( | ||
| code.contains(r#"consts:[[1,"box",2,"width","150px","height","80px"]]"#), | ||
| "Got:\n{code}" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn chained_and_negative_number_consts_and_number_literals() { | ||
| let code = compile( | ||
| r#" | ||
| import { Component } from '@angular/core'; | ||
| const WIDTH = 150; | ||
| const SIZE = `${WIDTH}px`; | ||
| const OFFSET = -2; | ||
| @Component({ selector: 'e3-cmp', template: `<div style="width: ${SIZE}; margin: ${OFFSET}px; opacity: ${0.5};"></div>` }) | ||
| export class E3Cmp {} | ||
| "#, | ||
| ); | ||
| assert!( | ||
| code.contains(r#"consts:[[2,"width","150px","margin","-2px","opacity","0.5"]]"#), | ||
| "Got:\n{code}" | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.