feat(ivy): add (event)="handle" syntax support to compiler (#22921)

PR Close #22921
This commit is contained in:
Miško Hevery
2018-03-23 10:55:17 -07:00
committed by Alex Rickabaugh
parent 4290ea4bb9
commit 5266ffe04a
5 changed files with 96 additions and 72 deletions

View File

@ -125,10 +125,6 @@ describe('compiler compliance', () => {
$r3$.ɵe();
$r3$.ɵT(3, '!');
}
ChildComponent.ngComponentDef.h(1, 0);
SomeDirective.ngDirectiveDef.h(2, 0);
$r3$.ɵr(1, 0);
$r3$.ɵr(2, 0);
}
});
`;
@ -266,9 +262,7 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
const $foo$ = $r3$.ɵld(1);
IfDirective.ngDirectiveDef.h(3,2);
$r3$.ɵcR(2);
$r3$.ɵr(3,2);
$r3$.ɵcr();
function MyComponent_IfDirective_Template_2(ctx0: IDENT, cm: IDENT) {
@ -337,8 +331,6 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
$r3$.ɵp(0, 'names', $r3$.ɵb($r3$.ɵf1($e0_ff$, ctx.customName)));
MyComp.ngComponentDef.h(1, 0);
$r3$.ɵr(1, 0);
}
});
`;
@ -417,8 +409,6 @@ describe('compiler compliance', () => {
$r3$.ɵp(
0, 'names',
$r3$.ɵb($r3$.ɵfV($e0_ff$, ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8)));
MyComp.ngComponentDef.h(1, 0);
$r3$.ɵr(1, 0);
}
});
`;
@ -475,8 +465,6 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
$r3$.ɵp(0, 'config', $r3$.ɵb($r3$.ɵf1($e0_ff$, ctx.name)));
ObjectComp.ngComponentDef.h(1, 0);
$r3$.ɵr(1, 0);
}
});
`;
@ -542,8 +530,6 @@ describe('compiler compliance', () => {
0, 'config',
$r3$.ɵb($r3$.ɵf2(
$e0_ff_2$, ctx.name, $r3$.ɵf1($e0_ff_1$, $r3$.ɵf1($e0_ff$, ctx.duration)))));
NestedComp.ngComponentDef.h(1, 0);
$r3$.ɵr(1, 0);
}
});
`;
@ -683,8 +669,6 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
($r3$.ɵqR(($tmp$ = $r3$.ɵld(0))) && (ctx.someDir = $tmp$.first));
SomeDirective.ngDirectiveDef.h(2, 1);
$r3$.ɵr(2, 1);
}
});`;
@ -939,8 +923,6 @@ describe('compiler compliance', () => {
});`;
const SimpleLayoutDefinition = `
const $c1$ = LifecycleComp.ngComponentDef;
static ngComponentDef = $r3$.ɵdefineComponent({
type: SimpleLayout,
selectors: [['simple-layout']],
@ -954,10 +936,6 @@ describe('compiler compliance', () => {
}
$r3$.ɵp(0, 'name', $r3$.ɵb(ctx.name1));
$r3$.ɵp(2, 'name', $r3$.ɵb(ctx.name2));
$c1$.h(1, 0);
$c1$.h(3, 2);
$r3$.ɵr(1, 0);
$r3$.ɵr(3, 2);
}
});`;
@ -1074,9 +1052,7 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
$r3$.ɵp(1, 'forOf', $r3$.ɵb(ctx.items));
ForOfDirective.ngDirectiveDef.h(2, 1);
$r3$.ɵcR(1);
$r3$.ɵr(2, 1);
$r3$.ɵcr();
function MyComponent_ForOfDirective_Template_1(ctx0: IDENT, cm: IDENT) {
@ -1139,7 +1115,6 @@ describe('compiler compliance', () => {
const MyComponentDefinition = `
const $c1$ = [ForOfDirective];
const $c2$ = ForOfDirective.ngDirectiveDef;
static ngComponentDef = $r3$.ɵdefineComponent({
type: MyComponent,
@ -1152,9 +1127,7 @@ describe('compiler compliance', () => {
$r3$.ɵe();
}
$r3$.ɵp(1, 'forOf', $r3$.ɵb(ctx.items));
$c2$.h(2,1);
$r3$.ɵcR(1);
$r3$.ɵr(2, 1);
$r3$.ɵcr();
function MyComponent_ForOfDirective_Template_1(ctx0: IDENT, cm: IDENT) {
@ -1170,10 +1143,8 @@ describe('compiler compliance', () => {
}
const $item$ = ctx0.$implicit;
$r3$.ɵp(4, 'forOf', $r3$.ɵb(IDENT.infos));
$c2$.h(5,4);
$r3$.ɵt(2, $r3$.ɵi1('', IDENT.name, ''));
$r3$.ɵcR(4);
$r3$.ɵr(5, 4);
$r3$.ɵcr();
function MyComponent_ForOfDirective_ForOfDirective_Template_4(

View File

@ -0,0 +1,62 @@
/**
* @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
*/
import {MockDirectory, setup} from '../aot/test_util';
import {compile, expectEmit} from './mock_compile';
/* These tests are codified version of the tests in compiler_canonical_spec.ts. Every
* test in compiler_canonical_spec.ts should have a corresponding test here.
*/
describe('compiler compliance: listen()', () => {
const angularFiles = setup({
compileAngular: true,
compileAnimations: false,
compileCommon: true,
});
it('should create listener instruction on element', () => {
const files = {
app: {
'spec.ts': `
import {Component, NgModule} from '@angular/core';
@Component({
selector: 'my-component',
template: \`<div (click)="onClick($event)"></div>\`
})
export class MyComponent {
onClick(event: any) {}
}
@NgModule({declarations: [MyComponent]})
export class MyModule {}
`
}
};
// The template should look like this (where IDENT is a wild card for an identifier):
const template = `
template: function MyComponent_Template(ctx: $MyComponent$, cm: $boolean$) {
if (cm) {
$r3$.ɵE(0, 'div');
$r3$.ɵL('click', function MyComponent_Template_div_click_listener($event: $any$) {
const $return_value$:$any$ = … ctx.onClick($event) …;
return $return_value$;
});
$r3$.ɵe();
}
}
`;
const result = compile(files, angularFiles);
expectEmit(result.source, template, 'Incorrect template');
});
});