From d11049636d0f3a30de246ee34f845b4552fda33e Mon Sep 17 00:00:00 2001 From: crisbeto Date: Mon, 23 Sep 2019 20:29:37 +0200 Subject: [PATCH] fixup! perf(ivy): move attributes array into component def --- .../compliance/r3_compiler_compliance_spec.ts | 48 +++++++++--------- .../r3_view_compiler_binding_spec.ts | 14 +++--- .../r3_view_compiler_directives_spec.ts | 12 ++--- .../compliance/r3_view_compiler_i18n_spec.ts | 50 +++++++++---------- .../r3_view_compiler_listener_spec.ts | 8 +-- .../r3_view_compiler_styling_spec.ts | 6 +-- .../r3_view_compiler_template_spec.ts | 16 +++--- .../test/ngtsc/template_mapping_spec.ts | 2 +- .../compiler/src/render3/view/compiler.ts | 8 +-- .../compiler/src/render3/view/template.ts | 22 ++++---- packages/core/src/render3/definition.ts | 6 +-- .../src/render3/instructions/container.ts | 10 ++-- .../core/src/render3/instructions/element.ts | 22 ++++---- .../render3/instructions/element_container.ts | 20 ++++---- .../src/render3/instructions/embedded_view.ts | 2 +- .../src/render3/instructions/lview_debug.ts | 2 +- .../core/src/render3/instructions/shared.ts | 10 ++-- .../core/src/render3/interfaces/definition.ts | 4 +- packages/core/src/render3/interfaces/view.ts | 2 +- packages/core/test/render3/component_spec.ts | 4 +- .../core/test/render3/instructions_spec.ts | 2 +- .../core/test/render3/integration_spec.ts | 12 ++--- packages/core/test/render3/query_spec.ts | 6 +-- packages/core/test/render3/render_util.ts | 6 +-- .../test/render3/view_container_ref_spec.ts | 6 +-- tools/public_api_guard/core/core.d.ts | 16 +++--- 26 files changed, 158 insertions(+), 158 deletions(-) diff --git a/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts b/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts index 1e3c2d589adc3..357f3657cc549 100644 --- a/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts @@ -49,7 +49,7 @@ describe('compiler compliance', () => { // The template should look like this (where IDENT is a wild card for an identifier): const template = ` … - attrs: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"], ["cx", "20", "cy", "30", "r", "50"]], + consts: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"], ["cx", "20", "cy", "30", "r", "50"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -98,7 +98,7 @@ describe('compiler compliance', () => { // The template should look like this (where IDENT is a wild card for an identifier): const template = ` … - attrs: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"]], + consts: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -146,7 +146,7 @@ describe('compiler compliance', () => { // The template should look like this (where IDENT is a wild card for an identifier): const template = ` … - attrs: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"]], + consts: [["title", "Hello", ${AttributeMarker.Classes}, "my-app"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -194,7 +194,7 @@ describe('compiler compliance', () => { // The template should look like this (where IDENT is a wild card for an identifier): const template = ` … - attrs: [["class", "my-app", 0, "http://someuri/foo", "foo:bar", "baz", "title", "Hello", 0, "http://someuri/foo", "foo:qux", "quacks"]], + consts: [["class", "my-app", 0, "http://someuri/foo", "foo:bar", "baz", "title", "Hello", 0, "http://someuri/foo", "foo:qux", "quacks"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -308,7 +308,7 @@ describe('compiler compliance', () => { 'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }'; const template = ` … - attrs: [[${AttributeMarker.Bindings}, "id"]], + consts: [[${AttributeMarker.Bindings}, "id"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -524,7 +524,7 @@ describe('compiler compliance', () => { const template = ` … - attrs: [["title", "hi"]], + consts: [["title", "hi"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -600,7 +600,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 2, vars: 0, - attrs: [["some-directive", ""]], + consts: [["some-directive", ""]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "child", 0); @@ -818,7 +818,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 3, vars: 0, - attrs: [[${AttributeMarker.Template}, "if"]], + consts: [[${AttributeMarker.Template}, "if"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "ul", null, $c1$); @@ -885,7 +885,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 1, vars: 3, - attrs: [[${AttributeMarker.Bindings}, "names"]], + consts: [[${AttributeMarker.Bindings}, "names"]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "my-comp", 0); @@ -966,7 +966,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 1, vars: 11, - attrs: [[${AttributeMarker.Bindings}, "names"]], + consts: [[${AttributeMarker.Bindings}, "names"]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "my-comp", 0); @@ -1028,7 +1028,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 1, vars: 3, - attrs: [[${AttributeMarker.Bindings}, "config"]], + consts: [[${AttributeMarker.Bindings}, "config"]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "object-comp", 0); @@ -1095,7 +1095,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 1, vars: 8, - attrs: [[${AttributeMarker.Bindings}, "config"]], + consts: [[${AttributeMarker.Bindings}, "config"]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "nested-comp", 0); @@ -1177,7 +1177,7 @@ describe('compiler compliance', () => { ngContentSelectors: $c2$, decls: 4, vars: 0, - attrs: [["id","first"], ["id","second"]], + consts: [["id","first"], ["id","second"]], template: function ComplexComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵprojectionDef($c1$); @@ -1296,7 +1296,7 @@ describe('compiler compliance', () => { } const $_c4$ = [[["span", "title", "tofirst"]], "*"]; … - attrs: [["id", "second", ${AttributeMarker.Template}, "ngIf"], ["id", "third", ${AttributeMarker.Template}, "ngIf"], ["id", "second"], ["id", "third"]], + consts: [["id", "second", ${AttributeMarker.Template}, "ngIf"], ["id", "third", ${AttributeMarker.Template}, "ngIf"], ["id", "second"], ["id", "third"]], template: function Cmp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵprojectionDef($_c4$); @@ -1416,7 +1416,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 2, vars: 0, - attrs: [[5, ["", "title", ""]]], + consts: [[5, ["", "title", ""]]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "simple"); @@ -1468,7 +1468,7 @@ describe('compiler compliance', () => { selectors: [["my-app"]], decls: 2, vars: 0, - attrs: [[5, ["", "title", ""]]], + consts: [[5, ["", "title", ""]]], template: function MyApp_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "simple"); @@ -1542,7 +1542,7 @@ describe('compiler compliance', () => { }, decls: 1, vars: 0, - attrs: [["someDir",""]], + consts: [["someDir",""]], template: function ViewQueryComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -1652,7 +1652,7 @@ describe('compiler compliance', () => { }, decls: 1, vars: 0, - attrs: [["someDir",""]], + consts: [["someDir",""]], template: function ViewQueryComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -2335,7 +2335,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 6, vars: 1, - attrs: [[${AttributeMarker.Template}, "if"]], + consts: [[${AttributeMarker.Template}, "if"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", null, $c1$); @@ -2414,7 +2414,7 @@ describe('compiler compliance', () => { } // ... - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Template}, "ngIf"]], template:function MyComponent_Template(rf, ctx){ if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 4, 1, "div", 0); @@ -2492,7 +2492,7 @@ describe('compiler compliance', () => { selectors: [["simple-layout"]], decls: 2, vars: 2, - attrs: [[3, "name"]], + consts: [[3, "name"]], template: function SimpleLayout_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "lifecycle-comp", 0); @@ -2624,7 +2624,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 2, vars: 1, - attrs: [[${AttributeMarker.Template}, "for", "forOf"]], + consts: [[${AttributeMarker.Template}, "for", "forOf"]], template: function MyComponent_Template(rf, ctx){ if (rf & 1) { $r3$.ɵɵnamespaceSVG(); @@ -2710,7 +2710,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 2, vars: 1, - attrs: [[${AttributeMarker.Template}, "for", "forOf"]], + consts: [[${AttributeMarker.Template}, "for", "forOf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "ul"); @@ -2814,7 +2814,7 @@ describe('compiler compliance', () => { selectors: [["my-component"]], decls: 2, vars: 1, - attrs: [[${AttributeMarker.Template}, "for", "forOf"]], + consts: [[${AttributeMarker.Template}, "for", "forOf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "ul"); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_binding_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_binding_spec.ts index 5e0c3e2610780..0d573974ed5c0 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_binding_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_binding_spec.ts @@ -75,7 +75,7 @@ describe('compiler compliance: bindings', () => { const template = ` … - attrs: [[${AttributeMarker.Bindings}, "title"]], + consts: [[${AttributeMarker.Bindings}, "title"]], template:function MyComponent_Template(rf, $ctx$){ if (rf & 1) { $i0$.ɵɵelement(0, "a", 0); @@ -109,7 +109,7 @@ describe('compiler compliance: bindings', () => { const template = ` … - attrs: [[${AttributeMarker.Bindings}, "title"]], + consts: [[${AttributeMarker.Bindings}, "title"]], template:function MyComponent_Template(rf, $ctx$){ if (rf & 1) { $i0$.ɵɵelement(0, "a", 0); @@ -162,7 +162,7 @@ describe('compiler compliance: bindings', () => { }; const template = ` - attrs: [[${AttributeMarker.Bindings}, "for"]] + consts: [[${AttributeMarker.Bindings}, "for"]] // ... @@ -640,7 +640,7 @@ describe('compiler compliance: bindings', () => { }; const template = ` - attrs: [["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"]], + consts: [["target", "_blank", "aria-label", "link", ${AttributeMarker.Bindings}, "title", "id", "customEvent"]], … `; const result = compile(files, angularFiles); @@ -1253,7 +1253,7 @@ describe('compiler compliance: bindings', () => { const template = ` const $_c1$ = ["myRef", ""]; … - attrs: [["id", "my-id"]], + consts: [["id", "my-id"]], template:function MyComponent_Template(rf, $ctx$){ if (rf & 1) { $i0$.ɵɵelementStart(0, "b", 0, $_c1$); @@ -1285,7 +1285,7 @@ describe('compiler compliance: bindings', () => { const template = ` … - attrs: [["value", "one", "#myInput", ""]], + consts: [["value", "one", "#myInput", ""]], template:function MyComponent_Template(rf, $ctx$){ if (rf & 1) { $i0$.ɵɵelementStart(0, "div"); @@ -1309,7 +1309,7 @@ describe('compiler compliance: bindings', () => { const template = ` … - attrs: [["[id]", "my-id", "(click)", "onclick"]], + consts: [["[id]", "my-id", "(click)", "onclick"]], template:function MyComponent_Template(rf, $ctx$){ if (rf & 1) { $i0$.ɵɵelementStart(0, "div"); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_directives_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_directives_spec.ts index 744f550918bf8..21f68fafa333e 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_directives_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_directives_spec.ts @@ -140,7 +140,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [[${AttributeMarker.Bindings}, "someDirective"]], + consts: [[${AttributeMarker.Bindings}, "someDirective"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -198,7 +198,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [["directiveA", ""]], + consts: [["directiveA", ""]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 1, 0, "ng-template", 0); @@ -253,7 +253,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [["directiveA", "", ${AttributeMarker.Template}, "ngIf"], ["directiveA", ""]], + consts: [["directiveA", "", ${AttributeMarker.Template}, "ngIf"], ["directiveA", ""]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_ng_container_0_Template, 2, 0, "ng-container", 0); @@ -299,7 +299,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [[${AttributeMarker.Bindings}, "someDirective"]], + consts: [[${AttributeMarker.Bindings}, "someDirective"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 0, 0, "ng-template", 0); @@ -346,7 +346,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [[${AttributeMarker.Template}, "someDirective"]], + consts: [[${AttributeMarker.Template}, "someDirective"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", 0); @@ -394,7 +394,7 @@ describe('compiler compliance: directives', () => { … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ … - attrs: [[${AttributeMarker.Bindings}, "someDirective"]], + consts: [[${AttributeMarker.Bindings}, "someDirective"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts index 75def9ce2693c..5364e3ca70285 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts @@ -268,7 +268,7 @@ describe('i18n support in the template compiler', () => { } const $_c25$ = ["title", $I18N_23$]; … - attrs: [[${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -312,7 +312,7 @@ describe('i18n support in the template compiler', () => { const output = ` … - attrs: [["id", "static", "title", ""]], + consts: [["id", "static", "title", ""]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -333,7 +333,7 @@ describe('i18n support in the template compiler', () => { const output = ` … - attrs: [[3, "title"]], + consts: [[3, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -368,7 +368,7 @@ describe('i18n support in the template compiler', () => { } const $_c1$ = ["title", $I18N_1$]; … - attrs: [["id", "static", ${AttributeMarker.I18n}, "title"]], + consts: [["id", "static", ${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -473,7 +473,7 @@ describe('i18n support in the template compiler', () => { … decls: 5, vars: 8, - attrs: [["id", "dynamic-1", ${AttributeMarker.I18n}, "aria-roledescription", "title", "aria-label"], ["id", "dynamic-2", ${AttributeMarker.I18n}, "title", "aria-roledescription"]], + consts: [["id", "dynamic-1", ${AttributeMarker.I18n}, "aria-roledescription", "title", "aria-label"], ["id", "dynamic-2", ${AttributeMarker.I18n}, "title", "aria-roledescription"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -519,7 +519,7 @@ describe('i18n support in the template compiler', () => { } const $_c3$ = ["title", $I18N_1$]; … - attrs: [[${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -578,7 +578,7 @@ describe('i18n support in the template compiler', () => { … decls: 1, vars: 1, - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 4, 3, "div", 0); @@ -613,7 +613,7 @@ describe('i18n support in the template compiler', () => { … decls: 2, vars: 1, - attrs: [[${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -724,7 +724,7 @@ describe('i18n support in the template compiler', () => { … decls: 5, vars: 8, - attrs: [[ + consts: [[ "id", "dynamic-1", ${AttributeMarker.I18n}, "aria-roledescription", "title", "aria-label" ], ["id", "dynamic-2", ${AttributeMarker.I18n}, "title", "aria-roledescription"]], @@ -792,7 +792,7 @@ describe('i18n support in the template compiler', () => { … decls: 1, vars: 1, - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 4, 3, "div", 0); @@ -834,7 +834,7 @@ describe('i18n support in the template compiler', () => { $I18N_2$ = $localize \`:@@4969674997806975147:Some content\`; } … - attrs: [[${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -1362,7 +1362,7 @@ describe('i18n support in the template compiler', () => { … decls: 9, vars: 7, - attrs: [[${AttributeMarker.I18n}, "title"]], + consts: [[${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -1451,7 +1451,7 @@ describe('i18n support in the template compiler', () => { … decls: 3, vars: 1, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -1509,7 +1509,7 @@ describe('i18n support in the template compiler', () => { … decls: 3, vars: 2, - attrs: [["src", "logo.png"], ["src", "logo.png", ${AttributeMarker.Template}, "ngIf"], ["src", "logo.png", ${AttributeMarker.Bindings}, "title", ${AttributeMarker.Template}, "ngIf"], ["src", "logo.png", ${AttributeMarker.I18n}, "title"]], + consts: [["src", "logo.png"], ["src", "logo.png", ${AttributeMarker.Template}, "ngIf"], ["src", "logo.png", ${AttributeMarker.Bindings}, "title", ${AttributeMarker.Template}, "ngIf"], ["src", "logo.png", ${AttributeMarker.I18n}, "title"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelement(0, "img", 0); @@ -1650,7 +1650,7 @@ describe('i18n support in the template compiler', () => { … decls: 4, vars: 2, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -1711,7 +1711,7 @@ describe('i18n support in the template compiler', () => { … decls: 1, vars: 1, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 3, 1, "div", 0); @@ -1740,7 +1740,7 @@ describe('i18n support in the template compiler', () => { $I18N_1$ = $localize \`:@@3902961887793684628:Hello\`; } … - attrs: [[${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -1887,7 +1887,7 @@ describe('i18n support in the template compiler', () => { … decls: 4, vars: 0, - attrs: [[${AttributeMarker.Classes}, "myClass"], [${AttributeMarker.Styles}, "padding", "10px"]], + consts: [[${AttributeMarker.Classes}, "myClass"], [${AttributeMarker.Styles}, "padding", "10px"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "span", 0); @@ -2300,7 +2300,7 @@ describe('i18n support in the template compiler', () => { } } … - attrs: [["src", "logo.png", "title", "Logo"]], + consts: [["src", "logo.png", "title", "Logo"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementContainerStart(0); @@ -2497,7 +2497,7 @@ describe('i18n support in the template compiler', () => { … decls: 2, vars: 2, - attrs: [[4, "ngIf"]], + consts: [[4, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_0_Template, 1, 0, undefined, 0); @@ -2725,7 +2725,7 @@ describe('i18n support in the template compiler', () => { … decls: 4, vars: 3, - attrs: [["title", "icu only", ${AttributeMarker.Template}, "ngIf"], ["title", "icu and text", ${AttributeMarker.Template}, "ngIf"], ["title", "icu only"], ["title", "icu and text"]], + consts: [["title", "icu only", ${AttributeMarker.Template}, "ngIf"], ["title", "icu and text", ${AttributeMarker.Template}, "ngIf"], ["title", "icu only"], ["title", "icu and text"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -2836,7 +2836,7 @@ describe('i18n support in the template compiler', () => { … decls: 5, vars: 1, - attrs: [[1, "other"]], + consts: [[1, "other"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -3042,7 +3042,7 @@ describe('i18n support in the template compiler', () => { … decls: 4, vars: 3, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -3231,7 +3231,7 @@ describe('i18n support in the template compiler', () => { … decls: 3, vars: 2, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -3320,7 +3320,7 @@ describe('i18n support in the template compiler', () => { … decls: 3, vars: 4, - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_listener_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_listener_spec.ts index fde3117b10ba0..52fbc38af24e9 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_listener_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_listener_spec.ts @@ -42,7 +42,7 @@ describe('compiler compliance: listen()', () => { // The template should look like this (where IDENT is a wild card for an identifier): const template = ` … - attrs: [[${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", 0); @@ -88,7 +88,7 @@ describe('compiler compliance: listen()', () => { const template = ` … - attrs: [[${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "my-app", 0); @@ -155,7 +155,7 @@ describe('compiler compliance: listen()', () => { } } // ... - attrs: [[${AttributeMarker.Template}, "ngIf"], [${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Template}, "ngIf"], [${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 3, 0, "div", 0); @@ -200,7 +200,7 @@ describe('compiler compliance: listen()', () => { selectors: [["my-component"]], decls: 4, vars: 0, - attrs: [[${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { const $s$ = $r3$.ɵɵgetCurrentView(); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts index 0997fd9d42f92..457dbda594da0 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts @@ -507,7 +507,7 @@ describe('compiler compliance: styling', () => { selectors:[["my-component"]], decls: 1, vars: 4, - attrs: [[${AttributeMarker.Styles}, "opacity", "1"]], + consts: [[${AttributeMarker.Styles}, "opacity", "1"]], template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -701,7 +701,7 @@ describe('compiler compliance: styling', () => { selectors:[["my-component"]], decls: 1, vars: 4, - attrs: [[${AttributeMarker.Classes}, "grape"]], + consts: [[${AttributeMarker.Classes}, "grape"]], template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); @@ -750,7 +750,7 @@ describe('compiler compliance: styling', () => { selectors:[["my-component"]], decls: 1, vars: 2, - attrs: [[${AttributeMarker.Classes}, "foo", ${AttributeMarker.Styles}, "width", "100px"]], + consts: [[${AttributeMarker.Classes}, "foo", ${AttributeMarker.Styles}, "width", "100px"]], template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelement(0, "div", 0); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts index d763da3bcbbdb..7ea9a3e0e96a5 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts @@ -103,7 +103,7 @@ describe('compiler compliance: template', () => { } } // ... - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "title", "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "title", "click"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "title", "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "title", "click"]], template:function MyComponent_Template(rf, ctx){ if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_ul_0_Template, 2, 1, "ul", 0); @@ -157,7 +157,7 @@ describe('compiler compliance: template', () => { } } // ... - attrs: [[${AttributeMarker.Bindings}, "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "click"]], + consts: [[${AttributeMarker.Bindings}, "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Bindings}, "click"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", 0); @@ -261,7 +261,7 @@ describe('compiler compliance: template', () => { } } // ... - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"]], template:function MyComponent_Template(rf, ctx){ if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_span_0_Template, 2, 2, "span", 0); @@ -329,7 +329,7 @@ describe('compiler compliance: template', () => { } // ... - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"], [${AttributeMarker.Template}, "ngIf"]], template:function MyComponent_Template(rf, ctx){ if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 2, 1, "div", 0); @@ -411,7 +411,7 @@ describe('compiler compliance: template', () => { } } // ... - attrs: [[${AttributeMarker.Template}, "ngFor", "ngForOf"]], + consts: [[${AttributeMarker.Template}, "ngFor", "ngForOf"]], template:function MyComponent_Template(rf, ctx){ if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 2, 1, "div", 0); @@ -456,7 +456,7 @@ describe('compiler compliance: template', () => { // ... - attrs: [["attr", "l", ${AttributeMarker.Bindings}, "boundAttr"]], + consts: [["attr", "l", ${AttributeMarker.Bindings}, "boundAttr"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 1, 0, "ng-template", 0); @@ -536,7 +536,7 @@ describe('compiler compliance: template', () => { // ... - attrs: [[${AttributeMarker.Bindings}, "outDirective"]], + consts: [[${AttributeMarker.Bindings}, "outDirective"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 0, 0, "ng-template", 0); @@ -743,7 +743,7 @@ describe('compiler compliance: template', () => { } // ... - attrs: [[${AttributeMarker.Template}, "ngIf"]], + consts: [[${AttributeMarker.Template}, "ngIf"]], template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", 0); diff --git a/packages/compiler-cli/test/ngtsc/template_mapping_spec.ts b/packages/compiler-cli/test/ngtsc/template_mapping_spec.ts index 9ee9da8e9d7c4..d7679f300178f 100644 --- a/packages/compiler-cli/test/ngtsc/template_mapping_spec.ts +++ b/packages/compiler-cli/test/ngtsc/template_mapping_spec.ts @@ -430,7 +430,7 @@ runInEachFileSystem((os) => { }); const attrsMapping = - mappings.find(mapping => /attrs: \[\[1, "some-class"\]\]/.test(mapping.generated)); + mappings.find(mapping => /consts: \[\[1, "some-class"\]\]/.test(mapping.generated)); expect(attrsMapping).toBeDefined(); }); }); diff --git a/packages/compiler/src/render3/view/compiler.ts b/packages/compiler/src/render3/view/compiler.ts index f25ea2d888273..a9a8a266a24cc 100644 --- a/packages/compiler/src/render3/view/compiler.ts +++ b/packages/compiler/src/render3/view/compiler.ts @@ -246,10 +246,10 @@ export function compileComponentFromMetadata( // e.g. `vars: 2` definitionMap.set('vars', o.literal(templateBuilder.getVarCount())); - // e.g. `attrs: [['one', 'two'], ['three', 'four']] - const attrs = templateBuilder.getAttributes(); - if (attrs.length > 0) { - definitionMap.set('attrs', o.literalArr(attrs)); + // e.g. `consts: [['one', 'two'], ['three', 'four']] + const consts = templateBuilder.getConsts(); + if (consts.length > 0) { + definitionMap.set('consts', o.literalArr(consts)); } definitionMap.set('template', templateFunctionExpression); diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index 7413ce558e6e9..6361d16f7397d 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -166,7 +166,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver private directiveMatcher: SelectorMatcher|null, private directives: Set, private pipeTypeByName: Map, private pipes: Set, private _namespace: o.ExternalReference, relativeContextFilePath: string, - private i18nUseExternalIds: boolean, private _attributes: o.Expression[] = []) { + private i18nUseExternalIds: boolean, private _constants: o.Expression[] = []) { this._bindingScope = parentBindingScope.nestedScope(level); // Turn the relative context file path into an identifier by replacing non-alphanumeric @@ -600,7 +600,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver // add attributes for directive and projection matching purposes attributes.push(...this.prepareNonRenderAttrs( allOtherInputs, element.outputs, stylingBuilder, [], i18nAttrs)); - parameters.push(this.addAttributes(attributes)); + parameters.push(this.addConstants(attributes)); // local refs (ex.:
) parameters.push(this.prepareRefsParameter(element.references)); @@ -863,7 +863,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver (a: t.TextAttribute) => { attrsExprs.push(asLiteral(a.name), asLiteral(a.value)); }); attrsExprs.push(...this.prepareNonRenderAttrs( template.inputs, template.outputs, undefined, template.templateAttrs)); - parameters.push(this.addAttributes(attrsExprs)); + parameters.push(this.addConstants(attrsExprs)); // local refs (ex.: ) if (template.references && template.references.length) { @@ -876,7 +876,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver this.constantPool, this._bindingScope, this.level + 1, contextName, this.i18n, templateIndex, templateName, this.directiveMatcher, this.directives, this.pipeTypeByName, this.pipes, this._namespace, this.fileBasedI18nSuffix, this.i18nUseExternalIds, - this._attributes); + this._constants); // Nested templates must not be visited until after their parent templates have completed // processing, so they are queued here until after the initial pass. Otherwise, we wouldn't @@ -1015,7 +1015,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver getVarCount() { return this._pureFunctionSlots; } - getAttributes() { return this._attributes; } + getConsts() { return this._constants; } getNgContentSelectors(): o.Expression|null { return this._ngContentReservedSlots.length ? @@ -1282,18 +1282,18 @@ export class TemplateDefinitionBuilder implements t.Visitor, LocalResolver return attrExprs; } - private addAttributes(attrsExprs: o.Expression[]): o.LiteralExpr { - if (attrsExprs.length > 0) { - const literal = o.literalArr(attrsExprs); + private addConstants(constExprs: o.Expression[]): o.LiteralExpr { + if (constExprs.length > 0) { + const literal = o.literalArr(constExprs); // Try to reuse a literal that's already in the array, if possible. - for (let i = 0; i < this._attributes.length; i++) { - if (this._attributes[i].isEquivalent(literal)) { + for (let i = 0; i < this._constants.length; i++) { + if (this._constants[i].isEquivalent(literal)) { return o.literal(i); } } - return o.literal(this._attributes.push(literal) - 1); + return o.literal(this._constants.push(literal) - 1); } return o.TYPED_NULL_EXPR; diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 51f7be5fa74f1..b1c54d8da37bd 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -172,8 +172,8 @@ export function ɵɵdefineComponent(componentDefinition: { */ template: ComponentTemplate; - /** Attributes for all of the nodes inside the component template. Used during creation. */ - attrs?: TAttributes[]; + /** Constants for the nodes in the component's view. */ + consts?: TAttributes[]; /** * An array of `ngContent[selector]` values that were found in the template. @@ -256,7 +256,7 @@ export function ɵɵdefineComponent(componentDefinition: { vars: componentDefinition.vars, factory: null, template: componentDefinition.template || null !, - attrs: componentDefinition.attrs || null, + consts: componentDefinition.consts || null, ngContentSelectors: componentDefinition.ngContentSelectors, hostBindings: componentDefinition.hostBindings || null, contentQueries: componentDefinition.contentQueries || null, diff --git a/packages/core/src/render3/instructions/container.ts b/packages/core/src/render3/instructions/container.ts index c97821613a1fc..1a2375786f209 100644 --- a/packages/core/src/render3/instructions/container.ts +++ b/packages/core/src/render3/instructions/container.ts @@ -56,7 +56,7 @@ export function ɵɵcontainer(index: number): void { * @param decls The number of nodes, local refs, and pipes for this template * @param vars The number of bindings for this template * @param tagName The name of the container element, if applicable - * @param attrsIndex Index of template in the attributes array. + * @param constsIndex Index of template in the `consts` array. * @param localRefs A set of local reference bindings on the element. * @param localRefExtractor A function which extracts local-refs values from the template. * Defaults to the current element associated with the local-ref. @@ -65,16 +65,16 @@ export function ɵɵcontainer(index: number): void { */ export function ɵɵtemplate( index: number, templateFn: ComponentTemplate| null, decls: number, vars: number, - tagName?: string | null, attrsIndex?: number | null, localRefs?: string[] | null, + tagName?: string | null, constsIndex?: number | null, localRefs?: string[] | null, localRefExtractor?: LocalRefExtractor) { const lView = getLView(); const tView = lView[TVIEW]; - const tViewAttrs = tView.attrs; + const tViewConsts = tView.consts; // TODO: consider a separate node type for templates const tContainerNode = containerInternal( lView, index, tagName || null, - tViewAttrs === null || attrsIndex == null ? null : tViewAttrs[attrsIndex]); + tViewConsts === null || constsIndex == null ? null : tViewConsts[constsIndex]); if (tView.firstTemplatePass) { ngDevMode && ngDevMode.firstTemplatePass++; resolveDirectives(tView, lView, tContainerNode, localRefs || null); @@ -82,7 +82,7 @@ export function ɵɵtemplate( const embeddedTView = tContainerNode.tViews = createTView( -1, templateFn, decls, vars, tView.directiveRegistry, tView.pipeRegistry, null, - tView.schemas, tViewAttrs); + tView.schemas, tViewConsts); const embeddedTViewNode = createTNode(tView, null, TNodeType.View, -1, null, null) as TViewNode; embeddedTViewNode.injectorIndex = tContainerNode.injectorIndex; embeddedTView.node = embeddedTViewNode; diff --git a/packages/core/src/render3/instructions/element.ts b/packages/core/src/render3/instructions/element.ts index b9d683d77290d..4216b052eb405 100644 --- a/packages/core/src/render3/instructions/element.ts +++ b/packages/core/src/render3/instructions/element.ts @@ -32,7 +32,7 @@ import {registerInitialStylingOnTNode} from './styling'; * * @param index Index of the element in the LView array * @param name Name of the DOM Node - * @param attrsIndex Index of the element in the attributes array. + * @param constsIndex Index of the element in the `consts` array. * @param localRefs A set of local reference bindings on the element. * * Attributes and localRefs are passed as an array of strings where elements with an even index @@ -42,11 +42,11 @@ import {registerInitialStylingOnTNode} from './styling'; * @codeGenApi */ export function ɵɵelementStart( - index: number, name: string, attrsIndex?: number | null, localRefs?: string[] | null): void { + index: number, name: string, constsIndex?: number | null, localRefs?: string[] | null): void { const lView = getLView(); const tView = lView[TVIEW]; - const tViewAttrs = tView.attrs; - const attrs = tViewAttrs === null || attrsIndex == null ? null : tViewAttrs[attrsIndex]; + const tViewConsts = tView.consts; + const consts = tViewConsts === null || constsIndex == null ? null : tViewConsts[constsIndex]; ngDevMode && assertEqual( lView[BINDING_INDEX], tView.bindingStartIndex, 'elements should be created before any bindings'); @@ -55,12 +55,12 @@ export function ɵɵelementStart( ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET); const renderer = lView[RENDERER]; const native = lView[index + HEADER_OFFSET] = elementCreate(name, renderer, getNamespace()); - const tNode = getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, name, attrs); + const tNode = getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, name, consts); - if (attrs != null) { - const lastAttrIndex = setUpAttributes(renderer, native, attrs); + if (consts != null) { + const lastAttrIndex = setUpAttributes(renderer, native, consts); if (tView.firstTemplatePass) { - registerInitialStylingOnTNode(tNode, attrs, lastAttrIndex); + registerInitialStylingOnTNode(tNode, consts, lastAttrIndex); } } @@ -154,14 +154,14 @@ export function ɵɵelementEnd(): void { * * @param index Index of the element in the data array * @param name Name of the DOM Node - * @param attrsIndex Index of the element in the attributes array. + * @param constsIndex Index of the element in the `consts` array. * @param localRefs A set of local reference bindings on the element. * * @codeGenApi */ export function ɵɵelement( - index: number, name: string, attrsIndex?: number | null, localRefs?: string[] | null): void { - ɵɵelementStart(index, name, attrsIndex, localRefs); + index: number, name: string, constsIndex?: number | null, localRefs?: string[] | null): void { + ɵɵelementStart(index, name, constsIndex, localRefs); ɵɵelementEnd(); } diff --git a/packages/core/src/render3/instructions/element_container.ts b/packages/core/src/render3/instructions/element_container.ts index eb20c74f2d000..92b8392039958 100644 --- a/packages/core/src/render3/instructions/element_container.ts +++ b/packages/core/src/render3/instructions/element_container.ts @@ -26,7 +26,7 @@ import {registerInitialStylingOnTNode} from './styling'; * The instruction must later be followed by `elementContainerEnd()` call. * * @param index Index of the element in the LView array - * @param attrsIndex Index of the container in the attributes array. + * @param constsIndex Index of the container in the `consts` array. * @param localRefs A set of local reference bindings on the element. * * Even if this instruction accepts a set of attributes no actual attribute values are propagated to @@ -36,13 +36,13 @@ import {registerInitialStylingOnTNode} from './styling'; * @codeGenApi */ export function ɵɵelementContainerStart( - index: number, attrsIndex?: number | null, localRefs?: string[] | null): void { + index: number, constsIndex?: number | null, localRefs?: string[] | null): void { const lView = getLView(); const tView = lView[TVIEW]; const renderer = lView[RENDERER]; const tagName = 'ng-container'; - const tViewAttrs = tView.attrs; - const attrs = tViewAttrs === null || attrsIndex == null ? null : tViewAttrs[attrsIndex]; + const tViewConsts = tView.consts; + const consts = tViewConsts === null || constsIndex == null ? null : tViewConsts[constsIndex]; ngDevMode && assertEqual( lView[BINDING_INDEX], tView.bindingStartIndex, 'element containers should be created before any bindings'); @@ -53,12 +53,12 @@ export function ɵɵelementContainerStart( ngDevMode && assertDataInRange(lView, index - 1); const tNode = - getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.ElementContainer, tagName, attrs); + getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.ElementContainer, tagName, consts); - if (attrs && tView.firstTemplatePass) { + if (consts && tView.firstTemplatePass) { // While ng-container doesn't necessarily support styling, we use the style context to identify // and execute directives on the ng-container. - registerInitialStylingOnTNode(tNode, attrs as TAttributes, 0); + registerInitialStylingOnTNode(tNode, consts as TAttributes, 0); } appendChild(native, tNode, lView); @@ -114,13 +114,13 @@ export function ɵɵelementContainerEnd(): void { * and {@link elementContainerEnd} * * @param index Index of the element in the LView array - * @param attrsIndex Index of the container in the attributes array. + * @param constsIndex Index of the container in the `consts` array. * @param localRefs A set of local reference bindings on the element. * * @codeGenApi */ export function ɵɵelementContainer( - index: number, attrsIndex?: number | null, localRefs?: string[] | null): void { - ɵɵelementContainerStart(index, attrsIndex, localRefs); + index: number, constsIndex?: number | null, localRefs?: string[] | null): void { + ɵɵelementContainerStart(index, constsIndex, localRefs); ɵɵelementContainerEnd(); } diff --git a/packages/core/src/render3/instructions/embedded_view.ts b/packages/core/src/render3/instructions/embedded_view.ts index a3f9b52f6ca00..0ceeaf309e975 100644 --- a/packages/core/src/render3/instructions/embedded_view.ts +++ b/packages/core/src/render3/instructions/embedded_view.ts @@ -88,7 +88,7 @@ function getOrCreateEmbeddedTView( if (viewIndex >= containerTViews.length || containerTViews[viewIndex] == null) { containerTViews[viewIndex] = createTView( viewIndex, null, decls, vars, tView.directiveRegistry, tView.pipeRegistry, null, null, - tView.attrs); + tView.consts); } return containerTViews[viewIndex]; } diff --git a/packages/core/src/render3/instructions/lview_debug.ts b/packages/core/src/render3/instructions/lview_debug.ts index e0fd4cdc25d73..fa014c31ae310 100644 --- a/packages/core/src/render3/instructions/lview_debug.ts +++ b/packages/core/src/render3/instructions/lview_debug.ts @@ -102,7 +102,7 @@ export const TViewConstructor = class TView implements ITView { public pipeRegistry: PipeDefList|null, // public firstChild: TNode|null, // public schemas: SchemaMetadata[]|null, // - public attrs: TAttributes[]|null, // + public consts: TAttributes[]|null, // ) {} get template_(): string { diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index ee87f65ce5035..37dd34bec8537 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -567,7 +567,7 @@ export function saveResolvedLocalsInData( export function getOrCreateTView(def: ComponentDef): TView { return def.tView || (def.tView = createTView( -1, def.template, def.decls, def.vars, def.directiveDefs, def.pipeDefs, - def.viewQuery, def.schemas, def.attrs)); + def.viewQuery, def.schemas, def.consts)); } @@ -581,13 +581,13 @@ export function getOrCreateTView(def: ComponentDef): TView { * @param pipes Registry of pipes for this view * @param viewQuery View queries for this view * @param schemas Schemas for this view - * @param attrs Attributes for tis view + * @param consts Constants for this view */ export function createTView( viewIndex: number, templateFn: ComponentTemplate| null, decls: number, vars: number, directives: DirectiveDefListOrFactory | null, pipes: PipeDefListOrFactory | null, viewQuery: ViewQueriesFunction| null, schemas: SchemaMetadata[] | null, - attrs: TAttributes[] | null): TView { + consts: TAttributes[] | null): TView { ngDevMode && ngDevMode.tView++; const bindingStartIndex = HEADER_OFFSET + decls; // This length does not yet contain host bindings from child directives because at this point, @@ -626,7 +626,7 @@ export function createTView( typeof pipes === 'function' ? pipes() : pipes, // pipeRegistry: PipeDefList|null, null, // firstChild: TNode|null, schemas, // schemas: SchemaMetadata[]|null, - attrs) : // attrs: TAttributes[] + consts) : // consts: TAttributes[] { id: viewIndex, blueprint: blueprint, @@ -655,7 +655,7 @@ export function createTView( pipeRegistry: typeof pipes === 'function' ? pipes() : pipes, firstChild: null, schemas: schemas, - attrs: attrs, + consts: consts, }; } diff --git a/packages/core/src/render3/interfaces/definition.ts b/packages/core/src/render3/interfaces/definition.ts index 8e57579e937cc..de88ec65acbb2 100644 --- a/packages/core/src/render3/interfaces/definition.ts +++ b/packages/core/src/render3/interfaces/definition.ts @@ -241,8 +241,8 @@ export interface ComponentDef extends DirectiveDef { */ readonly template: ComponentTemplate; - /** Attributes for all of the nodes in the component's view */ - readonly attrs: TAttributes[]|null; + /** Constants associated with the component's view. */ + readonly consts: TAttributes[]|null; /** * An array of `ngContent[selector]` values that were found in the template. diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index f214dfda1e7f1..7c0aab9196b3a 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -566,7 +566,7 @@ export interface TView { * Array of attributes for all of the elements in the view. Used * for directive matching and attribute bindings. */ - attrs: TAttributes[]|null; + consts: TAttributes[]|null; } export const enum RootContextFlags {Empty = 0b00, DetectChanges = 0b01, FlushPlayers = 0b10} diff --git a/packages/core/test/render3/component_spec.ts b/packages/core/test/render3/component_spec.ts index 698112583720b..30f55c0295d20 100644 --- a/packages/core/test/render3/component_spec.ts +++ b/packages/core/test/render3/component_spec.ts @@ -181,7 +181,7 @@ it('should not invoke renderer destroy method for embedded views', () => { decls: 3, vars: 1, directives: [NgIf], - attrs: [[AttributeMarker.Template, 'ngIf']], + consts: [[AttributeMarker.Template, 'ngIf']], /** *
Root view
*
Child view
@@ -397,7 +397,7 @@ describe('recursive components', () => { selectors: [['ng-if-tree']], decls: 3, vars: 3, - attrs: [[AttributeMarker.Bindings, 'data', AttributeMarker.Template, 'ngIf']], + consts: [[AttributeMarker.Bindings, 'data', AttributeMarker.Template, 'ngIf']], template: (rf: RenderFlags, ctx: NgIfTree) => { if (rf & RenderFlags.Create) { ɵɵtext(0); diff --git a/packages/core/test/render3/instructions_spec.ts b/packages/core/test/render3/instructions_spec.ts index 527c6b4cfadb2..3082e5862854e 100644 --- a/packages/core/test/render3/instructions_spec.ts +++ b/packages/core/test/render3/instructions_spec.ts @@ -246,7 +246,7 @@ describe('instructions', () => { selectors: [['nested-loops']], decls: 1, vars: 1, - attrs: [[AttributeMarker.Template, 'ngFor', 'ngForOf']], + consts: [[AttributeMarker.Template, 'ngFor', 'ngForOf']], template: function ToDoAppComponent_Template(rf: RenderFlags, ctx: NestedLoops) { if (rf & RenderFlags.Create) { ɵɵtemplate(0, ToDoAppComponent_NgForOf_Template_0, 2, 1, 'ul', 0); diff --git a/packages/core/test/render3/integration_spec.ts b/packages/core/test/render3/integration_spec.ts index b018fdbbab99c..8e07cc8228add 100644 --- a/packages/core/test/render3/integration_spec.ts +++ b/packages/core/test/render3/integration_spec.ts @@ -280,7 +280,7 @@ describe('component animations', () => { decls: 1, vars: 1, selectors: [['foo']], - attrs: [[AttributeMarker.Bindings, '@fooAnimation']], + consts: [[AttributeMarker.Bindings, '@fooAnimation']], template: (rf: RenderFlags, ctx: AnimComp) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0); @@ -317,7 +317,7 @@ describe('component animations', () => { decls: 1, vars: 1, selectors: [['foo']], - attrs: [['@fooAnimation', '']], + consts: [['@fooAnimation', '']], template: (rf: RenderFlags, ctx: AnimComp) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0); @@ -479,7 +479,7 @@ describe('element discovery', () => { directives: [NgIf], decls: 2, vars: 1, - attrs: [['ngIf', '']], + consts: [['ngIf', '']], template: (rf: RenderFlags, ctx: StructuredComp) => { if (rf & RenderFlags.Create) { ɵɵelementStart(0, 'section'); @@ -861,7 +861,7 @@ describe('element discovery', () => { directives: [MyDir1, MyDir2, MyDir3], decls: 2, vars: 0, - attrs: [['my-dir-1', '', 'my-dir-2', ''], ['my-dir-3']], + consts: [['my-dir-1', '', 'my-dir-2', ''], ['my-dir-3']], template: (rf: RenderFlags, ctx: StructuredComp) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0); @@ -954,7 +954,7 @@ describe('element discovery', () => { directives: [ChildComp, MyDir1, MyDir2], decls: 1, vars: 0, - attrs: [['my-dir-1', '', 'my-dir-2', '']], + consts: [['my-dir-1', '', 'my-dir-2', '']], template: (rf: RenderFlags, ctx: ParentComp) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'child-comp', 0); @@ -1135,7 +1135,7 @@ describe('sanitization', () => { selectors: [['sanitize-this']], decls: 1, vars: 0, - attrs: [['unsafeUrlHostBindingDir', '']], + consts: [['unsafeUrlHostBindingDir', '']], template: (rf: RenderFlags, ctx: SimpleComp) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'blockquote', 0); diff --git a/packages/core/test/render3/query_spec.ts b/packages/core/test/render3/query_spec.ts index c8a2889ce309f..672dde8d56ace 100644 --- a/packages/core/test/render3/query_spec.ts +++ b/packages/core/test/render3/query_spec.ts @@ -254,7 +254,7 @@ describe('query', () => { selectors: [['app']], decls: 1, vars: 0, - attrs: [['myDir']], + consts: [['myDir']], template: function App_Template(rf: RenderFlags, ctx: App) { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0); @@ -300,7 +300,7 @@ describe('query', () => { selectors: [['app']], decls: 1, vars: 0, - attrs: [['myDir']], + consts: [['myDir']], template: function App_Template(rf: RenderFlags, ctx: App) { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0); @@ -2033,7 +2033,7 @@ describe('query', () => { static ngComponentDef = ɵɵdefineComponent({ type: ViewQueryComponent, selectors: [['view-query']], - attrs: [['text', 'A'], ['text', 'B'], ['text', 'C'], ['text', 'D'], ['text', 'E']], + consts: [['text', 'A'], ['text', 'B'], ['text', 'C'], ['text', 'D'], ['text', 'E']], template: function(rf: RenderFlags, ctx: ViewQueryComponent) { if (rf & RenderFlags.Create) { ɵɵelement(0, 'span', 0); diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index c452923280239..e9208b9de1d49 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -266,7 +266,7 @@ export function renderTemplate( template: templateFn, decls: decls, vars: vars, - attrs: attrs, + consts: attrs, }); def.directiveDefs = directives || null; def.pipeDefs = pipes || null; @@ -370,7 +370,7 @@ export function createComponent( directives: DirectiveTypesOrFactory = [], pipes: PipeTypesOrFactory = [], viewQuery: ComponentTemplate| null = null, providers: Provider[] = [], viewProviders: Provider[] = [], hostBindings?: HostBindingsFunction, - attrs: TAttributes[] = []): ComponentType { + consts: TAttributes[] = []): ComponentType { return class Component { value: any; static ngFactoryDef = () => new Component; @@ -385,7 +385,7 @@ export function createComponent( pipes: pipes, features: (providers.length > 0 || viewProviders.length > 0)? [ɵɵProvidersFeature(providers || [], viewProviders || [])]: [], - attrs: attrs, + consts: consts, }); }; } diff --git a/packages/core/test/render3/view_container_ref_spec.ts b/packages/core/test/render3/view_container_ref_spec.ts index b34adac42c95f..cbc693e402eba 100644 --- a/packages/core/test/render3/view_container_ref_spec.ts +++ b/packages/core/test/render3/view_container_ref_spec.ts @@ -108,7 +108,7 @@ describe('ViewContainerRef', () => { selectors: [['test-cmp']], decls: 4, vars: 0, - attrs: [['testdir', '']], + consts: [['testdir', '']], template: (rf: RenderFlags, cmp: TestComponent) => { if (rf & RenderFlags.Create) { ɵɵtext(0, 'before|'); @@ -180,7 +180,7 @@ describe('ViewContainerRef', () => { selectors: [['test-cmp']], decls: 4, vars: 0, - attrs: [['testdir', '']], + consts: [['testdir', '']], template: (rf: RenderFlags, cmp: TestComponent) => { if (rf & RenderFlags.Create) { ɵɵtext(0, 'before|'); @@ -441,7 +441,7 @@ describe('ViewContainerRef', () => { selectors: [['dynamic-cmpt-with-view-queries']], decls: 2, vars: 0, - attrs: [['bar', '']], + consts: [['bar', '']], template: (rf: RenderFlags, ctx: DynamicCompWithViewQueries) => { if (rf & RenderFlags.Create) { ɵɵelement(0, 'div', 0, ['foo', '']); diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 20aa182cdc707..2618ac9d29bbc 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -773,7 +773,7 @@ export declare function ɵɵdefineBase(baseDefinition: { export declare function ɵɵdefineComponent(componentDefinition: { type: Type; selectors: CssSelectorList; - consts: number; + decls: number; vars: number; inputs?: { [P in keyof T]?: string | [string, string]; @@ -785,7 +785,7 @@ export declare function ɵɵdefineComponent(componentDefinition: { contentQueries?: ContentQueriesFunction; exportAs?: string[]; template: ComponentTemplate; - attrs?: TAttributes[]; + consts?: TAttributes[]; ngContentSelectors?: string[]; viewQuery?: ViewQueriesFunction | null; features?: ComponentDefFeature[]; @@ -851,23 +851,23 @@ export declare function ɵɵdirectiveInject(token: Type | InjectionToken | null, consts: number, vars: number, tagName?: string | null, attrsIndex?: number | null, localRefs?: string[] | null, localRefExtractor?: LocalRefExtractor): void; +export declare function ɵɵtemplate(index: number, templateFn: ComponentTemplate | null, decls: number, vars: number, tagName?: string | null, constsIndex?: number | null, localRefs?: string[] | null, localRefExtractor?: LocalRefExtractor): void; export declare function ɵɵtemplateRefExtractor(tNode: TNode, currentView: LView): ViewEngine_TemplateRef | null;