Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ivy): introduce host-specific styling instructions #29292

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration/_payload-limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"master": {
"uncompressed": {
"runtime": 1440,
"main": 13921,
"main": 14106,
"polyfills": 38390
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/directives/ng_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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
*/
import {Directive, DoCheck, Input, ɵRenderFlags, ɵdefineDirective, ɵelementStyling, ɵelementStylingApply, ɵelementStylingMap} from '@angular/core';
import {Directive, DoCheck, Input, ɵRenderFlags, ɵdefineDirective, ɵelementHostStyling, ɵelementHostStylingApply, ɵelementHostStylingMap} from '@angular/core';

import {NgClassImpl, NgClassImplProvider} from './ng_class_impl';

Expand Down Expand Up @@ -35,11 +35,11 @@ export const ngClassDirectiveDef__POST_R3__ = ɵdefineDirective({
factory: () => {},
hostBindings: function(rf: ɵRenderFlags, ctx: any, elIndex: number) {
if (rf & ɵRenderFlags.Create) {
ɵelementStyling(null, null, null, ctx);
ɵelementHostStyling();
}
if (rf & ɵRenderFlags.Update) {
ɵelementStylingMap(elIndex, ctx.getValue(), null, ctx);
ɵelementStylingApply(elIndex, ctx);
ɵelementHostStylingMap(ctx.getValue());
ɵelementHostStylingApply();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much better!

}
}
});
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/directives/ng_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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
*/
import {Directive, DoCheck, Input, ɵRenderFlags, ɵdefineDirective, ɵelementStyling, ɵelementStylingApply, ɵelementStylingMap} from '@angular/core';
import {Directive, DoCheck, Input, ɵRenderFlags, ɵdefineDirective, ɵelementHostStyling, ɵelementHostStylingApply, ɵelementHostStylingMap} from '@angular/core';

import {NgStyleImpl, NgStyleImplProvider} from './ng_style_impl';

Expand Down Expand Up @@ -35,11 +35,11 @@ export const ngStyleDirectiveDef__POST_R3__ = ɵdefineDirective({
factory: () => {},
hostBindings: function(rf: ɵRenderFlags, ctx: any, elIndex: number) {
if (rf & ɵRenderFlags.Create) {
ɵelementStyling(null, null, null, ctx);
ɵelementHostStyling();
}
if (rf & ɵRenderFlags.Update) {
ɵelementStylingMap(elIndex, null, ctx.getValue(), ctx);
ɵelementStylingApply(elIndex, ctx);
ɵelementHostStylingMap(null, ctx.getValue());
ɵelementHostStylingApply();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,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$.ɵelementHostAttrs(ctx, $c0$);
$r3$.ɵelementHostAttrs($c0$);
}
}
});
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('compiler compliance: bindings', () => {
factory: function HostAttributeComp_Factory(t) { return new (t || HostAttributeComp)(); },
hostBindings: function HostAttributeComp_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementHostAttrs(ctx, $c0$);
$r3$.ɵelementHostAttrs($c0$);
}
Expand All @@ -417,7 +417,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$.ɵelementHostAttrs(ctx, $c1$);
$r3$.ɵelementHostAttrs($c1$);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,14 @@ describe('compiler compliance: styling', () => {
hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementHostAttrs(ctx, $e0_attrs$);
$r3$.ɵelementStyling($e0_classBindings$, $e0_styleBindings$, $r3$.ɵdefaultStyleSanitizer, ctx);
$r3$.ɵelementHostAttrs($e0_attrs$);
$r3$.ɵelementHostStyling($e0_classBindings$, $e0_styleBindings$, $r3$.ɵdefaultStyleSanitizer);
}
if (rf & 2) {
$r3$.ɵelementStylingMap(elIndex, ctx.myClass, ctx.myStyle, ctx);
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myColorProp, null, ctx);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myFooClass, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStylingMap(ctx.myClass, ctx.myStyle);
$r3$.ɵelementHostStyleProp(0, ctx.myColorProp);
$r3$.ɵelementHostClassProp(0, ctx.myFooClass);
$r3$.ɵelementHostStylingApply();
}
},
consts: 0,
Expand Down Expand Up @@ -1046,15 +1046,15 @@ describe('compiler compliance: styling', () => {
hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementStyling(_c0, _c1, $r3$.ɵdefaultStyleSanitizer, ctx);
$r3$.ɵelementHostStyling(_c0, _c1, $r3$.ɵdefaultStyleSanitizer);
}
if (rf & 2) {
$r3$.ɵelementStylingMap(elIndex, ctx.myClasses, ctx.myStyle, ctx);
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myHeightProp, "pt", ctx);
$r3$.ɵelementStyleProp(elIndex, 1, ctx.myWidthProp, null, ctx);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myBarClass, ctx);
$r3$.ɵelementClassProp(elIndex, 1, ctx.myFooClass, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStylingMap(ctx.myClasses, ctx.myStyle);
$r3$.ɵelementHostStyleProp(0, ctx.myHeightProp, "pt");
$r3$.ɵelementHostStyleProp(1, ctx.myWidthProp);
$r3$.ɵelementHostClassProp(0, ctx.myBarClass);
$r3$.ɵelementHostClassProp(1, ctx.myFooClass);
$r3$.ɵelementHostStylingApply();
}
},
consts: 0,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ describe('compiler compliance: styling', () => {
if (rf & 2) {
$r3$.ɵelementStylingMap(0, ctx.myClassExp, ctx.myStyleExp);
$r3$.ɵelementStyleProp(0, 0, ctx.myHeightExp, null, true);
$r3$.ɵelementClassProp(0, 0, ctx.myBarClassExp, null, true);
$r3$.ɵelementClassProp(0, 0, ctx.myBarClassExp, true);
$r3$.ɵelementStylingApply(0);
}
},
Expand All @@ -1127,13 +1127,13 @@ describe('compiler compliance: styling', () => {
hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementStyling(_c0, _c1, $r3$.ɵdefaultStyleSanitizer, ctx);
$r3$.ɵelementHostStyling(_c0, _c1, $r3$.ɵdefaultStyleSanitizer);
}
if (rf & 2) {
$r3$.ɵelementStylingMap(elIndex, ctx.myClassExp, ctx.myStyleExp, ctx);
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myWidthExp, null, ctx, true);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myFooClassExp, ctx, true);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStylingMap(ctx.myClassExp, ctx.myStyleExp);
$r3$.ɵelementHostStyleProp(0, ctx.myWidthExp, null, true);
$r3$.ɵelementHostClassProp(0, ctx.myFooClassExp, true);
$r3$.ɵelementHostStylingApply();
}
},
`;
Expand Down Expand Up @@ -1195,33 +1195,33 @@ describe('compiler compliance: styling', () => {
function ClassDirective_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementStyling(null, null, null, ctx);
$r3$.ɵelementHostStyling();
}
if (rf & 2) {
$r3$.ɵelementStylingMap(elIndex, ctx.myClassMap, null, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStylingMap(ctx.myClassMap);
$r3$.ɵelementHostStylingApply();
}
}
function WidthDirective_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementStyling($widthDir_classes$, $widthDir_styles$, null, ctx);
$r3$.ɵelementHostStyling($widthDir_classes$, $widthDir_styles$);
}
if (rf & 2) {
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myWidth, null, ctx);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myFooClass, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStyleProp(0, ctx.myWidth);
$r3$.ɵelementHostClassProp(0, ctx.myFooClass);
$r3$.ɵelementHostStylingApply();
}
}
function HeightDirective_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵelementStyling($heightDir_classes$, $heightDir_styles$, null, ctx);
$r3$.ɵelementHostStyling($heightDir_classes$, $heightDir_styles$);
}
if (rf & 2) {
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myHeight, null, ctx);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myBarClass, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStyleProp(0, ctx.myHeight);
$r3$.ɵelementHostClassProp(0, ctx.myBarClass);
$r3$.ɵelementHostStylingApply();
}
}
Expand Down Expand Up @@ -1276,14 +1276,14 @@ describe('compiler compliance: styling', () => {
hostBindings: function MyComponent_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵallocHostVars(2);
$r3$.ɵelementHostAttrs(ctx, $_c0$);
$r3$.ɵelementStyling(null, null, $r3$.ɵdefaultStyleSanitizer, ctx);
$r3$.ɵelementHostAttrs($_c0$);
$r3$.ɵelementHostStyling(null, null, $r3$.ɵdefaultStyleSanitizer);
}
if (rf & 2) {
$r3$.ɵelementProperty(elIndex, "id", $r3$.ɵbind(ctx.id), null, true);
$r3$.ɵelementProperty(elIndex, "title", $r3$.ɵbind(ctx.title), null, true);
$r3$.ɵelementStylingMap(elIndex, ctx.myClass, ctx.myStyle, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStylingMap(ctx.myClass, ctx.myStyle);
$r3$.ɵelementHostStylingApply();
}
}
`;
Expand Down Expand Up @@ -1323,14 +1323,14 @@ describe('compiler compliance: styling', () => {
hostBindings: function WidthDirective_HostBindings(rf, ctx, elIndex) {
if (rf & 1) {
$r3$.ɵallocHostVars(2);
$r3$.ɵelementStyling($_c0$, $_c1$, null, ctx);
$r3$.ɵelementHostStyling($_c0$, $_c1$);
}
if (rf & 2) {
$r3$.ɵelementProperty(elIndex, "id", $r3$.ɵbind(ctx.id), null, true);
$r3$.ɵelementProperty(elIndex, "title", $r3$.ɵbind(ctx.title), null, true);
$r3$.ɵelementStyleProp(elIndex, 0, ctx.myWidth, null, ctx);
$r3$.ɵelementClassProp(elIndex, 0, ctx.myFooClass, ctx);
$r3$.ɵelementStylingApply(elIndex, ctx);
$r3$.ɵelementHostStyleProp(0, ctx.myWidth);
$r3$.ɵelementHostClassProp(0, ctx.myFooClass);
$r3$.ɵelementHostStylingApply();
}
}
`;
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,13 +1594,13 @@ describe('ngtsc behavioral tests', () => {
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.ɵelementStyling(_c0, null, null, ctx);
i0.ɵelementHostStyling(_c0);
}
if (rf & 2) {
i0.ɵelementAttribute(elIndex, "hello", i0.ɵbind(ctx.foo));
i0.ɵelementProperty(elIndex, "prop", i0.ɵbind(ctx.bar), null, true);
i0.ɵelementClassProp(elIndex, 0, ctx.someClass, ctx);
i0.ɵelementStylingApply(elIndex, ctx);
i0.ɵelementHostClassProp(0, ctx.someClass);
i0.ɵelementHostStylingApply();
}
}
`;
Expand Down Expand Up @@ -1629,7 +1629,7 @@ describe('ngtsc behavioral tests', () => {
`);
env.driveMain();
const jsContents = env.getContents('test.js');
expect(jsContents).toContain('i0.ɵelementHostAttrs(ctx, ["test", test])');
expect(jsContents).toContain('i0.ɵelementHostAttrs(["test", test])');
});

it('should accept enum values as host bindings', () => {
Expand Down Expand Up @@ -3107,8 +3107,8 @@ describe('ngtsc behavioral tests', () => {
describe('listLazyRoutes()', () => {
// clang-format off
const lazyRouteMatching = (
route: string, fromModulePath: RegExp, fromModuleName: string, toModulePath: RegExp,
toModuleName: string) => {
route: string, fromModulePath: RegExp, fromModuleName: string, toModulePath: RegExp,
toModuleName: string) => {
return {
route,
module: jasmine.objectContaining({
Expand Down
18 changes: 16 additions & 2 deletions packages/compiler/src/render3/r3_identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,29 @@ export class Identifiers {

static elementStyling: o.ExternalReference = {name: 'ɵelementStyling', moduleName: CORE};

static elementHostAttrs: o.ExternalReference = {name: 'ɵelementHostAttrs', moduleName: CORE};

static elementStylingMap: o.ExternalReference = {name: 'ɵelementStylingMap', moduleName: CORE};

static elementStyleProp: o.ExternalReference = {name: 'ɵelementStyleProp', moduleName: CORE};

static elementStylingApply:
o.ExternalReference = {name: 'ɵelementStylingApply', moduleName: CORE};

static elementHostAttrs: o.ExternalReference = {name: 'ɵelementHostAttrs', moduleName: CORE};

static elementHostStyling: o.ExternalReference = {name: 'ɵelementHostStyling', moduleName: CORE};

static elementHostStylingMap:
o.ExternalReference = {name: 'ɵelementHostStylingMap', moduleName: CORE};

static elementHostStyleProp:
o.ExternalReference = {name: 'ɵelementHostStyleProp', moduleName: CORE};

static elementHostClassProp:
o.ExternalReference = {name: 'ɵelementHostClassProp', moduleName: CORE};

static elementHostStylingApply:
o.ExternalReference = {name: 'ɵelementHostStylingApply', moduleName: CORE};

static containerCreate: o.ExternalReference = {name: 'ɵcontainer', moduleName: CORE};

static nextContext: o.ExternalReference = {name: 'ɵnextContext', moduleName: CORE};
Expand Down