Skip to content

Commit d1df0a9

Browse files
benleshmhevery
authored andcommitted
refactor(ivy): remove ɵɵelementProperty instruction (angular#30645)
- Removes ɵɵelementProperty instruction - Updates tests that were using it - NOTE: There is one test under `render3/integration_spec.ts` that is commented out, and needs to be reviewed. Basically, I could not find a good why to test what it was doing, because it was doing things that I am not sure we could generate in an acceptance test. PR Close angular#30645
1 parent 00cc905 commit d1df0a9

File tree

15 files changed

+146
-126
lines changed

15 files changed

+146
-126
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
@@ -138,7 +138,7 @@ describe('compiler compliance: bindings', () => {
138138
}
139139
};
140140
const result = compile(files, angularFiles);
141-
expect(result.source).not.toContain('i0.ɵɵelementProperty');
141+
expect(result.source).not.toContain('i0.ɵɵproperty');
142142
});
143143

144144
it('should not remap property names whose names do not correspond to their attribute names',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ describe('ngtsc behavioral tests', () => {
20432043
`);
20442044
env.driveMain();
20452045
const jsContents = env.getContents('test.js');
2046-
expect(jsContents).not.toContain('i0.ɵɵelementProperty');
2046+
expect(jsContents).not.toContain('i0.ɵɵproperty');
20472047
});
20482048

20492049
it('should correctly recognize local symbols', () => {

packages/compiler/src/render3/r3_identifiers.ts

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

3030
static elementEnd: o.ExternalReference = {name: 'ɵɵelementEnd', moduleName: CORE};
3131

32-
static elementProperty: o.ExternalReference = {name: 'ɵɵelementProperty', moduleName: CORE};
33-
3432
static select: o.ExternalReference = {name: 'ɵɵselect', moduleName: CORE};
3533

3634
static updateSyntheticHostBinding:

packages/core/src/core_render3_private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export {
108108
ɵɵcontentQuery,
109109
ɵɵloadContentQuery,
110110
ɵɵelementEnd,
111-
ɵɵelementProperty,
112111
ɵɵproperty,
113112
ɵɵpropertyInterpolate,
114113
ɵɵpropertyInterpolate1,

packages/core/src/render3/VIEW_DATA.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ class MyApp {
9898
ɵɵelementEnd();
9999
}
100100
if (rf & RenderFlags.Update) {
101-
ɵɵelementProperty(0, 'title', ɵɵbind(ctx.name));
102-
ɵɵtextBinding(1, ɵɵinterpolation1('Hello ', ctx.name, '!'));
101+
ɵɵselect(0);
102+
ɵɵproperty('title', ctx.name);
103+
ɵɵselect(1);
104+
ɵɵtextInterpolate1('Hello ', ctx.name, '!');
103105
}
104106
...
105107
}

packages/core/src/render3/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export {
5454
ɵɵelementEnd,
5555

5656
ɵɵelementHostAttrs,
57-
ɵɵelementProperty,
5857
ɵɵelementStart,
5958
ɵɵembeddedViewEnd,
6059

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,6 @@ export function ɵɵbind<T>(value: T): T|NO_CHANGE {
6161
return bindingUpdated(lView, bindingIndex, value) ? value : NO_CHANGE;
6262
}
6363

64-
/**
65-
* **TODO: Remove this function after `property` is in use**
66-
* Update a property on an element.
67-
*
68-
* If the property name also exists as an input property on one of the element's directives,
69-
* the component property will be set instead of the element property. This check must
70-
* be conducted at runtime so child components that add new @Inputs don't have to be re-compiled.
71-
*
72-
* @param index The index of the element to update in the data array
73-
* @param propName Name of property. Because it is going to DOM, this is not subject to
74-
* renaming as part of minification.
75-
* @param value New value to write.
76-
* @param sanitizer An optional function used to sanitize the value.
77-
* @param nativeOnly Whether or not we should only set native properties and skip input check
78-
* (this is necessary for host property bindings)
79-
*
80-
* @codeGenApi
81-
*/
82-
export function ɵɵelementProperty<T>(
83-
index: number, propName: string, value: T | NO_CHANGE, sanitizer?: SanitizerFn | null,
84-
nativeOnly?: boolean): void {
85-
if (value !== NO_CHANGE) {
86-
elementPropertyInternal(index, propName, value, sanitizer, nativeOnly);
87-
}
88-
}
89-
9064
/**
9165
* Updates a synthetic host binding (e.g. `[@foo]`) on a component.
9266
*

packages/core/src/render3/jit/environment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export const angularCoreEnv: {[name: string]: Function} =
8787
'ɵɵlistener': r3.ɵɵlistener,
8888
'ɵɵload': r3.ɵɵload,
8989
'ɵɵprojection': r3.ɵɵprojection,
90-
'ɵɵelementProperty': r3.ɵɵelementProperty,
9190
'ɵɵupdateSyntheticHostBinding': r3.ɵɵupdateSyntheticHostBinding,
9291
'ɵɵcomponentHostSyntheticListener': r3.ɵɵcomponentHostSyntheticListener,
9392
'ɵɵpipeBind1': r3.ɵɵpipeBind1,

packages/core/test/render3/change_detection_spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {withBody} from '@angular/private/testing';
1010

1111
import {ChangeDetectionStrategy, DoCheck} from '../../src/core';
1212
import {whenRendered} from '../../src/render3/component';
13-
import {LifecycleHooksFeature, getRenderedText, ɵɵdefineComponent, ɵɵgetCurrentView} from '../../src/render3/index';
14-
import {detectChanges, markDirty, tick, ɵɵbind, ɵɵelement, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵinterpolation1, ɵɵinterpolation2, ɵɵlistener, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
13+
import {LifecycleHooksFeature, getRenderedText, ɵɵdefineComponent, ɵɵgetCurrentView, ɵɵproperty, ɵɵselect} from '../../src/render3/index';
14+
import {detectChanges, markDirty, tick, ɵɵbind, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵinterpolation1, ɵɵinterpolation2, ɵɵlistener, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
1515
import {RenderFlags} from '../../src/render3/interfaces/definition';
1616
import {Renderer3, RendererFactory3} from '../../src/render3/interfaces/renderer';
1717
import {FLAGS, LViewFlags} from '../../src/render3/interfaces/view';
@@ -186,7 +186,8 @@ describe('change detection', () => {
186186
ɵɵelement(0, 'manual-comp');
187187
}
188188
if (rf & RenderFlags.Update) {
189-
ɵɵelementProperty(0, 'name', ɵɵbind(ctx.name));
189+
ɵɵselect(0);
190+
ɵɵproperty('name', ctx.name);
190191
}
191192

192193
},

packages/core/test/render3/component_spec.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {ViewEncapsulation, ɵɵdefineInjectable, ɵɵdefineInjector} from '../../src/core';
1010
import {createInjector} from '../../src/di/r3_injector';
11-
import {AttributeMarker, ComponentFactory, LifecycleHooksFeature, getRenderedText, markDirty, ɵɵdefineComponent, ɵɵdirectiveInject, ɵɵtemplate} from '../../src/render3/index';
12-
import {tick, ɵɵbind, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelement, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵnextContext, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
11+
import {AttributeMarker, ComponentFactory, LifecycleHooksFeature, getRenderedText, markDirty, ɵɵdefineComponent, ɵɵdirectiveInject, ɵɵproperty, ɵɵselect, ɵɵtemplate} from '../../src/render3/index';
12+
import {tick, ɵɵbind, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵnextContext, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
1313
import {ComponentDef, RenderFlags} from '../../src/render3/interfaces/definition';
1414

1515
import {NgIf} from './common_with_def';
@@ -137,7 +137,8 @@ describe('component', () => {
137137
ɵɵelement(4097, 'comp');
138138
}
139139
if (rf & RenderFlags.Update) {
140-
ɵɵelementProperty(4097, 'name', ɵɵbind(ctx.name));
140+
ɵɵselect(4097);
141+
ɵɵproperty('name', ctx.name);
141142
}
142143
}, 4098, 1, [Comp]);
143144

@@ -188,7 +189,8 @@ it('should not invoke renderer destroy method for embedded views', () => {
188189
2, MyComponent_div_Template_2, 2, 0, 'div', [AttributeMarker.Template, 'ngIf']);
189190
}
190191
if (rf & RenderFlags.Update) {
191-
ɵɵelementProperty(2, 'ngIf', ɵɵbind(ctx.visible));
192+
ɵɵselect(2);
193+
ɵɵproperty('ngIf', ctx.visible);
192194
}
193195
}
194196
});
@@ -269,7 +271,8 @@ describe('component with a container', () => {
269271
ɵɵelement(0, 'wrapper');
270272
}
271273
if (rf & RenderFlags.Update) {
272-
ɵɵelementProperty(0, 'items', ɵɵbind(ctx.items));
274+
ɵɵselect(0);
275+
ɵɵproperty('items', ctx.items);
273276
}
274277
}
275278

@@ -339,7 +342,8 @@ describe('recursive components', () => {
339342
ɵɵelement(0, 'tree-comp');
340343
}
341344
if (rf0 & RenderFlags.Update) {
342-
ɵɵelementProperty(0, 'data', ɵɵbind(ctx.data.left));
345+
ɵɵselect(0);
346+
ɵɵproperty('data', ctx.data.left);
343347
}
344348
ɵɵembeddedViewEnd();
345349
}
@@ -353,7 +357,8 @@ describe('recursive components', () => {
353357
ɵɵelement(0, 'tree-comp');
354358
}
355359
if (rf0 & RenderFlags.Update) {
356-
ɵɵelementProperty(0, 'data', ɵɵbind(ctx.data.right));
360+
ɵɵselect(0);
361+
ɵɵproperty('data', ctx.data.right);
357362
}
358363
ɵɵembeddedViewEnd();
359364
}
@@ -400,8 +405,10 @@ describe('recursive components', () => {
400405
}
401406
if (rf & RenderFlags.Update) {
402407
ɵɵtextBinding(0, ɵɵbind(ctx.data.value));
403-
ɵɵelementProperty(1, 'ngIf', ɵɵbind(ctx.data.left));
404-
ɵɵelementProperty(2, 'ngIf', ɵɵbind(ctx.data.right));
408+
ɵɵselect(1);
409+
ɵɵproperty('ngIf', ɵɵbind(ctx.data.left));
410+
ɵɵselect(2);
411+
ɵɵproperty('ngIf', ctx.data.right);
405412
}
406413

407414
},
@@ -416,7 +423,8 @@ describe('recursive components', () => {
416423
}
417424
if (rf & RenderFlags.Update) {
418425
const parent = ɵɵnextContext();
419-
ɵɵelementProperty(0, 'data', ɵɵbind(parent.data.left));
426+
ɵɵselect(0);
427+
ɵɵproperty('data', parent.data.left);
420428
}
421429
}
422430

@@ -427,7 +435,8 @@ describe('recursive components', () => {
427435
}
428436
if (rf & RenderFlags.Update) {
429437
const parent = ɵɵnextContext();
430-
ɵɵelementProperty(0, 'data', ɵɵbind(parent.data.right));
438+
ɵɵselect(0);
439+
ɵɵproperty('data', parent.data.right);
431440
}
432441
}
433442

packages/core/test/render3/instructions_spec.ts

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {NgForOfContext} from '@angular/common';
1010

1111
import {ɵɵdefineComponent} from '../../src/render3/definition';
12-
import {RenderFlags, ɵɵbind, ɵɵclassMap, ɵɵelement, ɵɵelementAttribute, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵinterpolation1, ɵɵproperty, ɵɵselect, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyling, ɵɵstylingApply, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/index';
12+
import {RenderFlags, ɵɵbind, ɵɵclassMap, ɵɵelement, ɵɵelementAttribute, ɵɵelementEnd, ɵɵelementStart, ɵɵinterpolation1, ɵɵproperty, ɵɵselect, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyling, ɵɵstylingApply, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/index';
1313
import {AttributeMarker} from '../../src/render3/interfaces/node';
1414
import {bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl} from '../../src/sanitization/bypass';
1515
import {ɵɵdefaultStyleSanitizer, ɵɵsanitizeHtml, ɵɵsanitizeResourceUrl, ɵɵsanitizeScript, ɵɵsanitizeStyle, ɵɵsanitizeUrl} from '../../src/sanitization/sanitization';
@@ -58,10 +58,16 @@ describe('instructions', () => {
5858
it('should update bindings when value changes with the correct perf counters', () => {
5959
const t = new TemplateFixture(createAnchor, () => {}, 1, 1);
6060

61-
t.update(() => ɵɵelementProperty(0, 'title', ɵɵbind('Hello')));
61+
t.update(() => {
62+
ɵɵselect(0);
63+
ɵɵproperty('title', 'Hello');
64+
});
6265
expect(t.html).toEqual('<a title="Hello"></a>');
6366

64-
t.update(() => ɵɵelementProperty(0, 'title', ɵɵbind('World')));
67+
t.update(() => {
68+
ɵɵselect(0);
69+
ɵɵproperty('title', 'World');
70+
});
6571
expect(t.html).toEqual('<a title="World"></a>');
6672
expect(ngDevMode).toHaveProperties({
6773
firstTemplatePass: 1,
@@ -74,7 +80,10 @@ describe('instructions', () => {
7480

7581
it('should not update bindings when value does not change, with the correct perf counters',
7682
() => {
77-
const idempotentUpdate = () => ɵɵelementProperty(0, 'title', ɵɵbind('Hello'));
83+
const idempotentUpdate = () => {
84+
ɵɵselect(0);
85+
ɵɵproperty('title', 'Hello');
86+
};
7887
const t = new TemplateFixture(createAnchor, idempotentUpdate, 1, 1);
7988

8089
t.update();
@@ -295,7 +304,8 @@ describe('instructions', () => {
295304
}
296305
if (rf & RenderFlags.Update) {
297306
const row_r2 = ctx0.$implicit;
298-
ɵɵelementProperty(1, 'ngForOf', ɵɵbind(row_r2));
307+
ɵɵselect(1);
308+
ɵɵproperty('ngForOf', row_r2);
299309
}
300310
}
301311

@@ -331,7 +341,8 @@ describe('instructions', () => {
331341
ɵɵtemplate(0, ToDoAppComponent_NgForOf_Template_0, 2, 1, 'ul', _c0);
332342
}
333343
if (rf & RenderFlags.Update) {
334-
ɵɵelementProperty(0, 'ngForOf', ɵɵbind(ctx.rows));
344+
ɵɵselect(0);
345+
ɵɵproperty('ngForOf', ctx.rows);
335346
}
336347
},
337348
directives: [NgForOf]
@@ -448,66 +459,84 @@ describe('instructions', () => {
448459

449460
it('should work for script sanitization', () => {
450461
const s = new LocalMockSanitizer(value => `${value} //sanitized`);
451-
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
462+
const t = new TemplateFixture(createScript, undefined, 1, 1, null, null, s);
452463
const inputValue = 'fn();';
453464
const outputValue = 'fn(); //sanitized';
454465

455-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
466+
t.update(() => {
467+
ɵɵselect(0);
468+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeScript);
469+
});
456470
expect(t.html).toEqual(`<script>${outputValue}</script>`);
457471
expect(s.lastSanitizedValue).toEqual(outputValue);
458472
});
459473

460474
it('should bypass script sanitization if marked by the service', () => {
461475
const s = new LocalMockSanitizer(value => '');
462-
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
476+
const t = new TemplateFixture(createScript, undefined, 1, 1, null, null, s);
463477
const inputValue = s.bypassSecurityTrustScript('alert("bar")');
464478
const outputValue = 'alert("bar")';
465479

466-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
480+
t.update(() => {
481+
ɵɵselect(0);
482+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeScript);
483+
});
467484
expect(t.html).toEqual(`<script>${outputValue}</script>`);
468485
expect(s.lastSanitizedValue).toBeFalsy();
469486
});
470487

471488
it('should bypass ivy-level script sanitization if a custom sanitizer is used', () => {
472489
const s = new LocalMockSanitizer(value => '');
473-
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
490+
const t = new TemplateFixture(createScript, undefined, 1, 1, null, null, s);
474491
const inputValue = bypassSanitizationTrustScript('alert("bar")');
475492
const outputValue = 'alert("bar")-ivy';
476493

477-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
494+
t.update(() => {
495+
ɵɵselect(0);
496+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeScript);
497+
});
478498
expect(t.html).toEqual(`<script>${outputValue}</script>`);
479499
expect(s.lastSanitizedValue).toBeFalsy();
480500
});
481501

482502
it('should work for html sanitization', () => {
483503
const s = new LocalMockSanitizer(value => `${value} <!--sanitized-->`);
484-
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
504+
const t = new TemplateFixture(createDiv, undefined, 1, 1, null, null, s);
485505
const inputValue = '<header></header>';
486506
const outputValue = '<header></header> <!--sanitized-->';
487507

488-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
508+
t.update(() => {
509+
ɵɵselect(0);
510+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeHtml);
511+
});
489512
expect(t.html).toEqual(`<div>${outputValue}</div>`);
490513
expect(s.lastSanitizedValue).toEqual(outputValue);
491514
});
492515

493516
it('should bypass html sanitization if marked by the service', () => {
494517
const s = new LocalMockSanitizer(value => '');
495-
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
518+
const t = new TemplateFixture(createDiv, undefined, 1, 1, null, null, s);
496519
const inputValue = s.bypassSecurityTrustHtml('<div onclick="alert(123)"></div>');
497520
const outputValue = '<div onclick="alert(123)"></div>';
498521

499-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
522+
t.update(() => {
523+
ɵɵselect(0);
524+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeHtml);
525+
});
500526
expect(t.html).toEqual(`<div>${outputValue}</div>`);
501527
expect(s.lastSanitizedValue).toBeFalsy();
502528
});
503529

504530
it('should bypass ivy-level script sanitization if a custom sanitizer is used', () => {
505531
const s = new LocalMockSanitizer(value => '');
506-
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
532+
const t = new TemplateFixture(createDiv, undefined, 1, 1, null, null, s);
507533
const inputValue = bypassSanitizationTrustHtml('<div onclick="alert(123)"></div>');
508534
const outputValue = '<div onclick="alert(123)"></div>-ivy';
509535

510-
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
536+
t.update(() => {
537+
ɵɵselect(0);
538+
ɵɵproperty('innerHTML', inputValue, ɵɵsanitizeHtml);
539+
});
511540
expect(t.html).toEqual(`<div>${outputValue}</div>`);
512541
expect(s.lastSanitizedValue).toBeFalsy();
513542
});

0 commit comments

Comments
 (0)