feat(ivy): generate ɵɵproperty instructions (#29946)

PR Close #29946
This commit is contained in:
Ben Lesh
2019-04-16 17:17:12 -07:00
parent a181e8e7d8
commit 10217bb3bc
22 changed files with 323 additions and 187 deletions

View File

@ -317,7 +317,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "id", $r3$.ɵɵbind(ctx.id));
$r3$.ɵɵproperty("id", ctx.id);
}
}
`;
@ -354,6 +354,14 @@ describe('compiler compliance', () => {
}
};
///////////////
// TODO(FW-1273): The code generated below is adding extra parens, and we need to stop
// generating those.
//
// For example:
// `$r3$.ɵɵproperty("ternary", (ctx.cond ? $r3$.ɵɵpureFunction1(8, $c0$, ctx.a): $c1$));`
///////////////
const $e0_attrs$ = [];
const factory =
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
@ -365,10 +373,10 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ternary", $r3$.ɵɵbind((ctx.cond ? $r3$.ɵɵpureFunction1(8, $c0$, ctx.a): $c1$)));
$r3$.ɵɵelementProperty(0, "pipe", $r3$.ɵɵbind($r3$.ɵɵpipeBind3(1, 4, ctx.value, 1, 2)));
$r3$.ɵɵelementProperty(0, "and", $r3$.ɵɵbind((ctx.cond && $r3$.ɵɵpureFunction1(10, $c0$, ctx.b))));
$r3$.ɵɵelementProperty(0, "or", $r3$.ɵɵbind((ctx.cond || $r3$.ɵɵpureFunction1(12, $c0$, ctx.c))));
$r3$.ɵɵproperty("ternary", (ctx.cond ? $r3$.ɵɵpureFunction1(8, $c0$, ctx.a): $c1$));
$r3$.ɵɵproperty("pipe", $r3$.ɵɵpipeBind3(1, 4, ctx.value, 1, 2));
$r3$.ɵɵproperty("and", (ctx.cond && $r3$.ɵɵpureFunction1(10, $c0$, ctx.b)));
$r3$.ɵɵproperty("or", (ctx.cond || $r3$.ɵɵpureFunction1(12, $c0$, ctx.c)));
}
}
`;
@ -880,7 +888,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "names", $r3$.ɵɵbind($r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.customName)));
$r3$.ɵɵproperty("names", $r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.customName));
}
},
directives: [MyComp],
@ -963,9 +971,8 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(
0, "names",
$r3$.ɵɵbind($r3$.ɵɵpureFunctionV(1, $e0_ff$, [ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8])));
$r3$.ɵɵproperty("names",
$r3$.ɵɵpureFunctionV(1, $e0_ff$, [ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8]));
}
},
directives: [MyComp],
@ -1028,7 +1035,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "config", $r3$.ɵɵbind($r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.name)));
$r3$.ɵɵproperty("config", $r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.name));
}
},
directives: [ObjectComp],
@ -1097,9 +1104,9 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(
0, "config",
$r3$.ɵɵbind($r3$.ɵɵpureFunction2(5, $e0_ff_2$, ctx.name, $r3$.ɵɵpureFunction1(3, $e0_ff_1$, $r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.duration)))));
$r3$.ɵɵproperty(
"config",
$r3$.ɵɵpureFunction2(5, $e0_ff_2$, ctx.name, $r3$.ɵɵpureFunction1(3, $e0_ff_1$, $r3$.ɵɵpureFunction1(1, $e0_ff$, ctx.duration))));
}
},
directives: [NestedComp],
@ -1261,9 +1268,9 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
}
}
`;
@ -2350,7 +2357,7 @@ describe('compiler compliance', () => {
if (rf & 2) {
const $app$ = $i0$.ɵɵnextContext();
$r3$.ɵɵselect(3);
$i0$.ɵɵelementProperty(3, "ngIf", $i0$.ɵɵbind($app$.showing));
$i0$.ɵɵproperty("ngIf", $app$.showing);
}
}
@ -2361,7 +2368,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngForOf", $i0$.ɵɵbind(ctx.items));
$i0$.ɵɵproperty("ngForOf", ctx.items);
}
}`;
@ -2442,9 +2449,9 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "name", $r3$.ɵɵbind(ctx.name1));
$r3$.ɵɵproperty("name", ctx.name1);
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "name", $r3$.ɵɵbind(ctx.name2));
$r3$.ɵɵproperty("name", ctx.name2);
}
},
directives: [LifecycleComp],
@ -2576,7 +2583,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1,"forOf",$r3$.ɵɵbind(ctx.items));
$r3$.ɵɵproperty("forOf", ctx.items);
}
},
directives: function() { return [ForOfDirective]; },
@ -2658,7 +2665,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "forOf", $r3$.ɵɵbind(ctx.items));
$r3$.ɵɵproperty("forOf", ctx.items);
}
},
directives: function() { return [ForOfDirective]; },
@ -2743,7 +2750,7 @@ describe('compiler compliance', () => {
$r3$.ɵɵselect(2);
$r3$.ɵɵtextBinding(2, $r3$.ɵɵinterpolation1("", IDENT.name, ""));
$r3$.ɵɵselect(4);
$r3$.ɵɵelementProperty(4, "forOf", $r3$.ɵɵbind(IDENT.infos));
$r3$.ɵɵproperty("forOf", IDENT.infos);
}
}
@ -2762,7 +2769,7 @@ describe('compiler compliance', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "forOf", $r3$.ɵɵbind(ctx.items));
$r3$.ɵɵproperty("forOf", ctx.items);
}
},
directives: function () { return [ForOfDirective]; },

View File

@ -82,7 +82,7 @@ describe('compiler compliance: bindings', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "title", $i0$.ɵɵbind($ctx$.title));
$i0$.ɵɵproperty("title", $ctx$.title);
}
}`;
const result = compile(files, angularFiles);
@ -174,7 +174,7 @@ describe('compiler compliance: bindings', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "for", $i0$.ɵɵbind(ctx.forValue));
$i0$.ɵɵproperty("for", ctx.forValue);
}
}`;

View File

@ -140,7 +140,7 @@ describe('compiler compliance: directives', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "someDirective", $r3$.ɵɵbind(true));
$r3$.ɵɵproperty("someDirective", true);
}
},
@ -255,7 +255,7 @@ describe('compiler compliance: directives', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngIf", $r3$.ɵɵbind(ctx.showing));
$r3$.ɵɵproperty("ngIf", ctx.showing);
}
},
@ -303,7 +303,7 @@ describe('compiler compliance: directives', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "someDirective", $r3$.ɵɵbind(true));
$r3$.ɵɵproperty("someDirective", true);
}
},

View File

@ -580,7 +580,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngForOf", $r3$.ɵɵbind(ctx.items));
$r3$.ɵɵproperty("ngForOf", ctx.items);
}
}
`;
@ -767,7 +767,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngForOf", $r3$.ɵɵbind(ctx.items));
$r3$.ɵɵproperty("ngForOf", ctx.items);
}
}
`;
@ -1429,7 +1429,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
}
}
`;
@ -1491,9 +1491,9 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
}
}
`;
@ -1558,7 +1558,7 @@ describe('i18n support in the view compiler', () => {
if (rf & 2) {
const $ctx_r0$ = $r3$.ɵɵnextContext();
$r3$.ɵɵselect(4);
$r3$.ɵɵelementProperty(4, "ngIf", $r3$.ɵɵbind($ctx_r0$.exists));
$r3$.ɵɵproperty("ngIf", $ctx_r0$.exists);
$r3$.ɵɵi18nExp($r3$.ɵɵbind($ctx_r0$.valueA));
$r3$.ɵɵi18nExp($r3$.ɵɵbind($r3$.ɵɵpipeBind1(3, 3, $ctx_r0$.valueB)));
$r3$.ɵɵi18nApply(0);
@ -1628,9 +1628,9 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵselect(3);
$r3$.ɵɵelementProperty(3, "ngIf", $r3$.ɵɵbind(!ctx.visible));
$r3$.ɵɵproperty("ngIf", !ctx.visible);
}
}
`;
@ -1686,7 +1686,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
}
}
`;
@ -2597,9 +2597,9 @@ describe('i18n support in the view compiler', () => {
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.gender));
$r3$.ɵɵi18nApply(1);
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵselect(3);
$r3$.ɵɵelementProperty(3, "ngIf", $r3$.ɵɵbind(ctx.available));
$r3$.ɵɵproperty("ngIf", ctx.available);
}
}
`;
@ -2935,7 +2935,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(3);
$r3$.ɵɵelementProperty(3, "ngIf", $r3$.ɵɵbind(ctx.visible));
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.gender));
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.gender));
$r3$.ɵɵi18nApply(1);
@ -3075,7 +3075,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.ageVisible));
$r3$.ɵɵproperty("ngIf", ctx.ageVisible);
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.gender));
$r3$.ɵɵi18nApply(1);
}
@ -3174,7 +3174,7 @@ describe('i18n support in the view compiler', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "ngIf", $r3$.ɵɵbind(ctx.ageVisible));
$r3$.ɵɵproperty("ngIf", ctx.ageVisible);
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.gender));
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.weight));
$r3$.ɵɵi18nExp($r3$.ɵɵbind(ctx.height));

View File

@ -164,7 +164,7 @@ describe('compiler compliance: listen()', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngIf", $i0$.ɵɵbind(ctx.showing));
$i0$.ɵɵproperty("ngIf", ctx.showing);
}
}
`;

View File

@ -147,8 +147,8 @@ describe('r3_view_compiler', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "@attr", …);
$i0$.ɵɵelementProperty(0, "@binding", …);
$i0$.ɵɵproperty("@attr", …);
$i0$.ɵɵproperty("@binding", …);
}
}`;
const result = compile(files, angularFiles);
@ -179,7 +179,7 @@ describe('r3_view_compiler', () => {
$i0$.ɵɵelementStart(0, "div");
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "@mySelector", …);
$i0$.ɵɵproperty("@mySelector", …);
}
}`;
const result = compile(files, angularFiles);

View File

@ -227,11 +227,11 @@ describe('compiler compliance: styling', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "@foo", $r3$.ɵɵbind(ctx.exp));
$r3$.ɵɵproperty("@foo", ctx.exp);
$r3$.ɵɵselect(1);
$r3$.ɵɵelementProperty(1, "@bar", $r3$.ɵɵbind(undefined));
$r3$.ɵɵproperty("@bar", undefined);
$r3$.ɵɵselect(2);
$r3$.ɵɵelementProperty(2, "@baz", $r3$.ɵɵbind(undefined));
$r3$.ɵɵproperty("@baz", undefined);
}
},
encapsulation: 2
@ -289,7 +289,7 @@ describe('compiler compliance: styling', () => {
$r3$.ɵɵelementEnd();
} if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "@myAnimation", $r3$.ɵɵbind(ctx.exp));
$r3$.ɵɵproperty("@myAnimation", ctx.exp);
}
},
encapsulation: 2,

View File

@ -76,7 +76,7 @@ describe('compiler compliance: template', () => {
const $outer1$ = $i0$.ɵɵnextContext().$implicit;
const $myComp1$ = $i0$.ɵɵnextContext();
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "title", $i0$.ɵɵbind($myComp1$.format($outer1$, $middle1$, $inner1$, $myComp1$.component)));
$i0$.ɵɵproperty("title", $myComp1$.format($outer1$, $middle1$, $inner1$, $myComp1$.component));
$r3$.ɵɵselect(1);
$i0$.ɵɵtextBinding(1, $i0$.ɵɵinterpolation1(" ", $myComp1$.format($outer1$, $middle1$, $inner1$, $myComp1$.component), " "));
}
@ -91,7 +91,7 @@ describe('compiler compliance: template', () => {
if (rf & 2) {
const $myComp2$ = $i0$.ɵɵnextContext(2);
$r3$.ɵɵselect(1);
$i0$.ɵɵelementProperty(1, "ngForOf", $i0$.ɵɵbind($myComp2$.items));
$i0$.ɵɵproperty("ngForOf", $myComp2$.items);
}
}
@ -104,7 +104,7 @@ describe('compiler compliance: template', () => {
if (rf & 2) {
const $outer2$ = ctx.$implicit;
$r3$.ɵɵselect(1);
$i0$.ɵɵelementProperty(1, "ngForOf", $i0$.ɵɵbind($outer2$.items));
$i0$.ɵɵproperty("ngForOf", $outer2$.items);
}
}
// ...
@ -114,7 +114,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngForOf", $i0$.ɵɵbind(ctx.items));
$i0$.ɵɵproperty("ngForOf", ctx.items);
}
}`;
@ -171,7 +171,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$r3$.ɵɵselect(0);
$r3$.ɵɵelementProperty(0, "ngForOf", $r3$.ɵɵbind(ctx._data));
$r3$.ɵɵproperty("ngForOf", ctx._data);
}
}
`;
@ -225,7 +225,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngForOf", $i0$.ɵɵbind(ctx.items));
$i0$.ɵɵproperty("ngForOf", ctx.items);
}
}`;
@ -285,7 +285,7 @@ describe('compiler compliance: template', () => {
if (rf & 2) {
const $app$ = $i0$.ɵɵnextContext();
$r3$.ɵɵselect(1);
$i0$.ɵɵelementProperty(1, "ngIf", $i0$.ɵɵbind($app$.showing));
$i0$.ɵɵproperty("ngIf", $app$.showing);
}
}
@ -296,7 +296,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngForOf", $i0$.ɵɵbind(ctx.items));
$i0$.ɵɵproperty("ngForOf", ctx.items);
}
}`;
@ -356,7 +356,7 @@ describe('compiler compliance: template', () => {
if (rf & 2) {
const $middle$ = ctx.$implicit;
$r3$.ɵɵselect(1);
$i0$.ɵɵelementProperty(1, "ngForOf", $i0$.ɵɵbind($middle$.items));
$i0$.ɵɵproperty("ngForOf", $middle$.items);
}
}
@ -369,7 +369,7 @@ describe('compiler compliance: template', () => {
if (rf & 2) {
const $outer$ = ctx.$implicit;
$r3$.ɵɵselect(1);
$i0$.ɵɵelementProperty(1, "ngForOf", $i0$.ɵɵbind($outer$.items));
$i0$.ɵɵproperty("ngForOf", $outer$.items);
}
}
// ...
@ -379,7 +379,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngForOf", $i0$.ɵɵbind(ctx.items));
$i0$.ɵɵproperty("ngForOf", ctx.items);
}
}`;
@ -426,7 +426,7 @@ describe('compiler compliance: template', () => {
}
if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "boundAttr", $i0$.ɵɵbind(ctx.b));
$i0$.ɵɵproperty("boundAttr", ctx.b);
}
}`;
@ -669,7 +669,7 @@ describe('compiler compliance: template', () => {
$i0$.ɵɵpipe(1, "pipe");
} if (rf & 2) {
$i0$.ɵɵselect(0);
$i0$.ɵɵelementProperty(0, "ngIf", $i0$.ɵɵbind($i0$.ɵɵpipeBind1(1, 1, ctx.val)));
$i0$.ɵɵproperty("ngIf", $i0$.ɵɵpipeBind1(1, 1, ctx.val));
}
}`;

View File

@ -104,13 +104,14 @@ describe('template source-mapping', () => {
});
expect(mappings).toContain({
source: '[attr]="name"',
generated: 'i0.ɵɵelementProperty(0, "attr", i0.ɵɵbind(ctx.name))',
generated: 'i0.ɵɵproperty("attr", ctx.name)',
sourceUrl: '../test.ts'
});
});
it('should map a complex input binding expression', () => {
const mappings = compileAndMap('<div [attr]="greeting + name"></div>');
expect(mappings).toContain({
source: '<div [attr]="greeting + name"></div>',
generated: 'i0.ɵɵelement(0, "div", _c0)',
@ -118,7 +119,7 @@ describe('template source-mapping', () => {
});
expect(mappings).toContain({
source: '[attr]="greeting + name"',
generated: 'i0.ɵɵelementProperty(0, "attr", i0.ɵɵbind((ctx.greeting + ctx.name)))',
generated: 'i0.ɵɵproperty("attr", (ctx.greeting + ctx.name))',
sourceUrl: '../test.ts'
});
});
@ -132,7 +133,7 @@ describe('template source-mapping', () => {
});
expect(mappings).toContain({
source: 'bind-attr="name"',
generated: 'i0.ɵɵelementProperty(0, "attr", i0.ɵɵbind(ctx.name))',
generated: 'i0.ɵɵproperty("attr", ctx.name)',
sourceUrl: '../test.ts'
});
});