| 
									
										
										
										
											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 = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = [${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							|  |  |  |       const $c1$ = [${AttributeMarker.Bindings}, "title", "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							|  |  |  |       const $c2$ = [${AttributeMarker.Bindings}, "title", "click"]; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ul_0_li_1_div_1_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $s$ = $i0$.ɵɵgetCurrentView(); | 
					
						
							|  |  |  |           $i0$.ɵɵelementStart(0, "div", $c2$); | 
					
						
							|  |  |  |           $i0$.ɵɵlistener("click", function MyComponent_ul_0_li_1_div_1_Template_div_click_0_listener($event){ | 
					
						
							|  |  |  |             $i0$.ɵɵrestoreView($s$); | 
					
						
							| 
									
										
										
										
											2018-07-30 19:43:56 -07:00
										 |  |  |             const $inner$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -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
										 |  |  |           }); | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -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; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $middle1$ = $i0$.ɵɵnextContext().$implicit; | 
					
						
							|  |  |  |           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))); | 
					
						
							|  |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ul_0_li_1_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "li"); | 
					
						
							|  |  |  |           $i0$.ɵɵtemplate(1, MyComponent_ul_0_li_1_div_1_Template, 2, 2, "div", $c1$); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $myComp2$ = $i0$.ɵɵnextContext(2); | 
					
						
							|  |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ul_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-18 01:59:49 +00:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "ul"); | 
					
						
							|  |  |  |           $i0$.ɵɵtemplate(1, MyComponent_ul_0_li_1_Template, 2, 1, "li", $c0$); | 
					
						
							|  |  |  |           $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; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_ul_0_Template, 2, 1, "ul", $c0$); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:46:16 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:20 -07:00
										 |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $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'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |   it('should correctly bind to context in nested template with many bindings', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <div *ngFor="let d of _data; let i = index" (click)="_handleClick(d, i)"></div> | 
					
						
							|  |  |  |                 \`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent { | 
					
						
							|  |  |  |                 _data = [1,2,3]; | 
					
						
							|  |  |  |                 _handleClick(d: any, i: any) {} | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |         const $t0_attrs$ = [${AttributeMarker.Bindings}, "click", ${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |         const $e_attrs$ = [${AttributeMarker.Bindings}, "click"]; | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         function MyComponent_div_0_Template(rf, ctx) { | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |             const $s$ = $r3$.ɵɵgetCurrentView(); | 
					
						
							|  |  |  |             $r3$.ɵɵelementStart(0, "div", $e_attrs$); | 
					
						
							|  |  |  |             $r3$.ɵɵlistener("click", function MyComponent_div_0_Template_div_click_0_listener($event) { | 
					
						
							|  |  |  |               $r3$.ɵɵrestoreView($s$); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |               const $d$ = ctx.$implicit; | 
					
						
							|  |  |  |               const $i$ = ctx.index; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |               const $comp$ = $r3$.ɵɵnextContext(); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |               return $comp$._handleClick($d$, $i$); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |             $r3$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // ...
 | 
					
						
							|  |  |  |         template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |             $r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", $t0_attrs$); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |             $r3$.ɵɵselect(0); | 
					
						
							|  |  |  |             $r3$.ɵɵelementProperty(0, "ngForOf", $r3$.ɵɵbind(ctx._data)); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:35:30 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |   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 = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = [${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_span_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -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; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $i0$.ɵɵtextBinding(1, $i0$.ɵɵinterpolation2(" ", $i$, " - ", $item$, " ")); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  |       template:function MyComponent_Template(rf, ctx){ | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_span_0_Template, 2, 2, "span", _c0); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $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 = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = [${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							|  |  |  |       const $c1$ = [${AttributeMarker.Template}, "ngIf"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_div_0_span_1_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "span"); | 
					
						
							|  |  |  |           $i0$.ɵɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $div$ = $i0$.ɵɵnextContext(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |           const $i$ = $div$.index; | 
					
						
							|  |  |  |           const $item$ = $div$.$implicit; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $i0$.ɵɵtextBinding(1, $i0$.ɵɵinterpolation2(" ", $i$, " - ", $item$, " ")); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_div_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵɵtemplate(1, MyComponent_div_0_span_1_Template, 2, 2, "span", $c1$); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $app$ = $i0$.ɵɵnextContext(); | 
					
						
							|  |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 2, 1, "div", $c0$); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $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 = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = [${AttributeMarker.Template}, "ngFor", "ngForOf"]; | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_div_0_div_1_div_1_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           const $middle$ = $i0$.ɵɵnextContext().$implicit; | 
					
						
							|  |  |  |           const $myComp$ = $i0$.ɵɵnextContext(2); | 
					
						
							|  |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_div_0_div_1_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵɵtemplate(1, MyComponent_div_0_div_1_div_1_Template, 2, 2, "div", $c0$); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							|  |  |  |           const $middle$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_div_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵɵtemplate(1, MyComponent_div_0_div_1_Template, 2, 1, "div", $c0$); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							|  |  |  |           const $outer$ = ctx.$implicit; | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $r3$.ɵɵselect(1); | 
					
						
							|  |  |  |           $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) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 2, 1, "div", $c0$); | 
					
						
							| 
									
										
										
										
											2018-07-25 17:25:22 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $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 = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = ["attr", "l", ${AttributeMarker.Bindings}, "boundAttr"]; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ng_template_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtext(0, " some-content "); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 1, 0, "ng-template", $c0$); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:32:30 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $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', | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 template: '<ng-template #foo>some-content</ng-template>', | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  |               }) | 
					
						
							|  |  |  |               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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ng_template_0_Template(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtext(0, "some-content"); | 
					
						
							| 
									
										
										
										
											2018-08-20 14:23:17 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 1, 0, "ng-template", 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', | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |                 template: '<ng-template (outDirective)="$event.doSth()"></ng-template>', | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:24 +02:00
										 |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $t0_attrs$ = [${AttributeMarker.Bindings}, "outDirective"]; | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  |       function MyComponent_ng_template_0_Template(rf, ctx) { } | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 0, 0, "ng-template", $t0_attrs$); | 
					
						
							|  |  |  |           $i0$.ɵɵlistener("outDirective", function MyComponent_Template_ng_template_outDirective_0_listener($event) { return $event.doSth(); }); | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-12-19 22:17:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should create unique template function names even for similar nested template structures', | 
					
						
							|  |  |  |      () => { | 
					
						
							|  |  |  |        const files = { | 
					
						
							|  |  |  |          app: { | 
					
						
							|  |  |  |            'spec1.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'a-component', | 
					
						
							|  |  |  |             template: \`
 | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <p *ngIf="item < 10">less than 10</p> | 
					
						
							|  |  |  |                 <p *ngIf="item < 10">less than 10</p> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <p *ngIf="item > 10">more than 10</p> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             \`,
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class AComponent { | 
					
						
							|  |  |  |             items = [4, 2]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [AComponent]}) | 
					
						
							|  |  |  |           export class AModule {} | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |            'spec2.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'b-component', | 
					
						
							|  |  |  |             template: \`
 | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <ng-container *ngFor="let subitem of item.subitems"> | 
					
						
							|  |  |  |                   <p *ngIf="subitem < 10">less than 10</p> | 
					
						
							|  |  |  |                   <p *ngIf="subitem < 10">less than 10</p> | 
					
						
							|  |  |  |                 </ng-container> | 
					
						
							|  |  |  |                 <ng-container *ngFor="let subitem of item.subitems"> | 
					
						
							|  |  |  |                   <p *ngIf="subitem < 10">less than 10</p> | 
					
						
							|  |  |  |                 </ng-container> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <ng-container *ngFor="let subitem of item.subitems"> | 
					
						
							|  |  |  |                   <p *ngIf="subitem > 10">more than 10</p> | 
					
						
							|  |  |  |                 </ng-container> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             \`,
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class BComponent { | 
					
						
							|  |  |  |             items = [ | 
					
						
							|  |  |  |               {subitems: [1, 3]}, | 
					
						
							|  |  |  |               {subitems: [3, 7]}, | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [BComponent]}) | 
					
						
							|  |  |  |           export class BModule {} | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |          }, | 
					
						
							|  |  |  |        }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        const allTemplateFunctionsNames = (result.source.match(/function ([^\s(]+)/g) || []) | 
					
						
							|  |  |  |                                              .map(x => x.slice(9)) | 
					
						
							|  |  |  |                                              .filter(x => x.includes('Template')) | 
					
						
							|  |  |  |                                              .sort(); | 
					
						
							|  |  |  |        const uniqueTemplateFunctionNames = Array.from(new Set(allTemplateFunctionsNames)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        // Expected template function:
 | 
					
						
							|  |  |  |        // - 5 for AComponent's template.
 | 
					
						
							|  |  |  |        // - 9 for BComponent's template.
 | 
					
						
							|  |  |  |        // - 2 for the two components.
 | 
					
						
							|  |  |  |        expect(allTemplateFunctionsNames.length).toBe(5 + 9 + 2); | 
					
						
							|  |  |  |        expect(allTemplateFunctionsNames).toEqual(uniqueTemplateFunctionNames); | 
					
						
							|  |  |  |      }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should create unique listener function names even for similar nested template structures', | 
					
						
							|  |  |  |      () => { | 
					
						
							|  |  |  |        const files = { | 
					
						
							|  |  |  |          app: { | 
					
						
							|  |  |  |            'spec.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-component', | 
					
						
							|  |  |  |             template: \`
 | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <p (click)="$event">{{ item }}</p> | 
					
						
							|  |  |  |                 <p (click)="$event">{{ item }}</p> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |               <div *ngFor="let item of items"> | 
					
						
							|  |  |  |                 <p (click)="$event">{{ item }}</p> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             \`,
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             items = [4, 2]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {} | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |          }, | 
					
						
							|  |  |  |        }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        const allListenerFunctionsNames = (result.source.match(/function ([^\s(]+)/g) || []) | 
					
						
							|  |  |  |                                              .map(x => x.slice(9)) | 
					
						
							|  |  |  |                                              .filter(x => x.includes('listener')) | 
					
						
							|  |  |  |                                              .sort(); | 
					
						
							|  |  |  |        const uniqueListenerFunctionNames = Array.from(new Set(allListenerFunctionsNames)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        expect(allListenerFunctionsNames.length).toBe(3); | 
					
						
							|  |  |  |        expect(allListenerFunctionsNames).toEqual(uniqueListenerFunctionNames); | 
					
						
							|  |  |  |      }); | 
					
						
							| 
									
										
										
										
											2019-02-09 16:04:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should support pipes in template bindings', () => { | 
					
						
							|  |  |  |     const files = { | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <div *ngIf="val | pipe"></div>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const template = `
 | 
					
						
							| 
									
										
										
										
											2019-03-07 08:31:31 +00:00
										 |  |  |       const $c0$ = [${AttributeMarker.Template}, "ngIf"]; | 
					
						
							| 
									
										
										
										
											2019-02-09 16:04:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       function MyComponent_div_0_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵelement(0, "div"); | 
					
						
							| 
									
										
										
										
											2019-02-09 16:04:15 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", $c0$); | 
					
						
							|  |  |  |           $i0$.ɵɵpipe(1, "pipe"); | 
					
						
							| 
									
										
										
										
											2019-02-09 16:04:15 +01:00
										 |  |  |         } if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-04-11 13:46:47 -07:00
										 |  |  |           $i0$.ɵɵselect(0); | 
					
						
							|  |  |  |           $i0$.ɵɵelementProperty(0, "ngIf", $i0$.ɵɵbind($i0$.ɵɵpipeBind1(1, 1, ctx.val))); | 
					
						
							| 
									
										
										
										
											2019-02-09 16:04:15 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:20 -07:00
										 |  |  | }); |