Skip to content

Commit 73c8139

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(core): replace styleMapInterpolateX with styleMap (angular#61639)
Replaces the `styleMapInterpolateX` instructions with the existing `styleMap` and a passed-in interpolated value in order to simplify the runtime. PR Close angular#61639
1 parent 2aaea80 commit 73c8139

File tree

10 files changed

+34
-608
lines changed

10 files changed

+34
-608
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/host_bindings/style_interpolation.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ function MyComponent_Template(rf, ctx) {
33
// ...
44
}
55
if (rf & 2) {
6-
$r3$.ɵɵstyleMapInterpolate1("p1:", ctx.p1, ";");
6+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate1("p1:", ctx.p1, ";"));
77
$r3$.ɵɵadvance();
8-
$r3$.ɵɵstyleMapInterpolate2("p1:", ctx.p1, ";p2:", ctx.p2, ";");
8+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate2("p1:", ctx.p1, ";p2:", ctx.p2, ";"));
99
$r3$.ɵɵadvance();
10-
$r3$.ɵɵstyleMapInterpolate3("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";");
10+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate3("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";"));
1111
$r3$.ɵɵadvance();
12-
$r3$.ɵɵstyleMapInterpolate4("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";");
12+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate4("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";"));
1313
$r3$.ɵɵadvance();
14-
$r3$.ɵɵstyleMapInterpolate5("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";");
14+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate5("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";"));
1515
$r3$.ɵɵadvance();
16-
$r3$.ɵɵstyleMapInterpolate6("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";");
16+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate6("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";"));
1717
$r3$.ɵɵadvance();
18-
$r3$.ɵɵstyleMapInterpolate7("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";");
18+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate7("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";"));
1919
$r3$.ɵɵadvance();
20-
$r3$.ɵɵstyleMapInterpolate8("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";p8:", ctx.p8, ";");
20+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolate8("p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";p8:", ctx.p8, ";"));
2121
$r3$.ɵɵadvance();
22-
$r3$.ɵɵstyleMapInterpolateV(["p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";p8:", ctx.p8, ";p9:", ctx.p9, ";"]);
22+
$r3$.ɵɵstyleMap($r3$.ɵɵinterpolateV(["p1:", ctx.p1, ";p2:", ctx.p2, ";p3:", ctx.p3, ";p4:", ctx.p4, ";p5:", ctx.p5, ";p6:", ctx.p6, ";p7:", ctx.p7, ";p8:", ctx.p8, ";p9:", ctx.p9, ";"]));
2323
}
2424
},

packages/compiler/src/render3/r3_identifiers.ts

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

6262
static styleMap: o.ExternalReference = {name: 'ɵɵstyleMap', moduleName: CORE};
6363

64-
static styleMapInterpolate1: o.ExternalReference = {
65-
name: 'ɵɵstyleMapInterpolate1',
66-
moduleName: CORE,
67-
};
68-
static styleMapInterpolate2: o.ExternalReference = {
69-
name: 'ɵɵstyleMapInterpolate2',
70-
moduleName: CORE,
71-
};
72-
static styleMapInterpolate3: o.ExternalReference = {
73-
name: 'ɵɵstyleMapInterpolate3',
74-
moduleName: CORE,
75-
};
76-
static styleMapInterpolate4: o.ExternalReference = {
77-
name: 'ɵɵstyleMapInterpolate4',
78-
moduleName: CORE,
79-
};
80-
static styleMapInterpolate5: o.ExternalReference = {
81-
name: 'ɵɵstyleMapInterpolate5',
82-
moduleName: CORE,
83-
};
84-
static styleMapInterpolate6: o.ExternalReference = {
85-
name: 'ɵɵstyleMapInterpolate6',
86-
moduleName: CORE,
87-
};
88-
static styleMapInterpolate7: o.ExternalReference = {
89-
name: 'ɵɵstyleMapInterpolate7',
90-
moduleName: CORE,
91-
};
92-
static styleMapInterpolate8: o.ExternalReference = {
93-
name: 'ɵɵstyleMapInterpolate8',
94-
moduleName: CORE,
95-
};
96-
static styleMapInterpolateV: o.ExternalReference = {
97-
name: 'ɵɵstyleMapInterpolateV',
98-
moduleName: CORE,
99-
};
100-
10164
static classMap: o.ExternalReference = {name: 'ɵɵclassMap', moduleName: CORE};
10265

10366
static classMapInterpolate1: o.ExternalReference = {

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

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,26 @@ export function classProp(
620620
return call(Identifiers.classProp, [o.literal(name), expression], sourceSpan);
621621
}
622622

623-
export function styleMap(expression: o.Expression, sourceSpan: ParseSourceSpan): ir.UpdateOp {
624-
return call(Identifiers.styleMap, [expression], sourceSpan);
623+
export function styleMap(
624+
expression: o.Expression | ir.Interpolation,
625+
sourceSpan: ParseSourceSpan,
626+
): ir.UpdateOp {
627+
let value: o.Expression;
628+
629+
if (expression instanceof ir.Interpolation) {
630+
const interpolationArgs = collateInterpolationArgs(expression.strings, expression.expressions);
631+
value = callVariadicInstructionExpr(
632+
VALUE_INTERPOLATE_CONFIG,
633+
[],
634+
interpolationArgs,
635+
[],
636+
sourceSpan,
637+
);
638+
} else {
639+
value = expression;
640+
}
641+
642+
return call(Identifiers.styleMap, [value], sourceSpan);
625643
}
626644

627645
export function classMap(expression: o.Expression, sourceSpan: ParseSourceSpan): ir.UpdateOp {
@@ -689,22 +707,6 @@ export function propertyInterpolate(
689707
);
690708
}
691709

692-
export function styleMapInterpolate(
693-
strings: string[],
694-
expressions: o.Expression[],
695-
sourceSpan: ParseSourceSpan,
696-
): ir.UpdateOp {
697-
const interpolationArgs = collateInterpolationArgs(strings, expressions);
698-
699-
return callVariadicInstruction(
700-
STYLE_MAP_INTERPOLATE_CONFIG,
701-
[],
702-
interpolationArgs,
703-
[],
704-
sourceSpan,
705-
);
706-
}
707-
708710
export function classMapInterpolate(
709711
strings: string[],
710712
expressions: o.Expression[],
@@ -889,30 +891,6 @@ const VALUE_INTERPOLATE_CONFIG: VariadicInstructionConfig = {
889891
},
890892
};
891893

892-
/**
893-
* `InterpolationConfig` for the `styleMapInterpolate` instruction.
894-
*/
895-
const STYLE_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = {
896-
constant: [
897-
Identifiers.styleMap,
898-
Identifiers.styleMapInterpolate1,
899-
Identifiers.styleMapInterpolate2,
900-
Identifiers.styleMapInterpolate3,
901-
Identifiers.styleMapInterpolate4,
902-
Identifiers.styleMapInterpolate5,
903-
Identifiers.styleMapInterpolate6,
904-
Identifiers.styleMapInterpolate7,
905-
Identifiers.styleMapInterpolate8,
906-
],
907-
variable: Identifiers.styleMapInterpolateV,
908-
mapping: (n) => {
909-
if (n % 2 === 0) {
910-
throw new Error(`Expected odd number of arguments`);
911-
}
912-
return (n - 1) / 2;
913-
},
914-
};
915-
916894
/**
917895
* `InterpolationConfig` for the `classMapInterpolate` instruction.
918896
*/

packages/compiler/src/template/pipeline/src/phases/collapse_singleton_interpolations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {CompilationJob} from '../compilation';
2222
export function collapseSingletonInterpolations(job: CompilationJob): void {
2323
for (const unit of job.units) {
2424
for (const op of unit.update) {
25-
const eligibleOpKind = op.kind === ir.OpKind.Attribute || op.kind === ir.OpKind.StyleProp;
25+
const eligibleOpKind =
26+
op.kind === ir.OpKind.Attribute ||
27+
op.kind === ir.OpKind.StyleProp ||
28+
op.kind == ir.OpKind.StyleMap;
2629
if (
2730
eligibleOpKind &&
2831
op.expression instanceof ir.Interpolation &&

packages/compiler/src/template/pipeline/src/phases/reify.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,7 @@ function reifyUpdateOperations(_unit: CompilationUnit, ops: ir.OpList<ir.UpdateO
515515
ir.OpList.replace(op, ng.classProp(op.name, op.expression, op.sourceSpan));
516516
break;
517517
case ir.OpKind.StyleMap:
518-
if (op.expression instanceof ir.Interpolation) {
519-
ir.OpList.replace(
520-
op,
521-
ng.styleMapInterpolate(op.expression.strings, op.expression.expressions, op.sourceSpan),
522-
);
523-
} else {
524-
ir.OpList.replace(op, ng.styleMap(op.expression, op.sourceSpan));
525-
}
518+
ir.OpList.replace(op, ng.styleMap(op.expression, op.sourceSpan));
526519
break;
527520
case ir.OpKind.ClassMap:
528521
if (op.expression instanceof ir.Interpolation) {

packages/core/src/core_render3_private_export.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ export {
188188
ɵɵgetComponentDepsFactory,
189189
ɵɵExternalStylesFeature,
190190
ɵɵstyleMap,
191-
ɵɵstyleMapInterpolate1,
192-
ɵɵstyleMapInterpolate2,
193-
ɵɵstyleMapInterpolate3,
194-
ɵɵstyleMapInterpolate4,
195-
ɵɵstyleMapInterpolate5,
196-
ɵɵstyleMapInterpolate6,
197-
ɵɵstyleMapInterpolate7,
198-
ɵɵstyleMapInterpolate8,
199-
ɵɵstyleMapInterpolateV,
200191
ɵɵstyleProp,
201192
ɵɵsyntheticHostListener,
202193
ɵɵsyntheticHostProperty,

packages/core/src/render3/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ export {
118118
ɵɵrepeaterTrackByIdentity,
119119
ɵɵrepeaterTrackByIndex,
120120
ɵɵstyleMap,
121-
ɵɵstyleMapInterpolate1,
122-
ɵɵstyleMapInterpolate2,
123-
ɵɵstyleMapInterpolate3,
124-
ɵɵstyleMapInterpolate4,
125-
ɵɵstyleMapInterpolate5,
126-
ɵɵstyleMapInterpolate6,
127-
ɵɵstyleMapInterpolate7,
128-
ɵɵstyleMapInterpolate8,
129-
ɵɵstyleMapInterpolateV,
130121
ɵɵstyleProp,
131122
ɵɵsyntheticHostListener,
132123
ɵɵsyntheticHostProperty,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export * from './property_interpolation';
5454
export * from './queries';
5555
export * from './queries_signals';
5656
export * from './storage';
57-
export * from './style_map_interpolation';
5857
export * from './styling';
5958
export * from './template';
6059
export * from './text';

0 commit comments

Comments
 (0)