Skip to content

Commit c73520b

Browse files
JeanMecheAndrewKushnir
authored andcommitted
refactor(compiler): remove empty empty string suffix from interpolation instructions (angular#60066)
With this change, interpolations that don't have a suffix will miss the last argument which was previously an empty string. PR Close angular#60066
1 parent e3afa24 commit c73520b

33 files changed

+134
-116
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/lifecycle_hooks/local_reference_nested.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function MyComponent_div_3_span_2_Template(rf, ctx) {
1111
const $foo$ = $r3$.ɵɵreference(1);
1212
const $baz$ = $r3$.ɵɵreference(5);
1313
$r3$.ɵɵadvance();
14-
$r3$.ɵɵtextInterpolate3("", $foo$, "-", $bar$, "-", $baz$, "");
14+
$r3$.ɵɵtextInterpolate3("", $foo$, "-", $bar$, "-", $baz$);
1515
}
1616
}
1717
function MyComponent_div_3_Template(rf, ctx) {

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipe_invocation.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
2020
"1:", i0.ɵɵpipeBind2(2, 7, ctx.name, 1),
2121
"2:", i0.ɵɵpipeBind3(3, 10, ctx.name, 1, 2),
2222
"3:", i0.ɵɵpipeBind4(4, 14, ctx.name, 1, 2, 3),
23-
"4:", i0.ɵɵpipeBindV(5, 19, $r3$.ɵɵpureFunction1(25, $c0$, ctx.name)),
24-
""
23+
"4:", i0.ɵɵpipeBindV(5, 19, $r3$.ɵɵpureFunction1(25, $c0$, ctx.name))
2524
);
2625
}
2726
},

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipes_my_app_def.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
2020
if (rf & 2) {
2121
$r3$.ɵɵtextInterpolate($r3$.ɵɵpipeBind2(2, 6, $r3$.ɵɵpipeBind2(1, 3, ctx.name, ctx.size), ctx.size));
2222
$r3$.ɵɵadvance(4);
23-
$r3$.ɵɵtextInterpolate2("", $r3$.ɵɵpipeBindV(5, 9, $r3$.ɵɵpureFunction1(18, $c0$, ctx.name)), " ", ctx.name ? 1 : $r3$.ɵɵpipeBind1(6, 16, 2), "");
23+
$r3$.ɵɵtextInterpolate2("", $r3$.ɵɵpipeBindV(5, 9, $r3$.ɵɵpureFunction1(18, $c0$, ctx.name)), " ", ctx.name ? 1 : $r3$.ɵɵpipeBind1(6, 16, 2));
2424
}
2525
},
2626
dependencies: [MyPipe, MyPurePipe],

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/number_separator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ template: function MyApp_Template(rf, ctx) {
22
// ...
33
if (rf & 2) {
44
$r3$.ɵɵadvance();
5-
$r3$.ɵɵtextInterpolate1("Total: $", 1000000 * ctx.multiplier, "");
5+
$r3$.ɵɵtextInterpolate1("Total: $", 1000000 * ctx.multiplier);
66
$r3$.ɵɵadvance(2);
7-
$r3$.ɵɵtextInterpolate1("Remaining: $", 123456.789 / 2, "");
7+
$r3$.ɵɵtextInterpolate1("Remaining: $", 123456.789 / 2);
88
}
99
}

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/structural_directives_my_component_def.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function MyComponent_li_2_Template(rf, ctx) {
88
const $myComp$ = $r3$.ɵɵnextContext();
99
const $foo$ = $r3$.ɵɵreference(1);
1010
$r3$.ɵɵadvance();
11-
$r3$.ɵɵtextInterpolate2("", $myComp$.salutation, " ", $foo$, "");
11+
$r3$.ɵɵtextInterpolate2("", $myComp$.salutation, " ", $foo$);
1212
}
1313
}
1414
// ...
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if (rf & 2) {
22
$r3$.ɵɵadvance();
3-
$r3$.ɵɵtextInterpolate1("No interpolations: ", ctx.tag `hello world `, "");
3+
$r3$.ɵɵtextInterpolate1("No interpolations: ", ctx.tag `hello world `);
44
$r3$.ɵɵadvance(2);
5-
$r3$.ɵɵtextInterpolate1("With interpolations: ", ctx.tag `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`, "");
5+
$r3$.ɵɵtextInterpolate1("With interpolations: ", ctx.tag `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`);
66
$r3$.ɵɵadvance(2);
7-
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, ctx.tag `hello ${ctx.name}`), "");
7+
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, ctx.tag `hello ${ctx.name}`));
88
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if (rf & 2) {
22
$r3$.ɵɵadvance();
3-
$r3$.ɵɵtextInterpolate1("No interpolations: ", `hello world `, "");
3+
$r3$.ɵɵtextInterpolate1("No interpolations: ", `hello world `);
44
$r3$.ɵɵadvance(2);
5-
$r3$.ɵɵtextInterpolate1("With interpolations: ", `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`, "");
5+
$r3$.ɵɵtextInterpolate1("With interpolations: ", `hello ${ctx.name}, it is currently ${ctx.timeOfDay}!`);
66
$r3$.ɵɵadvance(2);
7-
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, `hello ${ctx.name}`), "");
7+
$r3$.ɵɵtextInterpolate1("With pipe: ", $r3$.ɵɵpipeBind1(6, 3, `hello ${ctx.name}`));
88
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler/nullish_coalescing/nullish_coalescing_interpolation_template.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ template: function MyApp_Template(rf, ctx) {
1111
i0.ɵɵadvance();
1212
i0.ɵɵtextInterpolate1("Hello, ", ctx.firstName ?? "Frodo", "!");
1313
i0.ɵɵadvance(2);
14-
i0.ɵɵtextInterpolate1("Your last name is ", ctx.lastName ?? ctx.lastNameFallback ?? "unknown", "");
14+
i0.ɵɵtextInterpolate1("Your last name is ", ctx.lastName ?? ctx.lastNameFallback ?? "unknown");
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
} if (rf & 2) {
22
i0.ɵɵadvance();
3-
i0.ɵɵtextInterpolate1("Safe Property: ", ctx.p == null ? null : ctx.p.a == null ? null : ctx.p.a.b == null ? null : ctx.p.a.b.c == null ? null : ctx.p.a.b.c.d, "");
3+
i0.ɵɵtextInterpolate1("Safe Property: ", ctx.p == null ? null : ctx.p.a == null ? null : ctx.p.a.b == null ? null : ctx.p.a.b.c == null ? null : ctx.p.a.b.c.d);
44
i0.ɵɵadvance(2);
5-
i0.ɵɵtextInterpolate1("Safe Keyed: ", ctx.p == null ? null : ctx.p["a"] == null ? null : ctx.p["a"]["b"] == null ? null : ctx.p["a"]["b"]["c"] == null ? null : ctx.p["a"]["b"]["c"]["d"], "");
5+
i0.ɵɵtextInterpolate1("Safe Keyed: ", ctx.p == null ? null : ctx.p["a"] == null ? null : ctx.p["a"]["b"] == null ? null : ctx.p["a"]["b"]["c"] == null ? null : ctx.p["a"]["b"]["c"]["d"]);
66
i0.ɵɵadvance(2);
7-
i0.ɵɵtextInterpolate1("Mixed Property: ", ctx.p == null ? null : ctx.p.a == null ? null : ctx.p.a.b.c.d == null ? null : ctx.p.a.b.c.d.e == null ? null : ctx.p.a.b.c.d.e.f == null ? null : ctx.p.a.b.c.d.e.f.g.h, "");
7+
i0.ɵɵtextInterpolate1("Mixed Property: ", ctx.p == null ? null : ctx.p.a == null ? null : ctx.p.a.b.c.d == null ? null : ctx.p.a.b.c.d.e == null ? null : ctx.p.a.b.c.d.e.f == null ? null : ctx.p.a.b.c.d.e.f.g.h);
88
i0.ɵɵadvance(2);
9-
i0.ɵɵtextInterpolate1("Mixed Property and Keyed: ", ctx.p.a["b"].c.d == null ? null : ctx.p.a["b"].c.d["e"] == null ? null : ctx.p.a["b"].c.d["e"]["f"] == null ? null : ctx.p.a["b"].c.d["e"]["f"].g["h"]["i"] == null ? null : ctx.p.a["b"].c.d["e"]["f"].g["h"]["i"].j.k, "");
9+
i0.ɵɵtextInterpolate1("Mixed Property and Keyed: ", ctx.p.a["b"].c.d == null ? null : ctx.p.a["b"].c.d["e"] == null ? null : ctx.p.a["b"].c.d["e"]["f"] == null ? null : ctx.p.a["b"].c.d["e"]["f"].g["h"]["i"] == null ? null : ctx.p.a["b"].c.d["e"]["f"].g["h"]["i"].j.k);
1010
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler/safe_access/safe_access_temporaries_template.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
let $tmp_3_2$;
99
let $tmp_3_3$;
1010
i0.ɵɵadvance();
11-
i0.ɵɵtextInterpolate1("Safe Property with Calls: ", ($tmp_0_0$ = ctx.p()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.a()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.b()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.c()) == null ? null : $tmp_0_0$.d(), "");
11+
i0.ɵɵtextInterpolate1("Safe Property with Calls: ", ($tmp_0_0$ = ctx.p()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.a()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.b()) == null ? null : ($tmp_0_0$ = $tmp_0_0$.c()) == null ? null : $tmp_0_0$.d());
1212
i0.ɵɵadvance(2);
13-
i0.ɵɵtextInterpolate1("Safe and Unsafe Property with Calls: ", ctx.p == null ? null : ($tmp_1_0$ = ctx.p.a()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.b().c().d()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.e()) == null ? null : $tmp_1_0$.f == null ? null : $tmp_1_0$.f.g.h == null ? null : ($tmp_1_0$ = $tmp_1_0$.f.g.h.i()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.j()) == null ? null : $tmp_1_0$.k().l, "");
13+
i0.ɵɵtextInterpolate1("Safe and Unsafe Property with Calls: ", ctx.p == null ? null : ($tmp_1_0$ = ctx.p.a()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.b().c().d()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.e()) == null ? null : $tmp_1_0$.f == null ? null : $tmp_1_0$.f.g.h == null ? null : ($tmp_1_0$ = $tmp_1_0$.f.g.h.i()) == null ? null : ($tmp_1_0$ = $tmp_1_0$.j()) == null ? null : $tmp_1_0$.k().l);
1414
i0.ɵɵadvance(2);
15-
i0.ɵɵtextInterpolate1("Nested Safe with Calls: ", ($tmp_2_0$ = ctx.f1()) == null ? null : $tmp_2_0$[($tmp_2_1$ = ctx.f2()) == null ? null : $tmp_2_1$.a] == null ? null : $tmp_2_0$[($tmp_2_1$ = $tmp_2_1$) == null ? null : $tmp_2_1$.a].b, "");
15+
i0.ɵɵtextInterpolate1("Nested Safe with Calls: ", ($tmp_2_0$ = ctx.f1()) == null ? null : $tmp_2_0$[($tmp_2_1$ = ctx.f2()) == null ? null : $tmp_2_1$.a] == null ? null : $tmp_2_0$[($tmp_2_1$ = $tmp_2_1$) == null ? null : $tmp_2_1$.a].b);
1616
i0.ɵɵadvance(2);
17-
i0.ɵɵtextInterpolate1("Deep Nested Safe with Calls: ", ($tmp_3_0$ = ctx.f1()) == null ? null : $tmp_3_0$[($tmp_3_1$ = ctx.f2()) == null ? null : ($tmp_3_2$ = $tmp_3_1$.f3()) == null ? null : $tmp_3_2$[($tmp_3_3$ = ctx.f4()) == null ? null : $tmp_3_3$.f5()]] == null ? null : $tmp_3_0$[($tmp_3_1$ = $tmp_3_1$) == null ? null : ($tmp_3_2$ = $tmp_3_2$) == null ? null : $tmp_3_2$[($tmp_3_3$ = $tmp_3_3$) == null ? null : $tmp_3_3$.f5()]].f6(), "");
17+
i0.ɵɵtextInterpolate1("Deep Nested Safe with Calls: ", ($tmp_3_0$ = ctx.f1()) == null ? null : $tmp_3_0$[($tmp_3_1$ = ctx.f2()) == null ? null : ($tmp_3_2$ = $tmp_3_1$.f3()) == null ? null : $tmp_3_2$[($tmp_3_3$ = ctx.f4()) == null ? null : $tmp_3_3$.f5()]] == null ? null : $tmp_3_0$[($tmp_3_1$ = $tmp_3_1$) == null ? null : ($tmp_3_2$ = $tmp_3_2$) == null ? null : $tmp_3_2$[($tmp_3_3$ = $tmp_3_3$) == null ? null : $tmp_3_3$.f5()]].f6());
1818
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
template: function MyComponent_Template(rf, ctx) {
22
33
if (rf & 2) {
4-
$r3$.ɵɵattributeInterpolate1("tabindex", "prefix-", 0 + 3, "");
5-
$r3$.ɵɵattributeInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3, "");
4+
$r3$.ɵɵattributeInterpolate1("tabindex", "prefix-", 0 + 3);
5+
$r3$.ɵɵattributeInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3);
66
$r3$.ɵɵattribute("title", 1)("id", 2);
77
}
88
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/attribute_bindings/chain_multiple_bindings_mixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
template: function MyComponent_Template(rf, ctx) {
22
33
if (rf & 2) {
4-
$r3$.ɵɵattributeInterpolate1("aria-label", "prefix-", 1 + 3, "");
4+
$r3$.ɵɵattributeInterpolate1("aria-label", "prefix-", 1 + 3);
55
$r3$.ɵɵproperty("id", 2);
66
$r3$.ɵɵattribute("title", 1)("tabindex", 3);
77
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/order_bindings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function MyCmp_Template(rf, ctx) {
2626
} if (rf & 2) {
2727
i0.ɵɵstyleProp("style1", ctx.foo);
2828
i0.ɵɵclassProp("class1", ctx.foo);
29-
i0.ɵɵattributeInterpolate1("attrInterp1", "interp ", ctx.foo, "");
30-
i0.ɵɵpropertyInterpolate1("propInterp1", "interp ", ctx.foo, "");
29+
i0.ɵɵattributeInterpolate1("attrInterp1", "interp ", ctx.foo);
30+
i0.ɵɵpropertyInterpolate1("propInterp1", "interp ", ctx.foo);
3131
i0.ɵɵproperty("prop1", ctx.foo);
3232
i0.ɵɵattribute("attr1", ctx.foo);
3333
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/property_bindings/chain_bindings_with_interpolations.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ template: function MyComponent_Template(rf, ctx) {
22
33
if (rf & 2) {
44
$r3$.ɵɵpropertyInterpolate("tabindex", 0 + 3);
5-
$r3$.ɵɵpropertyInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3, "");
5+
$r3$.ɵɵpropertyInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3);
66
$r3$.ɵɵproperty("title", 1)("id", 2);
77
}
88
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/property_bindings/interpolation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ template:function MyComponent_Template(rf, $ctx$){
66
$i0$.ɵɵelement(0, "a", 0);
77
}
88
if (rf & 2) {
9-
$i0$.ɵɵpropertyInterpolate1("title", "Hello ", $ctx$.name, "");
9+
$i0$.ɵɵpropertyInterpolate1("title", "Hello ", $ctx$.name);
1010
}
1111
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/text_bindings/interpolation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ template:function MyComponent_Template(rf, $ctx$){
77
}
88
if (rf & 2) {
99
$r3$.ɵɵadvance();
10-
$i0$.ɵɵtextInterpolate1("Hello ", $ctx$.name, "");
10+
$i0$.ɵɵtextInterpolate1("Hello ", $ctx$.name);
1111
}
1212
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/attribute_interpolation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ template: function MyComponent_Template(rf, ctx) {
6767
}
6868
if (rf & 2) {
6969
i0.ɵɵadvance(2);
70-
i0.ɵɵpropertyInterpolate2("title", "", ctx.foo, "-", ctx.foo, "");
70+
i0.ɵɵpropertyInterpolate2("title", "", ctx.foo, "-", ctx.foo);
7171
i0.ɵɵadvance(2);
7272
i0.ɵɵi18nExp(ctx.foo)(ctx.foo)(ctx.foo)(ctx.foo)(ctx.foo);
7373
i0.ɵɵi18nApply(1);

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/mixed_style_and_class/pipe_bindings_slots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ template: function MyComponent_Template(rf, $ctx$) {
1414
$r3$.ɵɵstyleProp("bar", $r3$.ɵɵpipeBind2(2, 14, $ctx$.barExp, 3000))("baz", $r3$.ɵɵpipeBind2(3, 17, $ctx$.bazExp, 4000));
1515
$r3$.ɵɵclassProp("foo", $r3$.ɵɵpipeBind2(4, 20, $ctx$.fooExp, 2000));
1616
$r3$.ɵɵadvance(5);
17-
$r3$.ɵɵtextInterpolate1(" ", $ctx$.item, "");
17+
$r3$.ɵɵtextInterpolate1(" ", $ctx$.item);
1818
}
1919
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/style_bindings/binding_slots.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$r3$.ɵɵelement(0, "div");
77
}
88
if (rf & 2) {
9-
$r3$.ɵɵclassMapInterpolate1("foo foo-", $ctx$.fooId, "");
9+
$r3$.ɵɵclassMapInterpolate1("foo foo-", $ctx$.fooId);
1010
}
1111
}
1212
// ...
@@ -17,7 +17,7 @@
1717
$r3$.ɵɵelement(0, "div");
1818
}
1919
if (rf & 2) {
20-
$r3$.ɵɵclassMapInterpolate2("foo foo-", $ctx$.fooId, "-", $ctx$.fooUsername, "");
20+
$r3$.ɵɵclassMapInterpolate2("foo foo-", $ctx$.fooId, "-", $ctx$.fooUsername);
2121
}
2222
}
2323
// ...
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
2-
i0.ɵɵtextInterpolate1(" ", (ctx.a == null ? null : ctx.a.b) ? 1 : 2, "")
2+
i0.ɵɵtextInterpolate1(" ", (ctx.a == null ? null : ctx.a.b) ? 1 : 2)

packages/compiler-cli/test/compliance/test_cases/source_mapping/inline_templates/interpolation_basic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ i0.ɵɵelementStart(0, "h3") // SOURCE: "/interpolation_basic.ts" "<h3>"
22
33
i0.ɵɵelementEnd() // SOURCE: "/interpolation_basic.ts" "</h3>"
44
5-
i0.ɵɵtextInterpolate1("Hello ", ctx.name, "") // SOURCE: "/interpolation_basic.ts" "Hello {{ name }}"
5+
i0.ɵɵtextInterpolate1("Hello ", ctx.name) // SOURCE: "/interpolation_basic.ts" "Hello {{ name }}"

packages/compiler-cli/test/compliance/test_cases/source_mapping/inline_templates/interpolation_basic_partial.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// TODO: Work out how to fix the broken segment for the last item in a template
44
.ɵɵele // SOURCE: "/interpolation_basic.ts" "</h3>'"
55
6-
.ɵɵtextInterpolate1("Hello ", ctx.name, "") // SOURCE: "/interpolation_basic.ts" "Hello {{ name }}"
6+
.ɵɵtextInterpolate1("Hello ", ctx.name) // SOURCE: "/interpolation_basic.ts" "Hello {{ name }}"

packages/compiler-cli/test/ngtsc/template_mapping_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ runInEachFileSystem((os) => {
7272
});
7373
expectMapping(mappings, {
7474
source: 'Hello {{ name }}',
75-
generated: 'i0.ɵɵtextInterpolate1("Hello ", ctx.name, "")',
75+
generated: 'i0.ɵɵtextInterpolate1("Hello ", ctx.name)',
7676
sourceUrl: '../test.ts',
7777
});
7878
expectMapping(mappings, {

packages/compiler/src/template/pipeline/src/instruction.ts

+19
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ export function textInterpolate(
579579
sourceSpan: ParseSourceSpan,
580580
): ir.UpdateOp {
581581
const interpolationArgs = collateInterpolationArgs(strings, expressions);
582+
582583
return callVariadicInstruction(TEXT_INTERPOLATE_CONFIG, [], interpolationArgs, [], sourceSpan);
583584
}
584585

@@ -598,6 +599,7 @@ export function propertyInterpolate(
598599
sourceSpan: ParseSourceSpan,
599600
): ir.UpdateOp {
600601
const interpolationArgs = collateInterpolationArgs(strings, expressions);
602+
601603
const extraArgs = [];
602604
if (sanitizer !== null) {
603605
extraArgs.push(sanitizer);
@@ -620,6 +622,7 @@ export function attributeInterpolate(
620622
sourceSpan: ParseSourceSpan,
621623
): ir.UpdateOp {
622624
const interpolationArgs = collateInterpolationArgs(strings, expressions);
625+
623626
const extraArgs = [];
624627
if (sanitizer !== null) {
625628
extraArgs.push(sanitizer);
@@ -642,6 +645,7 @@ export function stylePropInterpolate(
642645
sourceSpan: ParseSourceSpan,
643646
): ir.UpdateOp {
644647
const interpolationArgs = collateInterpolationArgs(strings, expressions);
648+
645649
const extraArgs: o.Expression[] = [];
646650
if (unit !== null) {
647651
extraArgs.push(o.literal(unit));
@@ -748,6 +752,7 @@ function collateInterpolationArgs(strings: string[], expressions: o.Expression[]
748752
for (idx = 0; idx < expressions.length; idx++) {
749753
interpolationArgs.push(o.literal(strings[idx]), expressions[idx]);
750754
}
755+
751756
// idx points at the last string.
752757
interpolationArgs.push(o.literal(strings[idx]));
753758
}
@@ -953,7 +958,21 @@ function callVariadicInstructionExpr(
953958
extraArgs: o.Expression[],
954959
sourceSpan: ParseSourceSpan | null,
955960
): o.Expression {
961+
// mapping need to be done before potentially dropping the last interpolation argument
956962
const n = config.mapping(interpolationArgs.length);
963+
964+
// In the case the interpolation instruction ends with a empty string we drop it
965+
// And the runtime will take care of it.
966+
const lastInterpolationArg = interpolationArgs.at(-1);
967+
if (
968+
extraArgs.length === 0 &&
969+
interpolationArgs.length > 1 &&
970+
lastInterpolationArg instanceof o.LiteralExpr &&
971+
lastInterpolationArg.value === ''
972+
) {
973+
interpolationArgs.pop();
974+
}
975+
957976
if (n < config.constant.length) {
958977
// Constant calling pattern.
959978
return o

0 commit comments

Comments
 (0)