Skip to content

Commit 7241177

Browse files
fix: preserve trailing empty suffix in ɵɵtextInterpolateN calls
ɵɵtextInterpolate1/2/...N always require all positional string args including the trailing suffix. When the suffix was an empty string, it was incorrectly dropped, causing `undefined` to be concatenated at runtime (e.g. `#1undefined` instead of `#1`). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5cc1a58 commit 7241177

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

crates/oxc_angular_compiler/src/pipeline/phases/reify/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,15 @@ fn reify_update_op<'a>(
874874
}
875875
}
876876
UpdateOp::InterpolateText(interp) => {
877-
// Handle multiple interpolations like "{{a}} and {{b}}"
877+
// Handle multiple interpolations like "{{a}} and {{b}}" or "#{{a}}"
878+
// has_extra_args must be true to preserve trailing empty strings —
879+
// ɵɵtextInterpolateN always requires all positional string args.
878880
let (args, expr_count) = reify_interpolation(
879881
allocator,
880882
&interp.interpolation,
881883
expressions,
882884
root_xref,
883-
false,
885+
true,
884886
);
885887
Some(create_text_interpolate_stmt_with_args(allocator, args, expr_count))
886888
}

crates/oxc_angular_compiler/tests/integration_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn test_html_entity_between_interpolations() {
171171
// Should produce: textInterpolate2("", ctx.a, "×", ctx.b)
172172
// Note: × (multiplication sign) = U+00D7, emitted as raw UTF-8
173173
assert!(
174-
js.contains("textInterpolate2(\"\",ctx.a,\"\u{00D7}\",ctx.b)"),
174+
js.contains("textInterpolate2(\"\",ctx.a,\"\u{00D7}\",ctx.b,\"\")"),
175175
"Expected textInterpolate2 with raw times character. Got:\n{js}"
176176
);
177177
}
@@ -183,7 +183,7 @@ fn test_html_entity_at_start_of_interpolation() {
183183
// Should produce: textInterpolate1("×", ctx.a)
184184
// Note: × (multiplication sign) = U+00D7, emitted as raw UTF-8
185185
assert!(
186-
js.contains("textInterpolate1(\"\u{00D7}\",ctx.a)")
186+
js.contains("textInterpolate1(\"\u{00D7}\",ctx.a,\"\")")
187187
|| js.contains("textInterpolate(\"\u{00D7}\",ctx.a)"),
188188
"Expected textInterpolate with raw times character at start. Got:\n{js}"
189189
);
@@ -197,7 +197,7 @@ fn test_multiple_html_entities_between_interpolations() {
197197
// Should produce: textInterpolate2("", ctx.a, "\u{00A0}×\u{00A0}", ctx.b)
198198
// Note: &nbsp; = U+00A0, &times; = U+00D7, both emitted as raw UTF-8
199199
assert!(
200-
js.contains("textInterpolate2(\"\",ctx.a,\"\u{00A0}\u{00D7}\u{00A0}\",ctx.b)"),
200+
js.contains("textInterpolate2(\"\",ctx.a,\"\u{00A0}\u{00D7}\u{00A0}\",ctx.b,\"\")"),
201201
"Expected textInterpolate2 with raw Unicode entities. Got:\n{js}"
202202
);
203203
}

crates/oxc_angular_compiler/tests/snapshots/integration_test__for_listener_with_index.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function TestComponent_For_1_Template(rf,ctx) {
2020
if ((rf & 2)) {
2121
const ɵ$index_1_r2 = ctx.$index;
2222
i0.ɵɵadvance(2);
23-
i0.ɵɵtextInterpolate1("Remove #"$index_1_r2);
23+
i0.ɵɵtextInterpolate1("Remove #"$index_1_r2,"");
2424
}
2525
}
2626
function TestComponent_Template(rf,ctx) {

crates/oxc_angular_compiler/tests/snapshots/integration_test__for_with_context_variables.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function TestComponent_For_1_Template(rf,ctx) {
1818
i0.ɵɵadvance();
1919
i0.ɵɵclassProp("first",(ɵ$index_1_r2 === 0))("last",(ɵ$index_1_r2 ===$count_1_r3 - 1)));
2020
i0.ɵɵadvance();
21-
i0.ɵɵtextInterpolate2(""$index_1_r2,": ",item_r1.name);
21+
i0.ɵɵtextInterpolate2(""$index_1_r2,": ",item_r1.name,"");
2222
}
2323
}
2424
function TestComponent_Template(rf,ctx) {

crates/oxc_angular_compiler/tests/snapshots/integration_test__multiple_interpolations.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ function TestComponent_Template(rf,ctx) {
1010
}
1111
if ((rf & 2)) {
1212
i0.ɵɵadvance();
13-
i0.ɵɵtextInterpolate2("",ctx.first," and ",ctx.second);
13+
i0.ɵɵtextInterpolate2("",ctx.first," and ",ctx.second,"");
1414
}
1515
}

0 commit comments

Comments
 (0)