diff --git a/aio/scripts/_payload-limits.json b/aio/scripts/_payload-limits.json index 415c04e78a..4ba1f0b7e6 100755 --- a/aio/scripts/_payload-limits.json +++ b/aio/scripts/_payload-limits.json @@ -4,10 +4,10 @@ "uncompressed": { "runtime-es5": 3042, "runtime-es2015": 3048, - "main-es5": 511036, - "main-es2015": 450486, - "polyfills-es5": 130136, - "polyfills-es2015": 52931 + "main-es5": 511052, + "main-es2015": 450562, + "polyfills-es5": 129161, + "polyfills-es2015": 53295 } } }, @@ -16,10 +16,10 @@ "uncompressed": { "runtime-es5": 3042, "runtime-es2015": 3048, - "main-es5": 511036, - "main-es2015": 450486, - "polyfills-es5": 130136, - "polyfills-es2015": 52931 + "main-es5": 499085, + "main-es2015": 438296, + "polyfills-es5": 129161, + "polyfills-es2015": 53295 } } }, @@ -28,10 +28,10 @@ "uncompressed": { "runtime-es5": 2932, "runtime-es2015": 2938, - "main-es5": 565073, - "main-es2015": 583108, - "polyfills-es5": 130136, - "polyfills-es2015": 52931 + "main-es5": 555102, + "main-es2015": 572938, + "polyfills-es5": 129161, + "polyfills-es2015": 53295 } } } diff --git a/integration/_payload-limits.json b/integration/_payload-limits.json index 7a79c70b08..6d4990abfc 100644 --- a/integration/_payload-limits.json +++ b/integration/_payload-limits.json @@ -12,7 +12,7 @@ "master": { "uncompressed": { "runtime": 1440, - "main": 14847, + "main": 14912, "polyfills": 43567 } } @@ -21,7 +21,7 @@ "master": { "uncompressed": { "runtime": 1440, - "main": 149248, + "main": 147528, "polyfills": 43567 } } diff --git a/modules/benchmarks/src/tree/render3_function/index.ts b/modules/benchmarks/src/tree/render3_function/index.ts index 9b2d11ab2c..1401374bf0 100644 --- a/modules/benchmarks/src/tree/render3_function/index.ts +++ b/modules/benchmarks/src/tree/render3_function/index.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {ɵRenderFlags, ɵrenderComponent as renderComponent, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵdefineComponent, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵselect, ɵɵstyleProp, ɵɵstyling, ɵɵtext, ɵɵtextInterpolate1} from '@angular/core'; +import {ɵRenderFlags, ɵrenderComponent as renderComponent, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵdefineComponent, ɵɵelementEnd, ɵɵelementStart, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵselect, ɵɵstyleProp, ɵɵstyling, ɵɵstylingApply, ɵɵtext, ɵɵtextInterpolate1} from '@angular/core'; import {bindAction, profile} from '../../util'; import {createDom, destroyDom, detectChanges} from '../render3/tree'; @@ -32,13 +32,12 @@ export class TreeFunction { }); } -const c1 = ['background-color']; export function TreeTpl(rf: ɵRenderFlags, ctx: TreeNode) { if (rf & ɵRenderFlags.Create) { ɵɵelementStart(0, 'tree'); { ɵɵelementStart(1, 'span'); - ɵɵstyling(null, c1); + ɵɵstyling(); { ɵɵtext(2); } ɵɵelementEnd(); ɵɵcontainer(3); @@ -48,8 +47,8 @@ export function TreeTpl(rf: ɵRenderFlags, ctx: TreeNode) { } if (rf & ɵRenderFlags.Update) { ɵɵselect(1); - ɵɵstyleProp(0, ctx.depth % 2 ? '' : 'grey'); - ɵɵstyling(); + ɵɵstyleProp('background-color', ctx.depth % 2 ? '' : 'grey'); + ɵɵstylingApply(); ɵɵselect(2); ɵɵtextInterpolate1(' ', ctx.value, ' '); ɵɵcontainerRefreshStart(3); 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 50f048ebed..fc3581ad51 100644 --- a/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts @@ -478,24 +478,21 @@ describe('compiler compliance', () => { const factory = 'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }'; const template = ` - const $e0_classBindings$ = ["error"]; - const $e0_styleBindings$ = ["background-color"]; - … MyComponent.ngComponentDef = i0.ɵɵdefineComponent({type:MyComponent,selectors:[["my-component"]], factory: function MyComponent_Factory(t){ return new (t || MyComponent)(); }, consts: 1, - vars: 0, + vars: 2, template: function MyComponent_Template(rf,ctx){ if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling($e0_classBindings$, $e0_styleBindings$); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { - $r3$.ɵɵstyleProp(0, ctx.color); - $r3$.ɵɵclassProp(0, ctx.error); + $r3$.ɵɵstyleProp("background-color", ctx.color); + $r3$.ɵɵclassProp("error", ctx.error); $r3$.ɵɵstylingApply(); } }, 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 fc89d8e9f6..09d5b2b081 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 @@ -884,6 +884,7 @@ describe('compiler compliance: bindings', () => { factory: function HostAttributeDir_Factory(t) { return new (t || HostAttributeDir)(); }, hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) { if (rf & 1) { + $r3$.ɵɵallocHostVars(2); $r3$.ɵɵelementHostAttrs($c1$); … } 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 478e3b9811..01bc7c9619 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 @@ -6,10 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {AttributeMarker, ViewEncapsulation} from '@angular/compiler/src/core'; -import {CompilerStylingMode, compilerSetStylingMode} from '@angular/compiler/src/render3/view/styling_state'; +import {AttributeMarker} from '@angular/compiler/src/core'; import {setup} from '@angular/compiler/test/aot/test_util'; - import {compile, expectEmit} from './mock_compile'; describe('compiler compliance: styling', () => { @@ -385,10 +383,11 @@ describe('compiler compliance: styling', () => { template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(null, null, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap($ctx$.myStyleExp); $r3$.ɵɵstylingApply(); } @@ -446,7 +445,7 @@ describe('compiler compliance: styling', () => { const template = ` … consts: 1, - vars: 1, + vars: 2, template: function MyComponentWithInterpolation_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -460,7 +459,7 @@ describe('compiler compliance: styling', () => { } … consts: 1, - vars: 2, + vars: 3, template: function MyComponentWithMuchosInterpolation_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -474,7 +473,7 @@ describe('compiler compliance: styling', () => { } … consts: 1, - vars: 0, + vars: 1, template: function MyComponentWithoutInterpolation_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); @@ -521,7 +520,6 @@ describe('compiler compliance: styling', () => { const template = ` const $_c0$ = [${AttributeMarker.Styles}, "opacity", "1"]; - const $_c1$ = ["width", "height"]; … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ type: MyComponent, @@ -530,17 +528,18 @@ describe('compiler compliance: styling', () => { return new (t || MyComponent)(); }, consts: 1, - vars: 1, + vars: 4, template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", $_c0$); - $r3$.ɵɵstyling(null, $_c1$, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap($ctx$.myStyleExp); - $r3$.ɵɵstyleProp(0, $ctx$.myWidth); - $r3$.ɵɵstyleProp(1, $ctx$.myHeight); + $r3$.ɵɵstyleProp("width", $ctx$.myWidth); + $r3$.ɵɵstyleProp("height", $ctx$.myHeight); $r3$.ɵɵstylingApply(); $r3$.ɵɵattribute("style", "border-width: 10px", $r3$.ɵɵsanitizeStyle); } @@ -575,13 +574,6 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $_c0$ = ["background-image"]; - export class MyComponent { - constructor() { - this.myImage = 'url(foo.jpg)'; - } - } - MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ type: MyComponent, selectors: [["my-component"]], @@ -589,15 +581,16 @@ describe('compiler compliance: styling', () => { return new (t || MyComponent)(); }, consts: 1, - vars: 0, + vars: 1, template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(null, _c0, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { - $r3$.ɵɵstyleProp(0, ctx.myImage); + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyleProp("background-image", ctx.myImage); $r3$.ɵɵstylingApply(); } }, @@ -629,16 +622,14 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $e0_styles$ = ["font-size"]; - … template: function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(null, _c0); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { - $r3$.ɵɵstyleProp(0, 12, "px"); + $r3$.ɵɵstyleProp("font-size", 12, "px"); $r3$.ɵɵstylingApply(); } } @@ -646,7 +637,6 @@ describe('compiler compliance: styling', () => { const result = compile(files, angularFiles); expectEmit(result.source, template, 'Incorrect template'); - }); it('should not create instructions for empty style bindings', () => { @@ -742,7 +732,6 @@ describe('compiler compliance: styling', () => { const template = ` const $e0_attrs$ = [${AttributeMarker.Classes}, "grape"]; - const $e0_bindings$ = ["apple", "orange"]; … MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({ type: MyComponent, @@ -751,17 +740,17 @@ describe('compiler compliance: styling', () => { return new (t || MyComponent)(); }, consts: 1, - vars: 1, + vars: 4, template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div", $e0_attrs$); - $r3$.ɵɵstyling($e0_bindings$); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { $r3$.ɵɵclassMap($ctx$.myClassExp); - $r3$.ɵɵclassProp(0, $ctx$.yesToApple); - $r3$.ɵɵclassProp(1, $ctx$.yesToOrange); + $r3$.ɵɵclassProp("apple", $ctx$.yesToApple); + $r3$.ɵɵclassProp("orange", $ctx$.yesToOrange); $r3$.ɵɵstylingApply(); $r3$.ɵɵattribute("class", "banana"); } @@ -874,10 +863,11 @@ describe('compiler compliance: styling', () => { template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(null, null, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap($ctx$.myStyleExp); $r3$.ɵɵclassMap($ctx$.myClassExp); $r3$.ɵɵstylingApply(); @@ -915,14 +905,15 @@ describe('compiler compliance: styling', () => { template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(null, null, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵpipe(1, "stylePipe"); $r3$.ɵɵpipe(2, "classPipe"); $r3$.ɵɵelementEnd(); } if (rf & 2) { - $r3$.ɵɵstyleMap($r3$.ɵɵpipeBind1(1, 0, $ctx$.myStyleExp)); - $r3$.ɵɵclassMap($r3$.ɵɵpipeBind1(2, 2, $ctx$.myClassExp)); + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyleMap($r3$.ɵɵpipeBind1(1, 2, $ctx$.myStyleExp)); + $r3$.ɵɵclassMap($r3$.ɵɵpipeBind1(2, 4, $ctx$.myClassExp)); $r3$.ɵɵstylingApply(); } } @@ -963,13 +954,10 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $e0_classBindings$ = ["foo"]; - const $e0_styleBindings$ = ["bar", "baz"]; - … template: function MyComponent_Template(rf, $ctx$) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling($e0_classBindings$, $e0_styleBindings$, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵpipe(1, "pipe"); $r3$.ɵɵpipe(2, "pipe"); $r3$.ɵɵpipe(3, "pipe"); @@ -978,11 +966,12 @@ describe('compiler compliance: styling', () => { $r3$.ɵɵelementEnd(); } if (rf & 2) { - $r3$.ɵɵstyleMap($r3$.ɵɵpipeBind2(1, 1, $ctx$.myStyleExp, 1000)); + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyleMap($r3$.ɵɵpipeBind2(1, 6, $ctx$.myStyleExp, 1000)); $r3$.ɵɵclassMap($e2_styling$); - $r3$.ɵɵstyleProp(0, $r3$.ɵɵpipeBind2(2, 4, $ctx$.barExp, 3000)); - $r3$.ɵɵstyleProp(1, $r3$.ɵɵpipeBind2(3, 7, $ctx$.bazExp, 4000)); - $r3$.ɵɵclassProp(0, $r3$.ɵɵpipeBind2(4, 10, $ctx$.fooExp, 2000)); + $r3$.ɵɵstyleProp("bar", $r3$.ɵɵpipeBind2(2, 9, $ctx$.barExp, 3000)); + $r3$.ɵɵstyleProp("baz", $r3$.ɵɵpipeBind2(3, 12, $ctx$.bazExp, 4000)); + $r3$.ɵɵclassProp("foo", $r3$.ɵɵpipeBind2(4, 15, $ctx$.fooExp, 2000)); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(5); $r3$.ɵɵtextInterpolate1(" ", $ctx$.item, ""); @@ -1027,16 +1016,16 @@ describe('compiler compliance: styling', () => { template: function MyComponent_Template(rf, $ctx$) { … if (rf & 2) { - $r3$.ɵɵstyleProp(0, $ctx$.w1); + $r3$.ɵɵstyleProp("width", $ctx$.w1); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(1); - $r3$.ɵɵstyleProp(0, $ctx$.h1); + $r3$.ɵɵstyleProp("height", $ctx$.h1); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(2); - $r3$.ɵɵclassProp(0, $ctx$.a1); + $r3$.ɵɵclassProp("active", $ctx$.a1); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(3); - $r3$.ɵɵclassProp(0, $ctx$.r1); + $r3$.ɵɵclassProp("removed", $ctx$.r1); $r3$.ɵɵstylingApply(); } } @@ -1083,20 +1072,18 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $e0_attrs$ = [${AttributeMarker.Classes}, "foo", "baz", ${AttributeMarker.Styles}, "width", "200px", "height", "500px"]; - const $e0_classBindings$ = ["foo"]; - const $e0_styleBindings$ = ["color"]; - … hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) { if (rf & 1) { + $r3$.ɵɵallocHostVars(4); $r3$.ɵɵelementHostAttrs($e0_attrs$); - $r3$.ɵɵstyling($e0_classBindings$, $e0_styleBindings$, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap(ctx.myStyle); $r3$.ɵɵclassMap(ctx.myClass); - $r3$.ɵɵstyleProp(0, ctx.myColorProp); - $r3$.ɵɵclassProp(0, ctx.myFooClass); + $r3$.ɵɵstyleProp("color", ctx.myColorProp); + $r3$.ɵɵclassProp("foo", ctx.myFooClass); $r3$.ɵɵstylingApply(); } }, @@ -1146,20 +1133,19 @@ describe('compiler compliance: styling', () => { }; const template = ` - const _c0 = ["bar", "foo"]; - const _c1 = ["height", "width"]; - … hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵstyling(_c0, _c1, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵallocHostVars(6); + $r3$.ɵɵstyling(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap(ctx.myStyle); $r3$.ɵɵclassMap(ctx.myClasses); - $r3$.ɵɵstyleProp(0, ctx.myHeightProp, "pt"); - $r3$.ɵɵstyleProp(1, ctx.myWidthProp); - $r3$.ɵɵclassProp(0, ctx.myBarClass); - $r3$.ɵɵclassProp(1, ctx.myFooClass); + $r3$.ɵɵstyleProp("height", ctx.myHeightProp, "pt"); + $r3$.ɵɵstyleProp("width", ctx.myWidthProp); + $r3$.ɵɵclassProp("bar", ctx.myBarClass); + $r3$.ɵɵclassProp("foo", ctx.myFooClass); $r3$.ɵɵstylingApply(); } }, @@ -1209,38 +1195,35 @@ describe('compiler compliance: styling', () => { }; const template = ` - const _c2 = ["bar"]; - const _c3 = ["height"]; - … function MyComponent_Template(rf, ctx) { if (rf & 1) { $r3$.ɵɵelementStart(0, "div"); - $r3$.ɵɵstyling(_c2, _c3, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); $r3$.ɵɵelementEnd(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap(ctx.myStyleExp); $r3$.ɵɵclassMap(ctx.myClassExp); - $r3$.ɵɵstyleProp(0, ctx.myHeightExp, null, true); - $r3$.ɵɵclassProp(0, ctx.myBarClassExp, true); + $r3$.ɵɵstyleProp("height", ctx.myHeightExp); + $r3$.ɵɵclassProp("bar", ctx.myBarClassExp); $r3$.ɵɵstylingApply(); } }, `; const hostBindings = ` - const _c0 = ["foo"]; - const _c1 = ["width"]; - … hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵstyling(_c0, _c1, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵallocHostVars(4); + $r3$.ɵɵstyling(); } if (rf & 2) { + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap(ctx.myStyleExp); $r3$.ɵɵclassMap(ctx.myClassExp); - $r3$.ɵɵstyleProp(0, ctx.myWidthExp, null, true); - $r3$.ɵɵclassProp(0, ctx.myFooClassExp, true); + $r3$.ɵɵstyleProp("width", ctx.myWidthExp); + $r3$.ɵɵclassProp("foo", ctx.myFooClassExp); $r3$.ɵɵstylingApply(); } }, @@ -1296,13 +1279,9 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $widthDir_classes$ = ["foo"]; - const $widthDir_styles$ = ["width"]; - const $heightDir_classes$ = ["bar"]; - const $heightDir_styles$ = ["height"]; - … function ClassDirective_HostBindings(rf, ctx, elIndex) { if (rf & 1) { + $r3$.ɵɵallocHostVars(1); $r3$.ɵɵstyling(); } if (rf & 2) { @@ -1313,22 +1292,24 @@ describe('compiler compliance: styling', () => { … function WidthDirective_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵstyling($widthDir_classes$, $widthDir_styles$); + $r3$.ɵɵallocHostVars(2); + $r3$.ɵɵstyling(); } if (rf & 2) { - $r3$.ɵɵstyleProp(0, ctx.myWidth); - $r3$.ɵɵclassProp(0, ctx.myFooClass); + $r3$.ɵɵstyleProp("width", ctx.myWidth); + $r3$.ɵɵclassProp("foo", ctx.myFooClass); $r3$.ɵɵstylingApply(); } } … function HeightDirective_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵstyling($heightDir_classes$, $heightDir_styles$); + $r3$.ɵɵallocHostVars(2); + $r3$.ɵɵstyling(); } if (rf & 2) { - $r3$.ɵɵstyleProp(0, ctx.myHeight); - $r3$.ɵɵclassProp(0, ctx.myBarClass); + $r3$.ɵɵstyleProp("height", ctx.myHeight); + $r3$.ɵɵclassProp("bar", ctx.myBarClass); $r3$.ɵɵstylingApply(); } } @@ -1472,34 +1453,34 @@ describe('compiler compliance: styling', () => { const template = ` … if (rf & 2) { - $r3$.ɵɵstylePropInterpolateV(0, ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]); + $r3$.ɵɵstylePropInterpolateV("color", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(1); - $r3$.ɵɵstylePropInterpolate8(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"); + $r3$.ɵɵstylePropInterpolate8("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(2); - $r3$.ɵɵstylePropInterpolate7(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"); + $r3$.ɵɵstylePropInterpolate7("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(3); - $r3$.ɵɵstylePropInterpolate6(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"); + $r3$.ɵɵstylePropInterpolate6("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(4); - $r3$.ɵɵstylePropInterpolate5(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"); + $r3$.ɵɵstylePropInterpolate5("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(5); - $r3$.ɵɵstylePropInterpolate4(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"); + $r3$.ɵɵstylePropInterpolate4("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(6); - $r3$.ɵɵstylePropInterpolate3(0, "a", ctx.one, "b", ctx.two, "c", ctx.three, "d"); + $r3$.ɵɵstylePropInterpolate3("color", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(7); - $r3$.ɵɵstylePropInterpolate2(0, "a", ctx.one, "b", ctx.two, "c"); + $r3$.ɵɵstylePropInterpolate2("color", "a", ctx.one, "b", ctx.two, "c"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(8); - $r3$.ɵɵstylePropInterpolate1(0, "a", ctx.one, "b"); + $r3$.ɵɵstylePropInterpolate1("color", "a", ctx.one, "b"); $r3$.ɵɵstylingApply(); $r3$.ɵɵselect(9); - $r3$.ɵɵstyleProp(0, ctx.one); + $r3$.ɵɵstyleProp("color", ctx.one); $r3$.ɵɵstylingApply(); } … @@ -1530,7 +1511,7 @@ describe('compiler compliance: styling', () => { const template = ` … if (rf & 2) { - $r3$.ɵɵstylePropInterpolate2(0, "a", ctx.one, "b", ctx.two, "c", "px"); + $r3$.ɵɵstylePropInterpolate2("width", "a", ctx.one, "b", ctx.two, "c", "px"); $r3$.ɵɵstylingApply(); } … @@ -1561,7 +1542,7 @@ describe('compiler compliance: styling', () => { const template = ` … if (rf & 2) { - $r3$.ɵɵstylePropInterpolate2(0, "a", ctx.one, "b", ctx.two, "c", null, true); + $r3$.ɵɵstylePropInterpolate2("width", "a", ctx.one, "b", ctx.two, "c"); $r3$.ɵɵstylingApply(); } … @@ -1616,12 +1597,13 @@ describe('compiler compliance: styling', () => { … hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵallocHostVars(2); + $r3$.ɵɵallocHostVars(4); $r3$.ɵɵelementHostAttrs($_c0$); - $r3$.ɵɵstyling(null, null, $r3$.ɵɵdefaultStyleSanitizer); + $r3$.ɵɵstyling(); } if (rf & 2) { $r3$.ɵɵhostProperty("id", ctx.id)("title", ctx.title); + $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); $r3$.ɵɵstyleMap(ctx.myStyle); $r3$.ɵɵclassMap(ctx.myClass); $r3$.ɵɵstylingApply(); @@ -1658,18 +1640,15 @@ describe('compiler compliance: styling', () => { }; const template = ` - const $_c0$ = ["foo"]; - const $_c1$ = ["width"]; - … hostBindings: function WidthDirective_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - $r3$.ɵɵallocHostVars(2); - $r3$.ɵɵstyling($_c0$, $_c1$); + $r3$.ɵɵallocHostVars(4); + $r3$.ɵɵstyling(); } if (rf & 2) { $r3$.ɵɵhostProperty("id", ctx.id)("title", ctx.title); - $r3$.ɵɵstyleProp(0, ctx.myWidth); - $r3$.ɵɵclassProp(0, ctx.myFooClass); + $r3$.ɵɵstyleProp("width", ctx.myWidth); + $r3$.ɵɵclassProp("foo", ctx.myFooClass); $r3$.ɵɵstylingApply(); } } @@ -1680,10 +1659,6 @@ describe('compiler compliance: styling', () => { }); describe('new styling refactor', () => { - beforeEach(() => { compilerSetStylingMode(CompilerStylingMode.UseNew); }); - - afterEach(() => { compilerSetStylingMode(CompilerStylingMode.UseOld); }); - it('should generate a `styleSanitizer` instruction when one or more sanitizable style properties are statically detected', () => { const files = { @@ -1709,7 +1684,7 @@ describe('compiler compliance: styling', () => { … if (rf & 2) { $r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer); - $r3$.ɵɵstyleProp(0, ctx.bgExp); + $r3$.ɵɵstyleProp("background-image", ctx.bgExp); $r3$.ɵɵstylingApply(); } … @@ -1782,7 +1757,7 @@ describe('compiler compliance: styling', () => { … if (rf & 2) { $r3$.ɵɵclassMap(ctx.mapExp); - $r3$.ɵɵclassProp(0, ctx.nameExp); + $r3$.ɵɵclassProp("name", ctx.nameExp); $r3$.ɵɵstylingApply(); } … @@ -1792,5 +1767,67 @@ describe('compiler compliance: styling', () => { const result = compile(files, angularFiles); expectEmit(result.source, template, 'Incorrect template'); }); + + it('should generate the correct amount of host bindings when styling is present', () => { + const files = { + app: { + 'spec.ts': ` + import {Component, Directive, NgModule} from '@angular/core'; + + @Directive({ + selector: '[my-dir]', + host: { + '[title]': 'title', + '[class.foo]': 'foo', + '[@anim]': \`{ + value: _animValue, + params: { + param1: _animParam1, + param2: _animParam2 + } + }\` + } + }) + export class MyDir { + title = ''; + foo = true; + _animValue = null; + _animParam1 = null; + _animParam2 = null; + } + + @Component({ + selector: 'my-app', + template: \` +
+ \` + }) + export class MyAppComp {} + + @NgModule({declarations: [MyAppComp, MyDir]}) + export class MyModule {} + ` + } + }; + + const template = ` + hostBindings: function MyDir_HostBindings(rf, ctx, elIndex) { + … + $r3$.ɵɵallocHostVars(9); + … + if (rf & 2) { + $r3$.ɵɵhostProperty("title", ctx.title); + $r3$.ɵɵupdateSyntheticHostBinding("@anim", + $r3$.ɵɵpureFunction2(6, _c1, ctx._animValue, + $r3$.ɵɵpureFunction2(3, _c0, ctx._animParam1, ctx._animParam2))); + $r3$.ɵɵclassProp("foo", ctx.foo); + $r3$.ɵɵstylingApply(); + } + } + `; + + const result = compile(files, angularFiles); + expectEmit(result.source, template, 'Incorrect template'); + }); }); }); diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 6bd962b9d6..a89bd1c796 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -1825,16 +1825,16 @@ runInEachFileSystem(os => { const hostBindingsFn = ` hostBindings: function FooCmp_HostBindings(rf, ctx, elIndex) { if (rf & 1) { - i0.ɵɵallocHostVars(2); + i0.ɵɵallocHostVars(3); i0.ɵɵlistener("click", function FooCmp_click_HostBindingHandler($event) { return ctx.onClick($event); }); i0.ɵɵlistener("click", function FooCmp_click_HostBindingHandler($event) { return ctx.onBodyClick($event); }, false, i0.ɵɵresolveBody); i0.ɵɵlistener("change", function FooCmp_change_HostBindingHandler($event) { return ctx.onChange(ctx.arg1, ctx.arg2, ctx.arg3); }); - i0.ɵɵstyling(_c0); + i0.ɵɵstyling(); } if (rf & 2) { i0.ɵɵhostProperty("prop", ctx.bar); i0.ɵɵattribute("hello", ctx.foo); - i0.ɵɵclassProp(0, ctx.someClass); + i0.ɵɵclassProp("someclass", ctx.someClass); i0.ɵɵstylingApply(); } } diff --git a/packages/compiler/src/render3/view/compiler.ts b/packages/compiler/src/render3/view/compiler.ts index 401e3331f6..7b6fc0deb2 100644 --- a/packages/compiler/src/render3/view/compiler.ts +++ b/packages/compiler/src/render3/view/compiler.ts @@ -586,14 +586,8 @@ function createHostBindingsFunction( hostBindingsMetadata: R3HostMetadata, typeSourceSpan: ParseSourceSpan, bindingParser: BindingParser, constantPool: ConstantPool, selector: string, name?: string): o.Expression|null { - // Initialize hostVarsCount to number of bound host properties (interpolations illegal), - // except 'style' and 'class' properties, since they should *not* allocate host var slots - const hostVarsCount = Object.keys(hostBindingsMetadata.properties) - .filter(name => { - const prefix = getStylingPrefix(name); - return prefix !== 'style' && prefix !== 'class'; - }) - .length; + // Initialize hostVarsCount to number of bound host properties (interpolations illegal) + const hostVarsCount = Object.keys(hostBindingsMetadata.properties).length; const elVarExp = o.variable('elIndex'); const bindingContext = o.variable(CONTEXT_NAME); const styleBuilder = new StylingBuilder(elVarExp, bindingContext); @@ -733,7 +727,10 @@ function createHostBindingsFunction( // the update block of a component/directive templateFn/hostBindingsFn so that the bindings // are evaluated and updated for the element. styleBuilder.buildUpdateLevelInstructions(getValueConverter()).forEach(instruction => { - totalHostVarsCount += instruction.allocateBindingSlots; + // we subtract a value of `1` here because the binding slot was already + // allocated at the top of this method when all the input bindings were + // counted. + totalHostVarsCount += Math.max(instruction.allocateBindingSlots - 1, 0); updateStatements.push(createStylingStmt(instruction, bindingContext, bindingFn)); }); } diff --git a/packages/compiler/src/render3/view/styling_builder.ts b/packages/compiler/src/render3/view/styling_builder.ts index 26133a1eed..b7d06f64d4 100644 --- a/packages/compiler/src/render3/view/styling_builder.ts +++ b/packages/compiler/src/render3/view/styling_builder.ts @@ -15,8 +15,7 @@ import {error} from '../../util'; import * as t from '../r3_ast'; import {Identifiers as R3} from '../r3_identifiers'; -import {parse as parseStyle} from './style_parser'; -import {compilerIsNewStylingInUse} from './styling_state'; +import {hyphenate, parse as parseStyle} from './style_parser'; import {ValueConverter} from './template'; import {getInterpolationArgsLength} from './util'; @@ -69,7 +68,7 @@ interface BoundStylingEntry { * classMap(...) * styleProp(...) * classProp(...) - * stylingApp(...) + * stylingApply(...) * } * * The creation/update methods within the builder class produce these instructions. @@ -171,6 +170,7 @@ export class StylingBuilder { if (isEmptyExpression(value)) { return null; } + name = normalizePropName(name); const {property, hasOverrideFlag, unit: bindingUnit} = parseProperty(name); const entry: BoundStylingEntry = { name: property, @@ -296,46 +296,7 @@ export class StylingBuilder { sourceSpan, allocateBindingSlots: 0, reference: R3.styling, - params: () => { - // a string array of every style-based binding - const styleBindingProps = - this._singleStyleInputs ? this._singleStyleInputs.map(i => o.literal(i.name)) : []; - // a string array of every class-based binding - const classBindingNames = - this._singleClassInputs ? this._singleClassInputs.map(i => o.literal(i.name)) : []; - - // to salvage space in the AOT generated code, there is no point in passing - // in `null` into a param if any follow-up params are not used. Therefore, - // only when a trailing param is used then it will be filled with nulls in between - // (otherwise a shorter amount of params will be filled). The code below helps - // determine how many params are required in the expression code. - // - // min params => styling() - // max params => styling(classBindings, styleBindings, sanitizer) - // - const params: o.Expression[] = []; - let expectedNumberOfArgs = 0; - if (this._useDefaultSanitizer) { - expectedNumberOfArgs = 3; - } else if (styleBindingProps.length) { - expectedNumberOfArgs = 2; - } else if (classBindingNames.length) { - expectedNumberOfArgs = 1; - } - - addParam( - params, classBindingNames.length > 0, - getConstantLiteralFromArray(constantPool, classBindingNames), 1, - expectedNumberOfArgs); - addParam( - params, styleBindingProps.length > 0, - getConstantLiteralFromArray(constantPool, styleBindingProps), 2, - expectedNumberOfArgs); - addParam( - params, this._useDefaultSanitizer, o.importExpr(R3.defaultStyleSanitizer), 3, - expectedNumberOfArgs); - return params; - } + params: () => [], }; } return null; @@ -370,12 +331,8 @@ export class StylingBuilder { private _buildMapBasedInstruction( valueConverter: ValueConverter, isClassBased: boolean, stylingInput: BoundStylingEntry): StylingInstruction { - let totalBindingSlotsRequired = 0; - if (compilerIsNewStylingInUse()) { - // the old implementation does not reserve slot values for - // binding entries. The new one does. - totalBindingSlotsRequired++; - } + // each styling binding value is stored in the LView + let totalBindingSlotsRequired = 1; // these values must be outside of the update block so that they can // be evaluated (the AST visit call) during creation time so that any @@ -408,8 +365,11 @@ export class StylingBuilder { StylingInstruction[] { let totalBindingSlotsRequired = 0; return inputs.map(input => { - const bindingIndex: number = mapIndex.get(input.name !) !; const value = input.value.visit(valueConverter); + + // each styling binding value is stored in the LView + let totalBindingSlotsRequired = 1; + if (value instanceof Interpolation) { totalBindingSlotsRequired += value.expressions.length; @@ -417,35 +377,25 @@ export class StylingBuilder { reference = getInterpolationExpressionFn(value); } } - if (compilerIsNewStylingInUse()) { - // the old implementation does not reserve slot values for - // binding entries. The new one does. - totalBindingSlotsRequired++; - } + return { sourceSpan: input.sourceSpan, supportsInterpolation: !!getInterpolationExpressionFn, allocateBindingSlots: totalBindingSlotsRequired, reference, params: (convertFn: (value: any) => o.Expression | o.Expression[]) => { - // min params => stylingProp(elmIndex, bindingIndex, value) - // max params => stylingProp(elmIndex, bindingIndex, value, overrideFlag) - const params: o.Expression[] = [o.literal(bindingIndex)]; + // params => stylingProp(propName, value) + const params: o.Expression[] = []; + params.push(o.literal(input.name)); + const convertResult = convertFn(value); if (Array.isArray(convertResult)) { params.push(...convertResult); } else { params.push(convertResult); } - if (allowUnits) { - if (input.unit) { - params.push(o.literal(input.unit)); - } else if (input.hasOverrideFlag) { - params.push(o.NULL_EXPR); - } - } - if (input.hasOverrideFlag) { - params.push(o.literal(true)); + if (allowUnits && input.unit) { + params.push(o.literal(input.unit)); } return params; @@ -496,7 +446,7 @@ export class StylingBuilder { buildUpdateLevelInstructions(valueConverter: ValueConverter) { const instructions: StylingInstruction[] = []; if (this.hasBindings) { - if (compilerIsNewStylingInUse() && this._useDefaultSanitizer) { + if (this._useDefaultSanitizer) { instructions.push(this._buildSanitizerFn()); } const styleMapInstruction = this.buildStyleMapInstruction(valueConverter); @@ -630,3 +580,7 @@ function getStylePropInterpolationExpression(interpolation: Interpolation) { return R3.stylePropInterpolateV; } } + +function normalizePropName(prop: string): string { + return hyphenate(prop); +} diff --git a/packages/compiler/src/render3/view/styling_state.ts b/packages/compiler/src/render3/view/styling_state.ts deleted file mode 100644 index c63ab6d8e6..0000000000 --- a/packages/compiler/src/render3/view/styling_state.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license -* Copyright Google Inc. All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ - -/** - * A temporary enum of states that inform the core whether or not - * to defer all styling instruction calls to the old or new - * styling implementation. - */ -export const enum CompilerStylingMode { - UseOld = 0, - UseBothOldAndNew = 1, - UseNew = 2, -} - -let _stylingMode = 0; - -/** - * Temporary function used to inform the existing styling algorithm - * code to delegate all styling instruction calls to the new refactored - * styling code. - */ -export function compilerSetStylingMode(mode: CompilerStylingMode) { - _stylingMode = mode; -} - -export function compilerIsNewStylingInUse() { - return _stylingMode > CompilerStylingMode.UseOld; -} - -export function compilerAllowOldStyling() { - return _stylingMode < CompilerStylingMode.UseNew; -} diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 128a9bc29d..8bf4c36253 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -122,6 +122,7 @@ export { ɵɵelementContainer, ɵɵstyling, ɵɵstyleMap, + ɵɵstyleSanitizer, ɵɵclassMap, ɵɵclassMapInterpolate1, ɵɵclassMapInterpolate2, diff --git a/packages/core/src/debug/debug_node.ts b/packages/core/src/debug/debug_node.ts index 09580ffbcd..f599614088 100644 --- a/packages/core/src/debug/debug_node.ts +++ b/packages/core/src/debug/debug_node.ts @@ -10,11 +10,12 @@ import {Injector} from '../di'; import {getViewComponent} from '../render3/global_utils_api'; import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container'; import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node'; -import {StylingIndex} from '../render3/interfaces/styling'; import {isComponent, isLContainer} from '../render3/interfaces/type_checks'; import {LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view'; -import {getProp, getValue, isClassBasedValue} from '../render3/styling/class_and_style_bindings'; -import {getStylingContextFromLView} from '../render3/styling/util'; +import {TStylingContext} from '../render3/styling_next/interfaces'; +import {stylingMapToStringMap} from '../render3/styling_next/map_based_bindings'; +import {NodeStylingDebug} from '../render3/styling_next/styling_debug'; +import {isStylingContext} from '../render3/styling_next/util'; import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, isBrowserEvents, loadLContext, loadLContextFromNode} from '../render3/util/discovery_utils'; import {INTERPOLATION_DELIMITER, isPropMetadataString, renderStringify} from '../render3/util/misc_utils'; import {findComponentView} from '../render3/util/view_traversal_utils'; @@ -328,63 +329,12 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme return attributes; } - get classes(): {[key: string]: boolean;} { - const classes: {[key: string]: boolean;} = {}; - const element = this.nativeElement; - if (element) { - const lContext = loadLContextFromNode(element); - const stylingContext = getStylingContextFromLView(lContext.nodeIndex, lContext.lView); - if (stylingContext) { - for (let i = StylingIndex.SingleStylesStartPosition; i < stylingContext.length; - i += StylingIndex.Size) { - if (isClassBasedValue(stylingContext, i)) { - const className = getProp(stylingContext, i); - const value = getValue(stylingContext, i); - if (typeof value == 'boolean') { - // we want to ignore `null` since those don't overwrite the values. - classes[className] = value; - } - } - } - } else { - // Fallback, just read DOM. - const eClasses = element.classList; - for (let i = 0; i < eClasses.length; i++) { - classes[eClasses[i]] = true; - } - } - } - return classes; + get styles(): {[key: string]: string | null;} { + return _getStylingDebugInfo(this.nativeElement, false); } - get styles(): {[key: string]: string | null;} { - const styles: {[key: string]: string | null;} = {}; - const element = this.nativeElement; - if (element) { - const lContext = loadLContextFromNode(element); - const stylingContext = getStylingContextFromLView(lContext.nodeIndex, lContext.lView); - if (stylingContext) { - for (let i = StylingIndex.SingleStylesStartPosition; i < stylingContext.length; - i += StylingIndex.Size) { - if (!isClassBasedValue(stylingContext, i)) { - const styleName = getProp(stylingContext, i); - const value = getValue(stylingContext, i) as string | null; - if (value !== null) { - // we want to ignore `null` since those don't overwrite the values. - styles[styleName] = value; - } - } - } - } else { - // Fallback, just read DOM. - const eStyles = (element as HTMLElement).style; - for (let i = 0; i < eStyles.length; i++) { - const name = eStyles.item(i); - styles[name] = eStyles.getPropertyValue(name); - } - } - } - return styles; + get classes(): {[key: string]: boolean;} { + return _getStylingDebugInfo(this.nativeElement, true); } get childNodes(): DebugNode[] { @@ -435,6 +385,25 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme } } +function _getStylingDebugInfo(element: any, isClassBased: boolean) { + if (element) { + const context = loadLContextFromNode(element); + const lView = context.lView; + const tData = lView[TVIEW].data; + const tNode = tData[context.nodeIndex] as TNode; + if (isClassBased) { + return isStylingContext(tNode.classes) ? + new NodeStylingDebug(tNode.classes as TStylingContext, lView, true).values : + stylingMapToStringMap(tNode.classes); + } else { + return isStylingContext(tNode.styles) ? + new NodeStylingDebug(tNode.styles as TStylingContext, lView, false).values : + stylingMapToStringMap(tNode.styles); + } + } + return {}; +} + /** * Walk the TNode tree to find matches for the predicate. * diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index 35922dfd9f..9cd49a3045 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -17,7 +17,7 @@ import {assertComponentType} from './assert'; import {getComponentDef} from './definition'; import {diPublicInInjector, getOrCreateNodeInjectorForNode} from './di'; import {registerPostOrderHooks, registerPreOrderHooks} from './hooks'; -import {CLEAN_PROMISE, addToViewTree, createLView, createTView, getOrCreateTNode, getOrCreateTView, initNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, locateHostElement, queueComponentIndexForCheck, refreshDescendantViews} from './instructions/shared'; +import {CLEAN_PROMISE, addToViewTree, createLView, createTView, getOrCreateTNode, getOrCreateTView, initNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, locateHostElement, queueComponentIndexForCheck, refreshDescendantViews, renderInitialStyling} from './instructions/shared'; import {ComponentDef, ComponentType, RenderFlags} from './interfaces/definition'; import {TElementNode, TNode, TNodeFlags, TNodeType} from './interfaces/node'; import {PlayerHandler} from './interfaces/player'; @@ -230,10 +230,10 @@ export function createRootComponent