Skip to content

Commit 2aaea80

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(core): replace stylePropInterpolateX with styleProp (angular#61639)
Replaces all of the `stylePropInterpolateX` instructions with the existing `styleProp` with an interpolated value. PR Close angular#61639
1 parent f3dfad3 commit 2aaea80

File tree

18 files changed

+49
-754
lines changed

18 files changed

+49
-754
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/chaining/break_different_instructions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
44
template: function MyComponent_Template(rf, $ctx$) {
55
// ...
66
if (rf & 2) {
7-
$r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b")("border", "a", ctx.one, "b");
8-
$r3$.ɵɵstyleProp("transition", ctx.transition)("width", ctx.width);
9-
$r3$.ɵɵstylePropInterpolate1("height", "a", ctx.one, "b")("top", "a", ctx.one, "b");
7+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("border", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("transition", ctx.transition)("width", ctx.width)("height", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("top", $r3$.ɵɵinterpolate1("a", ctx.one, "b"));
108
$r3$.ɵɵclassProp("apple", ctx.yesToApple)("orange", ctx.yesToOrange);
119
}
1210
},

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/chaining/break_different_interpolation_instructions.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
44
template: function MyComponent_Template(rf, $ctx$) {
55
// ...
66
if (rf & 2) {
7-
$r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b")("border", "a", ctx.one, "b");
8-
$r3$.ɵɵstylePropInterpolate2("transition", "a", ctx.one, "b", ctx.two, "c");
9-
$r3$.ɵɵstylePropInterpolate3("width", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d");
10-
$r3$.ɵɵstylePropInterpolate1("height", "a", ctx.one, "b")("top", "a", ctx.one, "b");
7+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("border", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("transition", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"))("width", $r3$.ɵɵinterpolate3("a", ctx.one, "b", ctx.two, "c", ctx.three, "d"))("height", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("top", $r3$.ɵɵinterpolate1("a", ctx.one, "b"));
118
}
129
},
1310
encapsulation: 2

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/chaining/interpolations_different_arity.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
44
template: function MyComponent_Template(rf, $ctx$) {
55
// ...
66
if (rf & 2) {
7-
$r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b")("border", "a", ctx.one, "b");
8-
$r3$.ɵɵstylePropInterpolate2("transition", "a", ctx.one, "b", ctx.two, "c")("width", "a", ctx.one, "b", ctx.two, "c");
9-
$r3$.ɵɵstylePropInterpolate3("height", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d")("top", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d");
7+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("border", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("transition", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"))("width", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"))("height", $r3$.ɵɵinterpolate3("a", ctx.one, "b", ctx.two, "c", ctx.three, "d"))("top", $r3$.ɵɵinterpolate3("a", ctx.one, "b", ctx.two, "c", ctx.three, "d"));
108
}
119
},
1210
encapsulation: 2

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/chaining/interpolations_equal_arity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
44
template: function MyComponent_Template(rf, $ctx$) {
55
// ...
66
if (rf & 2) {
7-
$r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b")("border", "a", ctx.one, "b")("transition", "a", ctx.one, "b");
7+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("border", $r3$.ɵɵinterpolate1("a", ctx.one, "b"))("transition", $r3$.ɵɵinterpolate1("a", ctx.one, "b"));
88
}
99
},
1010
encapsulation: 2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ...
22
if (rf & 2) {
3-
$r3$.ɵɵstylePropInterpolate2("width", "a", ctx.one, "b", ctx.two, "c");
3+
$r3$.ɵɵstyleProp("width", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"));
44
}
55
// ...
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// ...
22
if (rf & 2) {
3-
$r3$.ɵɵstylePropInterpolate1("background", "url(", ctx.myUrl1, ")");
4-
$r3$.ɵɵstylePropInterpolate2("border-image", "url(", ctx.myUrl2, ") ", ctx.myRepeat, " auto");
5-
$r3$.ɵɵstylePropInterpolate3("box-shadow", "", ctx.myBoxX, " ", ctx.myBoxY, " ", ctx.myBoxWidth, " black");
3+
$r3$.ɵɵstyleProp("background", $r3$.ɵɵinterpolate1("url(", ctx.myUrl1, ")"))("border-image", $r3$.ɵɵinterpolate2("url(", ctx.myUrl2, ") ", ctx.myRepeat, " auto"))("box-shadow", $r3$.ɵɵinterpolate3("", ctx.myBoxX, " ", ctx.myBoxY, " ", ctx.myBoxWidth, " black"));
64
}
75
// ...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ...
22
if (rf & 2) {
3-
$r3$.ɵɵstylePropInterpolate2("width", "a", ctx.one, "b", ctx.two, "c", "px");
3+
$r3$.ɵɵstyleProp("width", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"), "px");
44
}
55
// ...

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/interpolations/style_properties.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// ...
22
if (rf & 2) {
3-
$r3$.ɵɵstylePropInterpolateV("color", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]);
3+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolateV(["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]));
44
$r3$.ɵɵadvance();
5-
$r3$.ɵɵstylePropInterpolate8("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i");
5+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate8("a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"));
66
$r3$.ɵɵadvance();
7-
$r3$.ɵɵstylePropInterpolate7("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h");
7+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate7("a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"));
88
$r3$.ɵɵadvance();
9-
$r3$.ɵɵstylePropInterpolate6("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g");
9+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate6("a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"));
1010
$r3$.ɵɵadvance();
11-
$r3$.ɵɵstylePropInterpolate5("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f");
11+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate5("a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"));
1212
$r3$.ɵɵadvance();
13-
$r3$.ɵɵstylePropInterpolate4("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e");
13+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate4("a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"));
1414
$r3$.ɵɵadvance();
15-
$r3$.ɵɵstylePropInterpolate3("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d");
15+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate3("a", ctx.one, "b", ctx.two, "c", ctx.three, "d"));
1616
$r3$.ɵɵadvance();
17-
$r3$.ɵɵstylePropInterpolate2("color", "a", ctx.one, "b", ctx.two, "c");
17+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate2("a", ctx.one, "b", ctx.two, "c"));
1818
$r3$.ɵɵadvance();
19-
$r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b");
19+
$r3$.ɵɵstyleProp("color", $r3$.ɵɵinterpolate1("a", ctx.one, "b"));
2020
$r3$.ɵɵadvance();
2121
$r3$.ɵɵstyleProp("color", ctx.one);
2222
}

packages/compiler/src/render3/r3_identifiers.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -139,43 +139,6 @@ export class Identifiers {
139139

140140
static styleProp: o.ExternalReference = {name: 'ɵɵstyleProp', moduleName: CORE};
141141

142-
static stylePropInterpolate1: o.ExternalReference = {
143-
name: 'ɵɵstylePropInterpolate1',
144-
moduleName: CORE,
145-
};
146-
static stylePropInterpolate2: o.ExternalReference = {
147-
name: 'ɵɵstylePropInterpolate2',
148-
moduleName: CORE,
149-
};
150-
static stylePropInterpolate3: o.ExternalReference = {
151-
name: 'ɵɵstylePropInterpolate3',
152-
moduleName: CORE,
153-
};
154-
static stylePropInterpolate4: o.ExternalReference = {
155-
name: 'ɵɵstylePropInterpolate4',
156-
moduleName: CORE,
157-
};
158-
static stylePropInterpolate5: o.ExternalReference = {
159-
name: 'ɵɵstylePropInterpolate5',
160-
moduleName: CORE,
161-
};
162-
static stylePropInterpolate6: o.ExternalReference = {
163-
name: 'ɵɵstylePropInterpolate6',
164-
moduleName: CORE,
165-
};
166-
static stylePropInterpolate7: o.ExternalReference = {
167-
name: 'ɵɵstylePropInterpolate7',
168-
moduleName: CORE,
169-
};
170-
static stylePropInterpolate8: o.ExternalReference = {
171-
name: 'ɵɵstylePropInterpolate8',
172-
moduleName: CORE,
173-
};
174-
static stylePropInterpolateV: o.ExternalReference = {
175-
name: 'ɵɵstylePropInterpolateV',
176-
moduleName: CORE,
177-
};
178-
179142
static interpolate: o.ExternalReference = {
180143
name: 'ɵɵinterpolate',
181144
moduleName: CORE,

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

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,21 @@ export function twoWayProperty(
565565

566566
export function attribute(
567567
name: string,
568-
expression: o.Expression,
568+
expression: o.Expression | ir.Interpolation,
569569
sanitizer: o.Expression | null,
570570
namespace: string | null,
571+
sourceSpan: ParseSourceSpan,
571572
): ir.UpdateOp {
572-
const args = [o.literal(name), expression];
573+
const args: o.Expression[] = [o.literal(name)];
574+
575+
if (expression instanceof ir.Interpolation) {
576+
const interpolationArgs = collateInterpolationArgs(expression.strings, expression.expressions);
577+
args.push(
578+
callVariadicInstructionExpr(VALUE_INTERPOLATE_CONFIG, [], interpolationArgs, [], sourceSpan),
579+
);
580+
} else {
581+
args.push(expression);
582+
}
573583
if (sanitizer !== null || namespace !== null) {
574584
args.push(sanitizer ?? o.literal(null));
575585
}
@@ -581,11 +591,21 @@ export function attribute(
581591

582592
export function styleProp(
583593
name: string,
584-
expression: o.Expression,
594+
expression: o.Expression | ir.Interpolation,
585595
unit: string | null,
586596
sourceSpan: ParseSourceSpan,
587597
): ir.UpdateOp {
588-
const args = [o.literal(name), expression];
598+
const args: o.Expression[] = [o.literal(name)];
599+
600+
if (expression instanceof ir.Interpolation) {
601+
const interpolationArgs = collateInterpolationArgs(expression.strings, expression.expressions);
602+
args.push(
603+
callVariadicInstructionExpr(VALUE_INTERPOLATE_CONFIG, [], interpolationArgs, [], sourceSpan),
604+
);
605+
} else {
606+
args.push(expression);
607+
}
608+
589609
if (unit !== null) {
590610
args.push(o.literal(unit));
591611
}
@@ -669,48 +689,6 @@ export function propertyInterpolate(
669689
);
670690
}
671691

672-
export function attributeInterpolate(
673-
name: string,
674-
strings: string[],
675-
expressions: o.Expression[],
676-
sanitizer: o.Expression | null,
677-
namespace: string | null,
678-
sourceSpan: ParseSourceSpan,
679-
): ir.UpdateOp {
680-
const interpolationArgs = collateInterpolationArgs(strings, expressions);
681-
const value = callVariadicInstructionExpr(
682-
VALUE_INTERPOLATE_CONFIG,
683-
[],
684-
interpolationArgs,
685-
[],
686-
sourceSpan,
687-
);
688-
return attribute(name, value, sanitizer, namespace);
689-
}
690-
691-
export function stylePropInterpolate(
692-
name: string,
693-
strings: string[],
694-
expressions: o.Expression[],
695-
unit: string | null,
696-
sourceSpan: ParseSourceSpan,
697-
): ir.UpdateOp {
698-
const interpolationArgs = collateInterpolationArgs(strings, expressions);
699-
700-
const extraArgs: o.Expression[] = [];
701-
if (unit !== null) {
702-
extraArgs.push(o.literal(unit));
703-
}
704-
705-
return callVariadicInstruction(
706-
STYLE_PROP_INTERPOLATE_CONFIG,
707-
[o.literal(name)],
708-
interpolationArgs,
709-
extraArgs,
710-
sourceSpan,
711-
);
712-
}
713-
714692
export function styleMapInterpolate(
715693
strings: string[],
716694
expressions: o.Expression[],
@@ -911,30 +889,6 @@ const VALUE_INTERPOLATE_CONFIG: VariadicInstructionConfig = {
911889
},
912890
};
913891

914-
/**
915-
* `InterpolationConfig` for the `stylePropInterpolate` instruction.
916-
*/
917-
const STYLE_PROP_INTERPOLATE_CONFIG: VariadicInstructionConfig = {
918-
constant: [
919-
Identifiers.styleProp,
920-
Identifiers.stylePropInterpolate1,
921-
Identifiers.stylePropInterpolate2,
922-
Identifiers.stylePropInterpolate3,
923-
Identifiers.stylePropInterpolate4,
924-
Identifiers.stylePropInterpolate5,
925-
Identifiers.stylePropInterpolate6,
926-
Identifiers.stylePropInterpolate7,
927-
Identifiers.stylePropInterpolate8,
928-
],
929-
variable: Identifiers.stylePropInterpolateV,
930-
mapping: (n) => {
931-
if (n % 2 === 0) {
932-
throw new Error(`Expected odd number of arguments`);
933-
}
934-
return (n - 1) / 2;
935-
},
936-
};
937-
938892
/**
939893
* `InterpolationConfig` for the `styleMapInterpolate` instruction.
940894
*/

0 commit comments

Comments
 (0)