Skip to content

Commit 8fbe558

Browse files
crisbetothePunderWoman
authored andcommitted
perf(core): move property remapping for dom properties to compiler (#62421)
Since we know that DOM properties won't go to an inputs, we can move the remapping logic to the compiler, saving us some processing on the client. PR Close #62421
1 parent c30f4ee commit 8fbe558

16 files changed

Lines changed: 118 additions & 36 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ template: function MyComponent_Template(rf, ctx) {
1212
$r3$.ɵɵadvance(3);
1313
$r3$.ɵɵattribute("aria-label", ctx.value1)("aria-label", ctx.value2);
1414
$r3$.ɵɵadvance();
15-
$r3$.ɵɵdomProperty("tabindex", ctx.value1)("tabindex", ctx.value2);
15+
$r3$.ɵɵdomProperty("tabIndex", ctx.value1)("tabIndex", ctx.value2);
1616
$r3$.ɵɵadvance();
1717
$r3$.ɵɵclassMap(ctx.value2);
1818
$r3$.ɵɵadvance();
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
hostBindings: function MyDirective_HostBindings(rf, ctx) {
22
…
33
if (rf & 2) {
4-
$r3$.ɵɵdomProperty("tabindex", 1);
4+
$r3$.ɵɵdomProperty("tabIndex", 1);
55
$r3$.ɵɵattribute("title", "my title")("id", "my-id");
66
}
77
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
hostBindings: function MyDirective_HostBindings(rf, ctx) {
22
…
33
if (rf & 2) {
4-
$r3$.ɵɵdomProperty("title", ctx.myTitle)("tabindex", 1)("id", ctx.myId);
4+
$r3$.ɵɵdomProperty("title", ctx.myTitle)("tabIndex", 1)("id", ctx.myId);
55
}
66
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
hostBindings: function MyDirective_HostBindings(rf, ctx) {
22
…
33
if (rf & 2) {
4-
$r3$.ɵɵdomProperty("tabindex", 1)("title", ctx.myTitle)("id", ctx.myId);
4+
$r3$.ɵɵdomProperty("tabIndex", 1)("title", ctx.myTitle)("id", ctx.myId);
55
}
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
hostBindings: function HostBindingDir_HostBindings(rf, ctx) {
22
if (rf & 2) {
3-
$r3$.ɵɵdomProperty("innerHtml", ctx.evil, $r3$.ɵɵsanitizeHtml)("href", ctx.evil, $r3$.ɵɵsanitizeUrlOrResourceUrl)("src", ctx.evil, $r3$.ɵɵsanitizeUrlOrResourceUrl)("sandbox", ctx.evil, $r3$.ɵɵvalidateIframeAttribute);
3+
$r3$.ɵɵdomProperty("innerHTML", ctx.evil, $r3$.ɵɵsanitizeHtml)("href", ctx.evil, $r3$.ɵɵsanitizeUrlOrResourceUrl)("src", ctx.evil, $r3$.ɵɵsanitizeUrlOrResourceUrl)("sandbox", ctx.evil, $r3$.ɵɵvalidateIframeAttribute);
44
$r3$.ɵɵattribute("style", ctx.evil, $r3$.ɵɵsanitizeStyle);
55
}
66
}
77
…
88
hostBindings: function HostBindingDir2_HostBindings(rf, ctx) {
99
if (rf & 2) {
10-
$r3$.ɵɵdomProperty("innerHtml", ctx.evil, $r3$.ɵɵsanitizeHtml)("href", ctx.evil, $r3$.ɵɵsanitizeUrl)("src", ctx.evil)("sandbox", ctx.evil, $r3$.ɵɵvalidateIframeAttribute);
10+
$r3$.ɵɵdomProperty("innerHTML", ctx.evil, $r3$.ɵɵsanitizeHtml)("href", ctx.evil, $r3$.ɵɵsanitizeUrl)("src", ctx.evil)("sandbox", ctx.evil, $r3$.ɵɵvalidateIframeAttribute);
1111
$r3$.ɵɵattribute("style", ctx.evil, $r3$.ɵɵsanitizeStyle);
1212
}
1313
}

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export declare class MyModule {
166166
}
167167

168168
/****************************************************************************************************
169-
* PARTIAL FILE: special_property_remapping.js
169+
* PARTIAL FILE: special_property_remapping_property.js
170170
****************************************************************************************************/
171171
import { Component, NgModule } from '@angular/core';
172172
import * as i0 from "@angular/core";
@@ -176,15 +176,13 @@ export class MyComponent {
176176
}
177177
}
178178
MyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
179-
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, isStandalone: false, selector: "my-component", ngImport: i0, template: `
180-
<label [for]="forValue"></label>`, isInline: true });
179+
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, isStandalone: false, selector: "my-component", ngImport: i0, template: `<label [for]="forValue"></label>`, isInline: true });
181180
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, decorators: [{
182181
type: Component,
183182
args: [{
184183
selector: 'my-component',
185-
template: `
186-
<label [for]="forValue"></label>`,
187-
standalone: false
184+
template: `<label [for]="forValue"></label>`,
185+
standalone: false,
188186
}]
189187
}] });
190188
export class MyModule {
@@ -198,7 +196,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
198196
}] });
199197

200198
/****************************************************************************************************
201-
* PARTIAL FILE: special_property_remapping.d.ts
199+
* PARTIAL FILE: special_property_remapping_property.d.ts
202200
****************************************************************************************************/
203201
import * as i0 from "@angular/core";
204202
export declare class MyComponent {
@@ -212,6 +210,35 @@ export declare class MyModule {
212210
static ɵinj: i0.ɵɵInjectorDeclaration<MyModule>;
213211
}
214212

213+
/****************************************************************************************************
214+
* PARTIAL FILE: special_property_remapping_dom_property.js
215+
****************************************************************************************************/
216+
import { Component } from '@angular/core';
217+
import * as i0 from "@angular/core";
218+
export class MyComponent {
219+
constructor() {
220+
this.forValue = 'some-input';
221+
}
222+
}
223+
MyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
224+
MyComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, isStandalone: true, selector: "ng-component", ngImport: i0, template: `<label [for]="forValue"></label>`, isInline: true });
225+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, decorators: [{
226+
type: Component,
227+
args: [{
228+
template: `<label [for]="forValue"></label>`,
229+
}]
230+
}] });
231+
232+
/****************************************************************************************************
233+
* PARTIAL FILE: special_property_remapping_dom_property.d.ts
234+
****************************************************************************************************/
235+
import * as i0 from "@angular/core";
236+
export declare class MyComponent {
237+
forValue: string;
238+
static ɵfac: i0.ɵɵFactoryDeclaration<MyComponent, never>;
239+
static ɵcmp: i0.ɵɵComponentDeclaration<MyComponent, "ng-component", never, {}, {}, never, never, true, never>;
240+
}
241+
215242
/****************************************************************************************************
216243
* PARTIAL FILE: temporary_variables.js
217244
****************************************************************************************************/

‎packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/property_bindings/TEST_CASES.json‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,29 @@
4444
]
4545
},
4646
{
47-
"description": "should not remap property names whose names do not correspond to their attribute names",
47+
"description": "should not remap special property names when outputting property instructions",
4848
"inputFiles": [
49-
"special_property_remapping.ts"
49+
"special_property_remapping_property.ts"
5050
],
5151
"expectations": [
5252
{
5353
"failureMessage": "Incorrect template",
5454
"files": [
55-
"special_property_remapping.js"
55+
"special_property_remapping_property.js"
56+
]
57+
}
58+
]
59+
},
60+
{
61+
"description": "should remap special property names when outputting domProperty instructions",
62+
"inputFiles": [
63+
"special_property_remapping_dom_property.ts"
64+
],
65+
"expectations": [
66+
{
67+
"failureMessage": "Incorrect template",
68+
"files": [
69+
"special_property_remapping_dom_property.js"
5670
]
5771
}
5872
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ template: function MyComponent_Template(rf, ctx) {
33
$r3$.ɵɵdomElement(0, "div", 0)(1, "link", 1)(2, "div")(3, "img", 2)(4, "iframe", 3)(5, "a", 1)(6, "div");
44
}
55
if (rf & 2) {
6-
$r3$.ɵɵdomProperty("innerHtml", ctx.evil, $r3$.ɵɵsanitizeHtml);
6+
$r3$.ɵɵdomProperty("innerHTML", ctx.evil, $r3$.ɵɵsanitizeHtml);
77
$r3$.ɵɵadvance();
88
$r3$.ɵɵdomProperty("href", ctx.evil, $r3$.ɵɵsanitizeResourceUrl);
99
$r3$.ɵɵadvance();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
consts: [[__AttributeMarker.Bindings__, "for"]]
3+
4+
…
5+
6+
function MyComponent_Template(rf, ctx) {
7+
if (rf & 1) {
8+
$i0$.ɵɵdomElement(0, "label", 0);
9+
}
10+
if (rf & 2) {
11+
$i0$.ɵɵdomProperty("htmlFor", ctx.forValue);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
template: `<label [for]="forValue"></label>`,
5+
})
6+
export class MyComponent {
7+
forValue = 'some-input';
8+
}

0 commit comments

Comments
 (0)