Skip to content

Commit 2cdbe9b

Browse files
benleshjasonaden
authored andcommitted
refactor(ivy): ensure new attribute instructons are available in JIT (angular#30503)
PR Close angular#30503
1 parent 988afad commit 2cdbe9b

File tree

9 files changed

+719
-1086
lines changed

9 files changed

+719
-1086
lines changed

packages/compiler-cli/test/compliance/r3_view_compiler_binding_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ describe('compiler compliance: bindings', () => {
533533
i0.ɵɵselect(8);
534534
i0.ɵɵattributeInterpolate1("title", "a", ctx.one, "b");
535535
i0.ɵɵselect(9);
536-
i0.ɵɵattributeInterpolate("title", ctx.one);
536+
i0.ɵɵattribute("title", ctx.one);
537537
}
538538
539539
`;

packages/compiler/src/render3/r3_identifiers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export class Identifiers {
4343

4444
static attribute: o.ExternalReference = {name: 'ɵɵattribute', moduleName: CORE};
4545

46-
static attributeInterpolate:
47-
o.ExternalReference = {name: 'ɵɵattributeInterpolate', moduleName: CORE};
4846
static attributeInterpolate1:
4947
o.ExternalReference = {name: 'ɵɵattributeInterpolate1', moduleName: CORE};
5048
static attributeInterpolate2:

packages/compiler/src/render3/view/template.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,16 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
763763
R3.property, elementIndex, attrName, input, implicit, value, params);
764764
}
765765
} else if (inputType === BindingType.Attribute) {
766-
if (value instanceof Interpolation) {
767-
// attr.name="{{value}}" and friends
766+
if (value instanceof Interpolation && getInterpolationArgsLength(value) > 1) {
767+
// attr.name="text{{value}}" and friends
768768
this.interpolatedUpdateInstruction(
769769
getAttributeInterpolationExpression(value), elementIndex, attrName, input, value,
770770
params);
771771
} else {
772-
// [attr.name]="value"
772+
const boundValue = value instanceof Interpolation ? value.expressions[0] : value;
773+
// [attr.name]="value" or attr.name="{{value}}"
773774
this.boundUpdateInstruction(
774-
R3.attribute, elementIndex, attrName, input, implicit, value, params);
775+
R3.attribute, elementIndex, attrName, input, implicit, boundValue, params);
775776
}
776777
} else {
777778
// class prop
@@ -1714,8 +1715,6 @@ function getPropertyInterpolationExpression(interpolation: Interpolation) {
17141715
*/
17151716
function getAttributeInterpolationExpression(interpolation: Interpolation) {
17161717
switch (getInterpolationArgsLength(interpolation)) {
1717-
case 1:
1718-
return R3.attributeInterpolate;
17191718
case 3:
17201719
return R3.attributeInterpolate1;
17211720
case 5:

packages/core/src/core_render3_private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// clang-format off
1010
export {
1111
ɵɵattribute,
12-
ɵɵattributeInterpolate,
1312
ɵɵattributeInterpolate1,
1413
ɵɵattributeInterpolate2,
1514
ɵɵattributeInterpolate3,

packages/core/src/render3/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
ɵɵallocHostVars,
2626

2727
ɵɵattribute,
28-
ɵɵattributeInterpolate,
2928
ɵɵattributeInterpolate1,
3029
ɵɵattributeInterpolate2,
3130
ɵɵattributeInterpolate3,

packages/core/src/render3/instructions/attribute.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import {SanitizerFn} from '../interfaces/sanitization';
99
import {getSelectedIndex} from '../state';
1010

11-
import {ΔelementAttribute} from './element';
12-
import {Δbind} from './property';
11+
import {ɵɵelementAttribute} from './element';
12+
import {ɵɵbind} from './property';
1313

1414
/**
1515
* Updates the value of or removes a bound attribute on an Element.
@@ -24,8 +24,9 @@ import {Δbind} from './property';
2424
*
2525
* @codeGenApi
2626
*/
27-
export function Δattribute(
27+
export function ɵɵattribute(
2828
name: string, value: any, sanitizer?: SanitizerFn | null, namespace?: string) {
2929
const index = getSelectedIndex();
30-
return ΔelementAttribute(index, name, Δbind(value), sanitizer, namespace);
30+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
31+
return ɵɵelementAttribute(index, name, ɵɵbind(value), sanitizer, namespace);
3132
}

packages/core/src/render3/instructions/attribute_interpolation.ts

Lines changed: 60 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,10 @@
77
*/
88
import {SanitizerFn} from '../interfaces/sanitization';
99
import {getSelectedIndex} from '../state';
10-
import {ΔelementAttribute} from './element';
11-
import {Δinterpolation1, Δinterpolation2, Δinterpolation3, Δinterpolation4, Δinterpolation5, Δinterpolation6, Δinterpolation7, Δinterpolation8, ΔinterpolationV} from './property_interpolation';
10+
import {ɵɵelementAttribute} from './element';
11+
import {ɵɵinterpolation1, ɵɵinterpolation2, ɵɵinterpolation3, ɵɵinterpolation4, ɵɵinterpolation5, ɵɵinterpolation6, ɵɵinterpolation7, ɵɵinterpolation8, ɵɵinterpolationV} from './property_interpolation';
1212
import {TsickleIssue1009} from './shared';
1313

14-
/**
15-
*
16-
* Update an interpolated attribute on an element with a lone bound value
17-
*
18-
* Used when the value passed to a property has 1 interpolated value in it, an no additional text
19-
* surrounds that interpolated value:
20-
*
21-
* ```html
22-
* <div attr.title="{{v0}}"></div>
23-
* ```
24-
*
25-
* Its compiled representation is::
26-
*
27-
* ```ts
28-
* ΔattributeInterpolate('title', v0);
29-
* ```
30-
*
31-
* @param attrName The name of the attribute to update
32-
* @param prefix Static value used for concatenation only.
33-
* @param v0 Value checked for change.
34-
* @param suffix Static value used for concatenation only.
35-
* @param sanitizer An optional sanitizer function
36-
* @returns itself, so that it may be chained.
37-
* @codeGenApi
38-
*/
39-
export function ΔattributeInterpolate(
40-
attrName: string, v0: any, sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
41-
ΔattributeInterpolate1(attrName, '', v0, '', sanitizer);
42-
return ΔattributeInterpolate;
43-
}
4414

4515

4616
/**
@@ -56,7 +26,7 @@ export function ΔattributeInterpolate(
5626
* Its compiled representation is::
5727
*
5828
* ```ts
59-
* ΔattributeInterpolate1('title', 'prefix', v0, 'suffix');
29+
* ɵɵattributeInterpolate1('title', 'prefix', v0, 'suffix');
6030
* ```
6131
*
6232
* @param attrName The name of the attribute to update
@@ -67,15 +37,17 @@ export function ΔattributeInterpolate(
6737
* @returns itself, so that it may be chained.
6838
* @codeGenApi
6939
*/
70-
export function ΔattributeInterpolate1(
40+
export function ɵɵattributeInterpolate1(
7141
attrName: string, prefix: string, v0: any, suffix: string, sanitizer?: SanitizerFn,
7242
namespace?: string): TsickleIssue1009 {
7343
const index = getSelectedIndex();
74-
const interpolatedValue = Δinterpolation1(prefix, v0, suffix);
7544

76-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
45+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
46+
const interpolatedValue = ɵɵinterpolation1(prefix, v0, suffix);
47+
48+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
7749

78-
return ΔattributeInterpolate1;
50+
return ɵɵattributeInterpolate1;
7951
}
8052

8153
/**
@@ -91,7 +63,7 @@ export function ΔattributeInterpolate1(
9163
* Its compiled representation is::
9264
*
9365
* ```ts
94-
* ΔattributeInterpolate2('title', 'prefix', v0, '-', v1, 'suffix');
66+
* ɵɵattributeInterpolate2('title', 'prefix', v0, '-', v1, 'suffix');
9567
* ```
9668
*
9769
* @param attrName The name of the attribute to update
@@ -104,13 +76,15 @@ export function ΔattributeInterpolate1(
10476
* @returns itself, so that it may be chained.
10577
* @codeGenApi
10678
*/
107-
export function ΔattributeInterpolate2(
79+
export function ɵɵattributeInterpolate2(
10880
attrName: string, prefix: string, v0: any, i0: string, v1: any, suffix: string,
10981
sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
11082
const index = getSelectedIndex();
111-
const interpolatedValue = Δinterpolation2(prefix, v0, i0, v1, suffix);
112-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
113-
return ΔattributeInterpolate2;
83+
84+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
85+
const interpolatedValue = ɵɵinterpolation2(prefix, v0, i0, v1, suffix);
86+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
87+
return ɵɵattributeInterpolate2;
11488
}
11589

11690
/**
@@ -126,7 +100,7 @@ export function ΔattributeInterpolate2(
126100
* Its compiled representation is::
127101
*
128102
* ```ts
129-
* ΔattributeInterpolate3(
103+
* ɵɵattributeInterpolate3(
130104
* 'title', 'prefix', v0, '-', v1, '-', v2, 'suffix');
131105
* ```
132106
*
@@ -142,13 +116,15 @@ export function ΔattributeInterpolate2(
142116
* @returns itself, so that it may be chained.
143117
* @codeGenApi
144118
*/
145-
export function ΔattributeInterpolate3(
119+
export function ɵɵattributeInterpolate3(
146120
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any,
147121
suffix: string, sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
148122
const index = getSelectedIndex();
149-
const interpolatedValue = Δinterpolation3(prefix, v0, i0, v1, i1, v2, suffix);
150-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
151-
return ΔattributeInterpolate3;
123+
124+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
125+
const interpolatedValue = ɵɵinterpolation3(prefix, v0, i0, v1, i1, v2, suffix);
126+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
127+
return ɵɵattributeInterpolate3;
152128
}
153129

154130
/**
@@ -164,7 +140,7 @@ export function ΔattributeInterpolate3(
164140
* Its compiled representation is::
165141
*
166142
* ```ts
167-
* ΔattributeInterpolate4(
143+
* ɵɵattributeInterpolate4(
168144
* 'title', 'prefix', v0, '-', v1, '-', v2, '-', v3, 'suffix');
169145
* ```
170146
*
@@ -182,13 +158,15 @@ export function ΔattributeInterpolate3(
182158
* @returns itself, so that it may be chained.
183159
* @codeGenApi
184160
*/
185-
export function ΔattributeInterpolate4(
161+
export function ɵɵattributeInterpolate4(
186162
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
187163
v3: any, suffix: string, sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
188164
const index = getSelectedIndex();
189-
const interpolatedValue = Δinterpolation4(prefix, v0, i0, v1, i1, v2, i2, v3, suffix);
190-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
191-
return ΔattributeInterpolate4;
165+
166+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
167+
const interpolatedValue = ɵɵinterpolation4(prefix, v0, i0, v1, i1, v2, i2, v3, suffix);
168+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
169+
return ɵɵattributeInterpolate4;
192170
}
193171

194172
/**
@@ -204,7 +182,7 @@ export function ΔattributeInterpolate4(
204182
* Its compiled representation is::
205183
*
206184
* ```ts
207-
* ΔattributeInterpolate5(
185+
* ɵɵattributeInterpolate5(
208186
* 'title', 'prefix', v0, '-', v1, '-', v2, '-', v3, '-', v4, 'suffix');
209187
* ```
210188
*
@@ -224,14 +202,16 @@ export function ΔattributeInterpolate4(
224202
* @returns itself, so that it may be chained.
225203
* @codeGenApi
226204
*/
227-
export function ΔattributeInterpolate5(
205+
export function ɵɵattributeInterpolate5(
228206
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
229207
v3: any, i3: string, v4: any, suffix: string, sanitizer?: SanitizerFn,
230208
namespace?: string): TsickleIssue1009 {
231209
const index = getSelectedIndex();
232-
const interpolatedValue = Δinterpolation5(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, suffix);
233-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
234-
return ΔattributeInterpolate5;
210+
211+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
212+
const interpolatedValue = ɵɵinterpolation5(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, suffix);
213+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
214+
return ɵɵattributeInterpolate5;
235215
}
236216

237217
/**
@@ -247,7 +227,7 @@ export function ΔattributeInterpolate5(
247227
* Its compiled representation is::
248228
*
249229
* ```ts
250-
* ΔattributeInterpolate6(
230+
* ɵɵattributeInterpolate6(
251231
* 'title', 'prefix', v0, '-', v1, '-', v2, '-', v3, '-', v4, '-', v5, 'suffix');
252232
* ```
253233
*
@@ -269,15 +249,16 @@ export function ΔattributeInterpolate5(
269249
* @returns itself, so that it may be chained.
270250
* @codeGenApi
271251
*/
272-
export function ΔattributeInterpolate6(
252+
export function ɵɵattributeInterpolate6(
273253
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
274254
v3: any, i3: string, v4: any, i4: string, v5: any, suffix: string, sanitizer?: SanitizerFn,
275255
namespace?: string): TsickleIssue1009 {
276256
const index = getSelectedIndex();
257+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
277258
const interpolatedValue =
278-
Δinterpolation6(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, suffix);
279-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
280-
return ΔattributeInterpolate6;
259+
ɵɵinterpolation6(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, suffix);
260+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
261+
return ɵɵattributeInterpolate6;
281262
}
282263

283264
/**
@@ -293,7 +274,7 @@ export function ΔattributeInterpolate6(
293274
* Its compiled representation is::
294275
*
295276
* ```ts
296-
* ΔattributeInterpolate7(
277+
* ɵɵattributeInterpolate7(
297278
* 'title', 'prefix', v0, '-', v1, '-', v2, '-', v3, '-', v4, '-', v5, '-', v6, 'suffix');
298279
* ```
299280
*
@@ -317,15 +298,16 @@ export function ΔattributeInterpolate6(
317298
* @returns itself, so that it may be chained.
318299
* @codeGenApi
319300
*/
320-
export function ΔattributeInterpolate7(
301+
export function ɵɵattributeInterpolate7(
321302
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
322303
v3: any, i3: string, v4: any, i4: string, v5: any, i5: string, v6: any, suffix: string,
323304
sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
324305
const index = getSelectedIndex();
306+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
325307
const interpolatedValue =
326-
Δinterpolation7(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, i5, v6, suffix);
327-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
328-
return ΔattributeInterpolate7;
308+
ɵɵinterpolation7(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, i5, v6, suffix);
309+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
310+
return ɵɵattributeInterpolate7;
329311
}
330312

331313
/**
@@ -341,7 +323,7 @@ export function ΔattributeInterpolate7(
341323
* Its compiled representation is::
342324
*
343325
* ```ts
344-
* ΔattributeInterpolate8(
326+
* ɵɵattributeInterpolate8(
345327
* 'title', 'prefix', v0, '-', v1, '-', v2, '-', v3, '-', v4, '-', v5, '-', v6, '-', v7, 'suffix');
346328
* ```
347329
*
@@ -367,15 +349,16 @@ export function ΔattributeInterpolate7(
367349
* @returns itself, so that it may be chained.
368350
* @codeGenApi
369351
*/
370-
export function ΔattributeInterpolate8(
352+
export function ɵɵattributeInterpolate8(
371353
attrName: string, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
372354
v3: any, i3: string, v4: any, i4: string, v5: any, i5: string, v6: any, i6: string, v7: any,
373355
suffix: string, sanitizer?: SanitizerFn, namespace?: string): TsickleIssue1009 {
374356
const index = getSelectedIndex();
357+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
375358
const interpolatedValue =
376-
Δinterpolation8(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, i5, v6, i6, v7, suffix);
377-
ΔelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
378-
return ΔattributeInterpolate8;
359+
ɵɵinterpolation8(prefix, v0, i0, v1, i1, v2, i2, v3, i3, v4, i4, v5, i5, v6, i6, v7, suffix);
360+
ɵɵelementAttribute(index, attrName, interpolatedValue, sanitizer, namespace);
361+
return ɵɵattributeInterpolate8;
379362
}
380363

381364
/**
@@ -391,7 +374,7 @@ export function ΔattributeInterpolate8(
391374
* Its compiled representation is::
392375
*
393376
* ```ts
394-
* ΔattributeInterpolateV(
377+
* ɵɵattributeInterpolateV(
395378
* 'title', ['prefix', v0, '-', v1, '-', v2, '-', v3, '-', v4, '-', v5, '-', v6, '-', v7, '-', v9,
396379
* 'suffix']);
397380
* ```
@@ -404,10 +387,11 @@ export function ΔattributeInterpolate8(
404387
* @returns itself, so that it may be chained.
405388
* @codeGenApi
406389
*/
407-
export function ΔattributeInterpolateV(
390+
export function ɵɵattributeInterpolateV(
408391
attrName: string, values: any[], sanitizer?: SanitizerFn,
409392
namespace?: string): TsickleIssue1009 {
410393
const index = getSelectedIndex();
411-
ΔelementAttribute(index, attrName, ΔinterpolationV(values), sanitizer, namespace);
412-
return ΔattributeInterpolateV;
394+
// TODO(FW-1340): Refactor to remove the use of other instructions here.
395+
ɵɵelementAttribute(index, attrName, ɵɵinterpolationV(values), sanitizer, namespace);
396+
return ɵɵattributeInterpolateV;
413397
}

0 commit comments

Comments
 (0)