| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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 {AttributeMarker} from '@angular/compiler/src/core'; | 
					
						
							|  |  |  | import {setup} from '@angular/compiler/test/aot/test_util'; | 
					
						
							|  |  |  | import {compile, expectEmit} from './mock_compile'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('compiler compliance: directives', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const angularFiles = setup({ | 
					
						
							|  |  |  |     compileAngular: false, | 
					
						
							|  |  |  |     compileAnimations: false, | 
					
						
							|  |  |  |     compileFakeCore: true, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('matching', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not match directives on i18n attribute', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |                 import {Component, Directive, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @Directive({selector: '[i18n]'}) | 
					
						
							|  |  |  |                 export class I18nDirective {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @Component({selector: 'my-component', template: '<div i18n></div>'}) | 
					
						
							|  |  |  |                 export class MyComponent {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @NgModule({declarations: [I18nDirective, MyComponent]}) | 
					
						
							|  |  |  |                 export class MyModule{}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |             MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 type: MyComponent, | 
					
						
							|  |  |  |                 selectors: [["my-component"]], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |                 decls: 1, | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 vars: 0, | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |                     if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                         $r3$.ɵɵelement(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-11-19 18:48:14 +01:00
										 |  |  |                 }, | 
					
						
							|  |  |  |                 encapsulation: 2 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |             }); | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       const MyComponentFactory = `
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       expectEmit(source, MyComponentFactory, 'Incorrect ChildComponent.ɵfac'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not match directives on i18n-prefixed attributes', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |                 import {Component, Directive, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @Directive({selector: '[i18n]'}) | 
					
						
							|  |  |  |                 export class I18nDirective {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 @Directive({selector: '[i18n-foo]'}) | 
					
						
							|  |  |  |                 export class I18nFooDirective {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 @Directive({selector: '[foo]'}) | 
					
						
							|  |  |  |                 export class FooDirective {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @Component({selector: 'my-component', template: '<div i18n-foo></div>'}) | 
					
						
							|  |  |  |                 export class MyComponent {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 @NgModule({declarations: [I18nDirective, I18nFooDirective, FooDirective, MyComponent]}) | 
					
						
							|  |  |  |                 export class MyModule{}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |             MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 type: MyComponent, | 
					
						
							|  |  |  |                 selectors: [["my-component"]], | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |                 decls: 1, | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 vars: 0, | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                 template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |                     if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |                         $r3$.ɵɵelement(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-11-19 18:48:14 +01:00
										 |  |  |                 }, | 
					
						
							|  |  |  |                 encapsulation: 2 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |             }); | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       const MyComponentFactory = `
 | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |         MyComponent.ɵfac = function MyComponent_Factory(t) { return new (t || MyComponent)(); }; | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2019-10-11 14:18:45 -07:00
										 |  |  |       expectEmit(source, MyComponentFactory, 'Incorrect ChildComponent.ɵfac'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match directives on element bindings', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             import {Component, Directive, Input, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Directive({selector: '[someDirective]'}) | 
					
						
							|  |  |  |             export class SomeDirective { | 
					
						
							|  |  |  |                 @Input() someDirective; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Component({selector: 'my-component', template: '<div [someDirective]="true"></div>'}) | 
					
						
							|  |  |  |             export class MyComponent {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @NgModule({declarations: [SomeDirective, MyComponent]}) | 
					
						
							|  |  |  |             export class MyModule{} | 
					
						
							|  |  |  |           `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |           MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |               … | 
					
						
							|  |  |  |               consts: [[${AttributeMarker.Bindings}, "someDirective"]], | 
					
						
							|  |  |  |               template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |                   if (rf & 1) { | 
					
						
							|  |  |  |                       $r3$.ɵɵelement(0, "div", 0); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                   if (rf & 2) { | 
					
						
							|  |  |  |                       $r3$.ɵɵproperty("someDirective", true); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               … | 
					
						
							|  |  |  |               directives: [SomeDirective], | 
					
						
							|  |  |  |               encapsulation: 2 | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |     it('should match directives on ng-templates', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Component, Directive, NgModule, TemplateRef} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |                 selector: 'ng-template[directiveA]' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class DirectiveA { | 
					
						
							|  |  |  |                 constructor(public templateRef: TemplateRef<any>) {} | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'my-component', | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <ng-template directiveA>Some content</ng-template> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [DirectiveA, MyComponent]}) | 
					
						
							|  |  |  |             export class MyModule{} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |         function MyComponent_ng_template_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $r3$.ɵɵtext(0, "Some content"); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           consts: [["directiveA", ""]], | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |               $r3$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 1, 0, "ng-template", 0); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           directives: [DirectiveA], | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(result.source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match directives on ng-container', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, Directive, NgModule, TemplateRef} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Directive({ | 
					
						
							|  |  |  |                   selector: 'ng-container[directiveA]' | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class DirectiveA { | 
					
						
							|  |  |  |                   constructor(public templateRef: TemplateRef<any>) {} | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <ng-container *ngIf="showing" directiveA>Some content</ng-container> | 
					
						
							|  |  |  |                 \`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [DirectiveA, MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule{} | 
					
						
							|  |  |  |             `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |         function MyComponent_ng_container_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             $r3$.ɵɵelementContainerStart(0, 1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $r3$.ɵɵtext(1, "Some content"); | 
					
						
							|  |  |  |             $r3$.ɵɵelementContainerEnd(); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           consts: [["directiveA", "", ${AttributeMarker.Template}, "ngIf"], ["directiveA", ""]], | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |               $r3$.ɵɵtemplate(0, MyComponent_ng_container_0_Template, 2, 0, "ng-container", 0); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |               $r3$.ɵɵproperty("ngIf", ctx.showing); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           directives: [DirectiveA], | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(result.source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-12-12 15:23:12 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     it('should match directives on ng-template bindings', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             import {Component, Directive, Input, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Directive({selector: '[someDirective]'}) | 
					
						
							|  |  |  |             export class SomeDirective { | 
					
						
							|  |  |  |                 @Input() someDirective; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Component({selector: 'my-component', template: '<ng-template [someDirective]="true"></ng-template>'}) | 
					
						
							|  |  |  |             export class MyComponent {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @NgModule({declarations: [SomeDirective, MyComponent]}) | 
					
						
							|  |  |  |             export class MyModule{} | 
					
						
							|  |  |  |           `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             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); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (rf & 2) { | 
					
						
							|  |  |  |                     $r3$.ɵɵproperty("someDirective", true); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             directives: [SomeDirective], | 
					
						
							|  |  |  |             encapsulation: 2 | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     `;
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match structural directives', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             import {Component, Directive, Input, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Directive({selector: '[someDirective]'}) | 
					
						
							|  |  |  |             export class SomeDirective { | 
					
						
							|  |  |  |                 @Input() someDirective; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Component({selector: 'my-component', template: '<div *someDirective></div>'}) | 
					
						
							|  |  |  |             export class MyComponent {} | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @NgModule({declarations: [SomeDirective, MyComponent]}) | 
					
						
							|  |  |  |             export class MyModule{} | 
					
						
							|  |  |  |           `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |           MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |               … | 
					
						
							|  |  |  |               consts: [[${AttributeMarker.Template}, "someDirective"]], | 
					
						
							|  |  |  |               template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |                   if (rf & 1) { | 
					
						
							|  |  |  |                       $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", 0); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               … | 
					
						
							|  |  |  |               directives: [SomeDirective], | 
					
						
							|  |  |  |               encapsulation: 2 | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match directives on element outputs', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             import {Component, Directive, Output, EventEmitter, NgModule} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Directive({selector: '[someDirective]'}) | 
					
						
							|  |  |  |             export class SomeDirective { | 
					
						
							|  |  |  |                 @Output() someDirective = new EventEmitter(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @Component({selector: 'my-component', template: '<div (someDirective)="noop()"></div>'}) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |                 noop() {} | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             @NgModule({declarations: [SomeDirective, MyComponent]}) | 
					
						
							|  |  |  |             export class MyModule{} | 
					
						
							|  |  |  |           `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // MyComponent definition should be:
 | 
					
						
							|  |  |  |       const MyComponentDefinition = `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         MyComponent.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             consts: [[${AttributeMarker.Bindings}, "someDirective"]], | 
					
						
							|  |  |  |             template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |                 if (rf & 1) { | 
					
						
							|  |  |  |                     $r3$.ɵɵelementStart(0, "div", 0); | 
					
						
							|  |  |  |                     $r3$.ɵɵlistener("someDirective", function MyComponent_Template_div_someDirective_0_listener($event) { return ctx.noop(); }); | 
					
						
							|  |  |  |                     $r3$.ɵɵelementEnd(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             directives: [SomeDirective], | 
					
						
							|  |  |  |             encapsulation: 2 | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     `;
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |       expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ɵcmp'); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-11-19 18:48:14 +01:00
										 |  |  | }); |