| 
									
										
										
										
											2018-04-03 15:46:16 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  | import {AttributeMarker} from '@angular/compiler/src/core'; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | import {setup} from '@angular/compiler/test/aot/test_util'; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  | import {compile, expectEmit} from './mock_compile'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 11:38:06 -07:00
										 |  |  | describe('compiler compliance: template', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |   const angularFiles = setup({ | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |     compileAngular: false, | 
					
						
							|  |  |  |     compileFakeCore: true, | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |     compileAnimations: false, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 15:29:42 -07:00
										 |  |  |   it('should correctly bind to context in nested template', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <ul *ngFor="let outer of items"> | 
					
						
							|  |  |  |                     <li *ngFor="let middle of outer.items"> | 
					
						
							| 
									
										
										
										
											2018-04-18 16:23:49 -07:00
										 |  |  |                       <div *ngFor="let inner of items" | 
					
						
							| 
									
										
										
										
											2018-04-05 11:38:06 -07:00
										 |  |  |                            (click)="onClick(outer, middle, inner)" | 
					
						
							|  |  |  |                            [title]="format(outer, middle, inner, component)" | 
					
						
							|  |  |  |                            > | 
					
						
							|  |  |  |                         {{format(outer, middle, inner, component)}} | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |                       </div> | 
					
						
							|  |  |  |                     </li> | 
					
						
							|  |  |  |                   </ul>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent { | 
					
						
							| 
									
										
										
										
											2018-04-05 11:38:06 -07:00
										 |  |  |                 component = this; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |                 format(outer: any, middle: any, inner: any) { } | 
					
						
							|  |  |  |                 onClick(outer: any, middle: any, inner: any) { } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The template should look like this (where IDENT is a wild card for an identifier):
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $c0$ = ["ngFor", "", ${AttributeMarker.SelectOnly}, "ngForOf"]; | 
					
						
							|  |  |  |       const $e0_attrs$ = [${AttributeMarker.SelectOnly}, "title", "click"]; | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_ul_li_div_Template_1(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $s$ = $i0$.ɵgetCurrentView(); | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |           $i0$.ɵelementStart(0, "div", $e0_attrs$); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵlistener("click", function MyComponent_ul_li_div_Template_1_div_click_listener($event){ | 
					
						
							|  |  |  |             $i0$.ɵrestoreView($s$); | 
					
						
							| 
									
										
										
										
											2018-07-30 19:43:56 -07:00
										 |  |  |             const $inner$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |             const $middle$ = $i0$.ɵnextContext().$implicit; | 
					
						
							|  |  |  |             const $outer$ = $i0$.ɵnextContext().$implicit; | 
					
						
							|  |  |  |             const $myComp$ = $i0$.ɵnextContext(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |             return $myComp$.onClick($outer$, $middle$, $inner$); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |           }); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |           const $inner1$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $middle1$ = $i0$.ɵnextContext().$implicit; | 
					
						
							|  |  |  |           const $outer1$ = $i0$.ɵnextContext().$implicit; | 
					
						
							|  |  |  |           const $myComp1$ = $i0$.ɵnextContext(); | 
					
						
							|  |  |  |           $i0$.ɵelementProperty(0, "title", $i0$.ɵbind($myComp1$.format($outer1$, $middle1$, $inner1$, $myComp1$.component))); | 
					
						
							|  |  |  |           $i0$.ɵtextBinding(1, $i0$.ɵinterpolation1(" ", $myComp1$.format($outer1$, $middle1$, $inner1$, $myComp1$.component), " ")); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_ul_li_Template_1(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "li"); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(1, MyComponent_ul_li_div_Template_1, 2, 2, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $myComp2$ = $i0$.ɵnextContext(2); | 
					
						
							|  |  |  |           $i0$.ɵelementProperty(1, "ngForOf", $i0$.ɵbind($myComp2$.items)); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_ul_Template_0(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "ul"); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(1, MyComponent_ul_li_Template_1, 2, 1, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |           const $outer2$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(1, "ngForOf", $i0$.ɵbind($outer2$.items)); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-04-18 16:23:49 -07:00
										 |  |  |       // ...
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       template:function MyComponent_Template(rf, ctx){ | 
					
						
							| 
									
										
										
										
											2018-04-18 16:23:49 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(0, MyComponent_ul_Template_0, 2, 1, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:20 -07:00
										 |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(0, "ngForOf", $i0$.ɵbind(ctx.items)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support ngFor context variables', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                     <span *ngFor="let item of items; index as i"> | 
					
						
							|  |  |  |                       {{ i }} - {{ item }} | 
					
						
							|  |  |  |                     </span>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $c0$ = ["ngFor", "", ${AttributeMarker.SelectOnly}, "ngForOf"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_span_Template_0(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "span"); | 
					
						
							|  |  |  |           $i0$.ɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							|  |  |  |           const $item$ = ctx.$implicit; | 
					
						
							|  |  |  |           const $i$ = ctx.index; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵtextBinding(1, $i0$.ɵinterpolation2(" ", $i$, " - ", $item$, " ")); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  |       template:function MyComponent_Template(rf, ctx){ | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |           $i0$.ɵtemplate(0, MyComponent_span_Template_0, 2, 2, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(0, "ngForOf", $i0$.ɵbind(ctx.items)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should support ngFor context variables in parent views', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <div *ngFor="let item of items; index as i"> | 
					
						
							|  |  |  |                       <span *ngIf="showing"> | 
					
						
							|  |  |  |                         {{ i }} - {{ item }} | 
					
						
							|  |  |  |                       </span> | 
					
						
							|  |  |  |                   </div>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $c0$ = ["ngFor", "", ${AttributeMarker.SelectOnly}, "ngForOf"]; | 
					
						
							|  |  |  |       const $c1$ = [${AttributeMarker.SelectOnly}, "ngIf"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_div_span_Template_1(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "span"); | 
					
						
							|  |  |  |           $i0$.ɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $div$ = $i0$.ɵnextContext(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |           const $i$ = $div$.index; | 
					
						
							|  |  |  |           const $item$ = $div$.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵtextBinding(1, $i0$.ɵinterpolation2(" ", $i$, " - ", $item$, " ")); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_div_Template_0(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |           $i0$.ɵtemplate(1, MyComponent_div_span_Template_1, 2, 2, null, $c1$); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $app$ = $i0$.ɵnextContext(); | 
					
						
							|  |  |  |           $i0$.ɵelementProperty(1, "ngIf", $i0$.ɵbind($app$.showing)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       // ...
 | 
					
						
							|  |  |  |       template:function MyComponent_Template(rf, ctx){ | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(0, MyComponent_div_Template_0, 2, 1, null, $c0$); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(0, "ngForOf", $i0$.ɵbind(ctx.items)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should correctly skip contexts as needed', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <div *ngFor="let outer of items"> | 
					
						
							|  |  |  |                     <div *ngFor="let middle of outer.items"> | 
					
						
							|  |  |  |                       <div *ngFor="let inner of middle.items"> | 
					
						
							|  |  |  |                         {{ middle.value }} - {{ name }} | 
					
						
							|  |  |  |                       </div> | 
					
						
							|  |  |  |                     </div> | 
					
						
							|  |  |  |                   </div>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The template should look like this (where IDENT is a wild card for an identifier):
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $c0$ = ["ngFor", "", ${AttributeMarker.SelectOnly}, "ngForOf"]; | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_div_div_div_Template_1(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           const $middle$ = $i0$.ɵnextContext().$implicit; | 
					
						
							|  |  |  |           const $myComp$ = $i0$.ɵnextContext(2); | 
					
						
							|  |  |  |           $i0$.ɵtextBinding(1, $i0$.ɵinterpolation2(" ", $middle$.value, " - ", $myComp$.name, " ")); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_div_div_Template_1(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |           $i0$.ɵtemplate(1, MyComponent_div_div_div_Template_1, 2, 2, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							|  |  |  |           const $middle$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(1, "ngForOf", $i0$.ɵbind($middle$.items)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |       function MyComponent_div_Template_0(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementStart(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(1, MyComponent_div_div_Template_1, 2, 1, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							|  |  |  |           const $outer$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(1, "ngForOf", $i0$.ɵbind($outer$.items)); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  |       template:function MyComponent_Template(rf, ctx){ | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(0, MyComponent_div_Template_0, 2, 1, null, _c0); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(0, "ngForOf", $i0$.ɵbind(ctx.items)); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:20 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |   it('should support <ng-template>', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <ng-template [boundAttr]="b" attr="l"> | 
					
						
							|  |  |  |                     some-content | 
					
						
							|  |  |  |                   </ng-template>\` | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-03 14:23:29 -07:00
										 |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $c0$ = ["attr", "l", ${AttributeMarker.SelectOnly}, "boundAttr"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       function Template_0(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵtext(0, " some-content "); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           $i0$.ɵtemplate(0, Template_0, 1, 0, null, $c0$); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:48:58 -07:00
										 |  |  |           $i0$.ɵelementProperty(0, "boundAttr", $i0$.ɵbind(ctx.b)); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should support local refs on <ng-template>', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: '<ng-template #foo>some-content</ng-template>'; | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       const $t0_refs$ = ["foo", ""]; | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       function Template_0(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							|  |  |  |           $i0$.ɵtext(0, "some-content"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |           $i0$.ɵtemplate(0, Template_0, 1, 0, null, null, $t0_refs$, $i0$.ɵtemplateRefExtractor); | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should support directive outputs on <ng-template>', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: '<ng-template (outDirective)="$event.doSth()"></ng-template>'; | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							|  |  |  |       const $t0_attrs$ = [${AttributeMarker.SelectOnly}, "outDirective"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       function Template_0(rf, ctx) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							|  |  |  |           $i0$.ɵtemplate(0, Template_0, 0, 0, null, $t0_attrs$); | 
					
						
							|  |  |  |           $i0$.ɵlistener("outDirective", function MyComponent_Template_ng_template_outDirective_listener($event) { return $event.doSth(); }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:20 -07:00
										 |  |  | }); |