| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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-07-12 15:10:55 -07:00
										 |  |  | import {MockDirectory, setup} from '@angular/compiler/test/aot/test_util'; | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  | import {compile, expectEmit} from './mock_compile'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('compiler compliance: bindings', () => { | 
					
						
							|  |  |  |   const angularFiles = setup({ | 
					
						
							| 
									
										
										
										
											2018-08-01 09:52:34 +02:00
										 |  |  |     compileAngular: false, | 
					
						
							|  |  |  |     compileFakeCore: true, | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |     compileAnimations: false, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('text bindings', () => { | 
					
						
							|  |  |  |     it('should generate interpolation instruction', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-component', | 
					
						
							|  |  |  |             template: \`
 | 
					
						
							|  |  |  |               <div>Hello {{ name }}</div>\`
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             name = 'World'; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |       template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |           $i0$.ɵɵtext(1); | 
					
						
							|  |  |  |           $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-04-23 20:40:05 -07:00
										 |  |  |           $i0$.ɵɵtextInterpolate1("Hello ", $ctx$.name, ""); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect interpolated text binding'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('property bindings', () => { | 
					
						
							|  |  |  |     it('should generate bind instruction', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-app', | 
					
						
							|  |  |  |             template: '<a [title]="title"></a>' | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             title = 'Hello World'; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       consts: [[${AttributeMarker.Bindings}, "title"]], | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |       template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           $i0$.ɵɵelement(0, "a", 0); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           $i0$.ɵɵproperty("title", $ctx$.title); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect property binding'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should generate interpolation instruction for {{...}} bindings', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-component', | 
					
						
							|  |  |  |             template: \`
 | 
					
						
							|  |  |  |               <a title="Hello {{name}}"></a>\`
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             name = 'World'; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							| 
									
										
										
										
											2018-08-20 15:20:12 +02:00
										 |  |  |       … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       consts: [[${AttributeMarker.Bindings}, "title"]], | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |       template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           $i0$.ɵɵelement(0, "a", 0); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           $i0$.ɵɵpropertyInterpolate1("title", "Hello ", $ctx$.name, ""); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect interpolated property binding'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-01-10 15:54:48 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should ignore empty bindings', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'test', | 
					
						
							|  |  |  |               template: '<div [someProp]></div>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             class FooCmp {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2019-05-24 14:20:41 -07:00
										 |  |  |       expect(result.source).not.toContain('i0.ɵɵproperty'); | 
					
						
							| 
									
										
										
										
											2019-01-10 15:54:48 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-02-21 00:00:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should not remap property names whose names do not correspond to their attribute names', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          const files = { | 
					
						
							|  |  |  |            app: { | 
					
						
							|  |  |  |              'spec.ts': `
 | 
					
						
							|  |  |  |               import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @Component({ | 
					
						
							|  |  |  |                 selector: 'my-component', | 
					
						
							|  |  |  |                 template: \`
 | 
					
						
							|  |  |  |                   <label [for]="forValue"></label>\`
 | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               export class MyComponent { | 
					
						
							|  |  |  |                 forValue = 'some-input'; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |               export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  |          }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          const template = `
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |       consts: [[${AttributeMarker.Bindings}, "for"]] | 
					
						
							| 
									
										
										
										
											2019-02-21 00:00:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // ...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             $i0$.ɵɵelement(0, "label", 0); | 
					
						
							| 
									
										
										
										
											2019-02-21 00:00:02 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵproperty("for", ctx.forValue); | 
					
						
							| 
									
										
										
										
											2019-02-21 00:00:02 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          const result = compile(files, angularFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |        }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												fix(compiler): evaluate safe navigation expressions in correct binding order (#37911)
When using the safe navigation operator in a binding expression, a temporary
variable may be used for storing the result of a side-effectful call.
For example, the following template uses a pipe and a safe property access:
```html
<app-person-view [enabled]="enabled" [firstName]="(person$ | async)?.name"></app-person-view>
```
The result of the pipe evaluation is stored in a temporary to be able to check
whether it is present. The temporary variable needs to be declared in a separate
statement and this would also cause the full expression itself to be pulled out
into a separate statement. This would compile into the following
pseudo-code instructions:
```js
var temp = null;
var firstName = (temp = pipe('async', ctx.person$)) == null ? null : temp.name;
property('enabled', ctx.enabled)('firstName', firstName);
```
Notice that the pipe evaluation happens before evaluating the `enabled` binding,
such that the runtime's internal binding index would correspond with `enabled`,
not `firstName`. This introduces a problem when the pipe uses `WrappedValue` to
force a change to be detected, as the runtime would then mark the binding slot
corresponding with `enabled` as dirty, instead of `firstName`. This results
in the `enabled` binding to be updated, triggering setters and affecting how
`OnChanges` is called.
In the pseudo-code above, the intermediate `firstName` variable is not strictly
necessary---it only improved readability a bit---and emitting it inline with
the binding itself avoids the out-of-order execution of the pipe:
```js
var temp = null;
property('enabled', ctx.enabled)
  ('firstName', (temp = pipe('async', ctx.person$)) == null ? null : temp.name);
```
This commit introduces a new `BindingForm` that results in the above code to be
generated and adds compiler and acceptance tests to verify the proper behavior.
Fixes #37194
PR Close #37911
											
										 
											2020-07-03 19:35:44 +02:00
										 |  |  |     it('should emit temporary evaluation within the binding expression for in-order execution', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          // https://github.com/angular/angular/issues/37194
 | 
					
						
							|  |  |  |          // Verifies that temporary expressions used for expressions with potential side-effects in
 | 
					
						
							|  |  |  |          // the LHS of a safe navigation access are emitted within the binding expression itself, to
 | 
					
						
							|  |  |  |          // ensure that these temporaries are evaluated during the evaluation of the binding. This
 | 
					
						
							|  |  |  |          // is important for when the LHS contains a pipe, as pipe evaluation depends on the current
 | 
					
						
							|  |  |  |          // binding index.
 | 
					
						
							|  |  |  |          const files = { | 
					
						
							|  |  |  |            app: { | 
					
						
							|  |  |  |              'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: '<button [title]="myTitle" [id]="(auth()?.identity() | async)?.id" [tabindex]="1"></button>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               auth?: () => { identity(): any; }; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  |          }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          const result = compile(files, angularFiles); | 
					
						
							|  |  |  |          const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2020-09-21 13:05:26 +01:00
										 |  |  |               let $tmp0$ = null; | 
					
						
							| 
									
										
											  
											
												fix(compiler): evaluate safe navigation expressions in correct binding order (#37911)
When using the safe navigation operator in a binding expression, a temporary
variable may be used for storing the result of a side-effectful call.
For example, the following template uses a pipe and a safe property access:
```html
<app-person-view [enabled]="enabled" [firstName]="(person$ | async)?.name"></app-person-view>
```
The result of the pipe evaluation is stored in a temporary to be able to check
whether it is present. The temporary variable needs to be declared in a separate
statement and this would also cause the full expression itself to be pulled out
into a separate statement. This would compile into the following
pseudo-code instructions:
```js
var temp = null;
var firstName = (temp = pipe('async', ctx.person$)) == null ? null : temp.name;
property('enabled', ctx.enabled)('firstName', firstName);
```
Notice that the pipe evaluation happens before evaluating the `enabled` binding,
such that the runtime's internal binding index would correspond with `enabled`,
not `firstName`. This introduces a problem when the pipe uses `WrappedValue` to
force a change to be detected, as the runtime would then mark the binding slot
corresponding with `enabled` as dirty, instead of `firstName`. This results
in the `enabled` binding to be updated, triggering setters and affecting how
`OnChanges` is called.
In the pseudo-code above, the intermediate `firstName` variable is not strictly
necessary---it only improved readability a bit---and emitting it inline with
the binding itself avoids the out-of-order execution of the pipe:
```js
var temp = null;
property('enabled', ctx.enabled)
  ('firstName', (temp = pipe('async', ctx.person$)) == null ? null : temp.name);
```
This commit introduces a new `BindingForm` that results in the above code to be
generated and adds compiler and acceptance tests to verify the proper behavior.
Fixes #37194
PR Close #37911
											
										 
											2020-07-03 19:35:44 +02:00
										 |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("id", ($tmp0$ = $r3$.ɵɵpipeBind1(1, 3, ($tmp0$ = ctx.auth()) == null ? null : $tmp0$.identity())) == null ? null : $tmp0$.id)("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |        }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |     it('should chain multiple property bindings into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: '<button [title]="myTitle" [id]="buttonId" [tabindex]="1"></button>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |     it('should chain property bindings in the presence of other bindings', () => { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: '<button [title]="1" [attr.id]="2" [tabindex]="3" aria-label="{{1 + 3}}"></button>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵpropertyInterpolate("aria-label", 1 + 3); | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", 1)("tabindex", 3); | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |               $r3$.ɵɵattribute("id", 2); | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not add interpolated properties to the property instruction chain', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: '<button [title]="1" [id]="2" tabindex="{{0 + 3}}" aria-label="hello-{{1 + 3}}-{{2 + 3}}"></button>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵpropertyInterpolate("tabindex", 0 + 3); | 
					
						
							|  |  |  |               $r3$.ɵɵpropertyInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3, ""); | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", 1)("id", 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain synthetic property bindings together with regular property bindings', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button | 
					
						
							|  |  |  |                   [title]="myTitle" | 
					
						
							|  |  |  |                   [@expand]="expansionState" | 
					
						
							|  |  |  |                   [tabindex]="1" | 
					
						
							|  |  |  |                   [@fade]="'out'"></button> | 
					
						
							|  |  |  |                 \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               expansionState = 'expanded'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("@expand", ctx.expansionState)("tabindex", 1)("@fade", "out"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple property bindings on an ng-template', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: '<ng-template [title]="myTitle" [id]="buttonId" [tabindex]="1"></ng-template>' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'custom-id'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple property bindings when there are multiple elements', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [title]="myTitle" [id]="buttonId" [tabindex]="1"></button> | 
					
						
							|  |  |  |                 <span [id]="1" [title]="'hello'" [someProp]="1 + 2"></span> | 
					
						
							|  |  |  |                 <custom-element [prop]="'one'" [otherProp]="2"></custom-element> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |               $r3$.ɵɵproperty("id", 1)("title", "hello")("someProp", 1 + 2); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |               $r3$.ɵɵproperty("prop", "one")("otherProp", 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple property bindings when there are child elements', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [title]="myTitle" [id]="buttonId" [tabindex]="1"> | 
					
						
							|  |  |  |                   <span [id]="1" [title]="'hello'" [someProp]="1 + 2"></span> | 
					
						
							|  |  |  |                 </button>\`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-19 19:50:42 +02:00
										 |  |  |               $r3$.ɵɵproperty("id", 1)("title", "hello")("someProp", 1 + 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |   describe('attribute bindings', () => { | 
					
						
							|  |  |  |     it('should chain multiple attribute bindings into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [attr.title]="myTitle" attr.id="{{buttonId}}" [attr.tabindex]="1"></button> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple single-interpolation attribute bindings into one instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button attr.title="{{myTitle}}" attr.id="{{buttonId}}" attr.tabindex="{{1}}"></button> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |     it('should chain attribute bindings in the presence of other bindings', () => { | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [attr.title]="1" [id]="2" [attr.tabindex]="3" attr.aria-label="prefix-{{1 + 3}}"> | 
					
						
							|  |  |  |                 </button> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattributeInterpolate1("aria-label", "prefix-", 1 + 3, ""); | 
					
						
							|  |  |  |               $r3$.ɵɵproperty("id", 2); | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", 1)("tabindex", 3); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not add interpolated attributes to the attribute instruction chain', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button | 
					
						
							|  |  |  |                   [attr.title]="1" | 
					
						
							|  |  |  |                   [attr.id]="2" | 
					
						
							|  |  |  |                   attr.tabindex="prefix-{{0 + 3}}" | 
					
						
							|  |  |  |                   attr.aria-label="hello-{{1 + 3}}-{{2 + 3}}"></button>\`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattributeInterpolate1("tabindex", "prefix-", 0 + 3, ""); | 
					
						
							|  |  |  |               $r3$.ɵɵattributeInterpolate2("aria-label", "hello-", 1 + 3, "-", 2 + 3, ""); | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", 1)("id", 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple attribute bindings when there are multiple elements', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [attr.title]="myTitle" [attr.id]="buttonId" [attr.tabindex]="1"></button> | 
					
						
							|  |  |  |                 <span [attr.id]="1" [attr.title]="'hello'" [attr.some-attr]="1 + 2"></span> | 
					
						
							|  |  |  |                 <custom-element [attr.some-attr]="'one'" [attr.some-other-attr]="2"></custom-element> | 
					
						
							|  |  |  |               \`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |               $r3$.ɵɵattribute("id", 1)("title", "hello")("some-attr", 1 + 2); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |               $r3$.ɵɵattribute("some-attr", "one")("some-other-attr", 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple attribute bindings when there are child elements', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               template: \`
 | 
					
						
							|  |  |  |                 <button [attr.title]="myTitle" [attr.id]="buttonId" [attr.tabindex]="1"> | 
					
						
							|  |  |  |                   <span [attr.id]="1" [attr.title]="'hello'" [attr.some-attr]="1 + 2"></span> | 
					
						
							|  |  |  |                 </button>\`
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               buttonId = 'special-button'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							|  |  |  |           template: function MyComponent_Template(rf, ctx) { | 
					
						
							|  |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", ctx.myTitle)("id", ctx.buttonId)("tabindex", 1); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |               $r3$.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |               $r3$.ɵɵattribute("id", 1)("title", "hello")("some-attr", 1 + 2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-13 13:34:34 +02:00
										 |  |  |     it('should exclude attribute bindings from the attributes array', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-app', | 
					
						
							|  |  |  |             template: \`<a
 | 
					
						
							|  |  |  |               target="_blank" | 
					
						
							|  |  |  |               [title]="1" | 
					
						
							|  |  |  |               [attr.foo]="'one'" | 
					
						
							|  |  |  |               (customEvent)="doThings()" | 
					
						
							|  |  |  |               [attr.bar]="'two'" | 
					
						
							|  |  |  |               [id]="2" | 
					
						
							|  |  |  |               aria-label="link" | 
					
						
							|  |  |  |               [attr.baz]="three"></a>\`
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             doThings() {} | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							| 
									
										
										
										
											2020-04-07 12:43:43 -07:00
										 |  |  |         consts: [["target", "_blank", "aria-label", "link", ${ | 
					
						
							|  |  |  |           AttributeMarker.Bindings}, "title", "id", "customEvent"]], | 
					
						
							| 
									
										
										
										
											2019-07-13 13:34:34 +02:00
										 |  |  |         … | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect attribute array'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-24 20:24:32 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |   describe('host bindings', () => { | 
					
						
							|  |  |  |     it('should support host bindings', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Directive, HostBinding, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({selector: '[hostBindingDir]'}) | 
					
						
							|  |  |  |             export class HostBindingDir { | 
					
						
							|  |  |  |               @HostBinding('id') dirId = 'some id'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostBindingDir]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const HostBindingDirDeclaration = `
 | 
					
						
							| 
									
										
										
										
											2020-01-08 11:32:33 -08:00
										 |  |  |       HostBindingDir.ɵdir = $r3$.ɵɵdefineDirective({ | 
					
						
							|  |  |  |         type: HostBindingDir, | 
					
						
							|  |  |  |         selectors: [["", "hostBindingDir", ""]], | 
					
						
							|  |  |  |           hostVars: 1, | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function HostBindingDir_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("id", ctx.dirId); | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-11-27 12:05:26 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(source, HostBindingDirDeclaration, 'Invalid host binding code'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												fix(compiler): evaluate safe navigation expressions in correct binding order (#37911)
When using the safe navigation operator in a binding expression, a temporary
variable may be used for storing the result of a side-effectful call.
For example, the following template uses a pipe and a safe property access:
```html
<app-person-view [enabled]="enabled" [firstName]="(person$ | async)?.name"></app-person-view>
```
The result of the pipe evaluation is stored in a temporary to be able to check
whether it is present. The temporary variable needs to be declared in a separate
statement and this would also cause the full expression itself to be pulled out
into a separate statement. This would compile into the following
pseudo-code instructions:
```js
var temp = null;
var firstName = (temp = pipe('async', ctx.person$)) == null ? null : temp.name;
property('enabled', ctx.enabled)('firstName', firstName);
```
Notice that the pipe evaluation happens before evaluating the `enabled` binding,
such that the runtime's internal binding index would correspond with `enabled`,
not `firstName`. This introduces a problem when the pipe uses `WrappedValue` to
force a change to be detected, as the runtime would then mark the binding slot
corresponding with `enabled` as dirty, instead of `firstName`. This results
in the `enabled` binding to be updated, triggering setters and affecting how
`OnChanges` is called.
In the pseudo-code above, the intermediate `firstName` variable is not strictly
necessary---it only improved readability a bit---and emitting it inline with
the binding itself avoids the out-of-order execution of the pipe:
```js
var temp = null;
property('enabled', ctx.enabled)
  ('firstName', (temp = pipe('async', ctx.person$)) == null ? null : temp.name);
```
This commit introduces a new `BindingForm` that results in the above code to be
generated and adds compiler and acceptance tests to verify the proper behavior.
Fixes #37194
PR Close #37911
											
										 
											2020-07-03 19:35:44 +02:00
										 |  |  |     it('should support host bindings with temporary expressions', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Directive, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[hostBindingDir]', | 
					
						
							|  |  |  |               host: {'[id]': 'getData()?.id'} | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostBindingDir { | 
					
						
							|  |  |  |               getData?: () => { id: number }; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostBindingDir]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const HostBindingDirDeclaration = `
 | 
					
						
							|  |  |  |       HostBindingDir.ɵdir = $r3$.ɵɵdefineDirective({ | 
					
						
							|  |  |  |         type: HostBindingDir, | 
					
						
							|  |  |  |         selectors: [["", "hostBindingDir", ""]], | 
					
						
							|  |  |  |           hostVars: 1, | 
					
						
							|  |  |  |           hostBindings: function HostBindingDir_HostBindings(rf, ctx) { | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2020-09-21 13:05:26 +01:00
										 |  |  |               let $tmp0$ = null; | 
					
						
							| 
									
										
											  
											
												fix(compiler): evaluate safe navigation expressions in correct binding order (#37911)
When using the safe navigation operator in a binding expression, a temporary
variable may be used for storing the result of a side-effectful call.
For example, the following template uses a pipe and a safe property access:
```html
<app-person-view [enabled]="enabled" [firstName]="(person$ | async)?.name"></app-person-view>
```
The result of the pipe evaluation is stored in a temporary to be able to check
whether it is present. The temporary variable needs to be declared in a separate
statement and this would also cause the full expression itself to be pulled out
into a separate statement. This would compile into the following
pseudo-code instructions:
```js
var temp = null;
var firstName = (temp = pipe('async', ctx.person$)) == null ? null : temp.name;
property('enabled', ctx.enabled)('firstName', firstName);
```
Notice that the pipe evaluation happens before evaluating the `enabled` binding,
such that the runtime's internal binding index would correspond with `enabled`,
not `firstName`. This introduces a problem when the pipe uses `WrappedValue` to
force a change to be detected, as the runtime would then mark the binding slot
corresponding with `enabled` as dirty, instead of `firstName`. This results
in the `enabled` binding to be updated, triggering setters and affecting how
`OnChanges` is called.
In the pseudo-code above, the intermediate `firstName` variable is not strictly
necessary---it only improved readability a bit---and emitting it inline with
the binding itself avoids the out-of-order execution of the pipe:
```js
var temp = null;
property('enabled', ctx.enabled)
  ('firstName', (temp = pipe('async', ctx.person$)) == null ? null : temp.name);
```
This commit introduces a new `BindingForm` that results in the above code to be
generated and adds compiler and acceptance tests to verify the proper behavior.
Fixes #37194
PR Close #37911
											
										 
											2020-07-03 19:35:44 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("id", ($tmp0$ = ctx.getData()) == null ? null : $tmp0$.id); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(source, HostBindingDirDeclaration, 'Invalid host binding code'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |     it('should support host bindings with pure functions', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'host-binding-comp', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[id]': '["red", id]' | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               template: '' | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostBindingComp { | 
					
						
							|  |  |  |               id = 'some id'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostBindingComp]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const HostBindingCompDeclaration = `
 | 
					
						
							|  |  |  |         const $ff$ = function ($v$) { return ["red", $v$]; }; | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         HostBindingComp.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |           type: HostBindingComp, | 
					
						
							|  |  |  |           selectors: [["host-binding-comp"]], | 
					
						
							| 
									
										
										
										
											2020-01-08 11:32:33 -08:00
										 |  |  |           hostVars: 3, | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function HostBindingComp_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("id", $r3$.ɵɵpureFunction1(1, $ff$, ctx.id)); | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |           decls: 0, | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |           vars: 0, | 
					
						
							| 
									
										
										
										
											2018-11-19 18:48:14 +01:00
										 |  |  |           template: function HostBindingComp_Template(rf, ctx) {}, | 
					
						
							|  |  |  |           encapsulation: 2 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(source, HostBindingCompDeclaration, 'Invalid host binding code'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support host attribute bindings', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Directive, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[hostAttributeDir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[attr.required]': 'required' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostAttributeDir { | 
					
						
							|  |  |  |               required = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostAttributeDir]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const HostAttributeDirDeclaration = `
 | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |         HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |           type: HostAttributeDir, | 
					
						
							|  |  |  |           selectors: [["", "hostAttributeDir", ""]], | 
					
						
							| 
									
										
										
										
											2020-01-08 11:32:33 -08:00
										 |  |  |           hostVars: 1, | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function HostAttributeDir_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |               $r3$.ɵɵattribute("required", ctx.required); | 
					
						
							| 
									
										
										
										
											2018-11-20 15:20:19 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-11-27 12:05:26 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(source, HostAttributeDirDeclaration, 'Invalid host attribute code'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support host attributes', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Directive, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[hostAttributeDir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 'aria-label': 'label' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostAttributeDir { | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostAttributeDir]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const HostAttributeDirDeclaration = `
 | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |         HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |           type: HostAttributeDir, | 
					
						
							|  |  |  |           selectors: [["", "hostAttributeDir", ""]], | 
					
						
							| 
									
										
										
										
											2020-01-08 11:32:33 -08:00
										 |  |  |           hostAttrs: ["aria-label", "label"] | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(source, HostAttributeDirDeclaration, 'Invalid host attribute code'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  |     it('should support host attributes together with host classes and styles', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'spec.ts': `
 | 
					
						
							|  |  |  |             import {Component, Directive, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'my-host-attribute-component', | 
					
						
							|  |  |  |               template: "...", | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 'title': 'hello there from component', | 
					
						
							|  |  |  |                 'style': 'opacity:1' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostAttributeComp { | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[hostAttributeDir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 'style': 'width: 200px; height: 500px', | 
					
						
							|  |  |  |                 '[style.opacity]': "true", | 
					
						
							|  |  |  |                 'class': 'one two', | 
					
						
							|  |  |  |                 '[class.three]': "true", | 
					
						
							|  |  |  |                 'title': 'hello there from directive', | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class HostAttributeDir { | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @NgModule({declarations: [HostAttributeComp, HostAttributeDir]}) | 
					
						
							|  |  |  |             export class MyModule {} | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const CompAndDirDeclaration = `
 | 
					
						
							| 
									
										
										
										
											2019-10-10 14:57:15 -07:00
										 |  |  |         HostAttributeComp.ɵcmp = $r3$.ɵɵdefineComponent({ | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  |           type: HostAttributeComp, | 
					
						
							|  |  |  |           selectors: [["my-host-attribute-component"]], | 
					
						
							| 
									
										
										
										
											2020-04-07 12:43:43 -07:00
										 |  |  |           hostAttrs: ["title", "hello there from component", ${ | 
					
						
							|  |  |  |           AttributeMarker.Styles}, "opacity", "1"], | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-11 12:28:12 -07:00
										 |  |  |         HostAttributeDir.ɵdir = $r3$.ɵɵdefineDirective({ | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  |           type: HostAttributeDir, | 
					
						
							|  |  |  |           selectors: [["", "hostAttributeDir", ""]], | 
					
						
							| 
									
										
										
										
											2020-04-07 12:43:43 -07:00
										 |  |  |           hostAttrs: ["title", "hello there from directive", ${ | 
					
						
							|  |  |  |           AttributeMarker.Classes}, "one", "two", ${ | 
					
						
							|  |  |  |           AttributeMarker.Styles}, "width", "200px", "height", "500px"], | 
					
						
							| 
									
										
										
										
											2019-12-17 15:40:37 -08:00
										 |  |  |           hostVars: 4, | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function HostAttributeDir_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  |             … | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-01-08 11:32:33 -08:00
										 |  |  |     `;
 | 
					
						
							| 
									
										
										
										
											2019-01-11 14:03:37 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const source = result.source; | 
					
						
							|  |  |  |       expectEmit(source, CompAndDirDeclaration, 'Invalid host attribute code'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple host property bindings into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[title]': 'myTitle', | 
					
						
							|  |  |  |                 '[tabindex]': '1', | 
					
						
							|  |  |  |                 '[id]': 'myId' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               myId = 'special-directive'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("title", ctx.myTitle)("tabindex", 1)("id", ctx.myId); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain both host properties in the decorator and on the class', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive, HostBinding} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[tabindex]': '1' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               @HostBinding('title') | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @HostBinding('id') | 
					
						
							|  |  |  |               myId = 'special-directive'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("tabindex", 1)("title", ctx.myTitle)("id", ctx.myId); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple host property bindings in the presence of other bindings', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[title]': '"my title"', | 
					
						
							|  |  |  |                 '[attr.tabindex]': '1', | 
					
						
							|  |  |  |                 '[id]': '"my-id"' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |               $r3$.ɵɵhostProperty("title", "my title")("id", "my-id"); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |               $r3$.ɵɵattribute("tabindex", 1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple synthetic properties into a single instruction call', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[@expand]': 'expandedState', | 
					
						
							|  |  |  |                 '[@fadeOut]': 'true', | 
					
						
							|  |  |  |                 '[@shrink]': 'isSmall' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               expandedState = 'collapsed'; | 
					
						
							|  |  |  |               isSmall = true; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |         hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |           … | 
					
						
							|  |  |  |           if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2020-05-15 15:33:00 -07:00
										 |  |  |             $r3$.ɵɵsyntheticHostProperty("@expand", ctx.expandedState)("@fadeOut", true)("@shrink", ctx.isSmall); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple host attribute bindings into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[attr.title]': 'myTitle', | 
					
						
							|  |  |  |                 '[attr.tabindex]': '1', | 
					
						
							|  |  |  |                 '[attr.id]': 'myId' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  |               myId = 'special-directive'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("title", ctx.myTitle)("tabindex", 1)("id", ctx.myId); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain both host attributes in the decorator and on the class', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive, HostBinding} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[attr.tabindex]': '1' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               @HostBinding('attr.title') | 
					
						
							|  |  |  |               myTitle = 'hello'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @HostBinding('attr.id') | 
					
						
							|  |  |  |               myId = 'special-directive'; | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |             … | 
					
						
							|  |  |  |             if (rf & 2) { | 
					
						
							|  |  |  |               $r3$.ɵɵattribute("tabindex", 1)("title", ctx.myTitle)("id", ctx.myId); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple host attribute bindings in the presence of other bindings', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '[attr.title]': '"my title"', | 
					
						
							|  |  |  |                 '[tabindex]': '1', | 
					
						
							|  |  |  |                 '[attr.id]': '"my-id"' | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective {}`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |             … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |             hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |               … | 
					
						
							|  |  |  |               if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-07-14 11:11:10 +02:00
										 |  |  |                 $r3$.ɵɵhostProperty("tabindex", 1); | 
					
						
							| 
									
										
										
										
											2019-06-27 20:23:15 +02:00
										 |  |  |                 $r3$.ɵɵattribute("title", "my title")("id", "my-id"); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |     it('should chain multiple host listeners into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Directive, HostListener} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Directive({ | 
					
						
							|  |  |  |               selector: '[my-dir]', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '(mousedown)': 'mousedown()', | 
					
						
							|  |  |  |                 '(mouseup)': 'mouseup()', | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyDirective { | 
					
						
							|  |  |  |               mousedown() {} | 
					
						
							|  |  |  |               mouseup() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @HostListener('click') | 
					
						
							|  |  |  |               click() {} | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyDirective_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |             if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2020-02-01 13:19:31 +01:00
										 |  |  |               $r3$.ɵɵlistener("mousedown", function MyDirective_mousedown_HostBindingHandler() { return ctx.mousedown(); })("mouseup", function MyDirective_mouseup_HostBindingHandler() { return ctx.mouseup(); })("click", function MyDirective_click_HostBindingHandler() { return ctx.click(); }); | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple synthetic host listeners into a single instruction', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component, HostListener} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'my-comp', | 
					
						
							|  |  |  |               template: '', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '(@animation.done)': 'done()', | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               @HostListener('@animation.start') | 
					
						
							|  |  |  |               start() {} | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |           … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |           hostBindings: function MyComponent_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |             if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2020-05-15 15:33:00 -07:00
										 |  |  |               $r3$.ɵɵsyntheticHostListener("@animation.done", function MyComponent_animation_animation_done_HostBindingHandler() { return ctx.done(); })("@animation.start", function MyComponent_animation_animation_start_HostBindingHandler() { return ctx.start(); }); | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should chain multiple regular and synthetic host listeners into two instructions', () => { | 
					
						
							|  |  |  |       const files = { | 
					
						
							|  |  |  |         app: { | 
					
						
							|  |  |  |           'example.ts': `
 | 
					
						
							|  |  |  |             import {Component, HostListener} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             @Component({ | 
					
						
							|  |  |  |               selector: 'my-comp', | 
					
						
							|  |  |  |               template: '', | 
					
						
							|  |  |  |               host: { | 
					
						
							|  |  |  |                 '(mousedown)': 'mousedown()', | 
					
						
							|  |  |  |                 '(@animation.done)': 'done()', | 
					
						
							|  |  |  |                 '(mouseup)': 'mouseup()', | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             export class MyComponent { | 
					
						
							|  |  |  |               @HostListener('@animation.start') | 
					
						
							|  |  |  |               start() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               @HostListener('click') | 
					
						
							|  |  |  |               click() {} | 
					
						
							|  |  |  |             }`
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2020-01-25 12:38:42 +01:00
										 |  |  |         hostBindings: function MyComponent_HostBindings(rf, ctx) { | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2020-05-15 15:33:00 -07:00
										 |  |  |             $r3$.ɵɵsyntheticHostListener("@animation.done", function MyComponent_animation_animation_done_HostBindingHandler() { return ctx.done(); })("@animation.start", function MyComponent_animation_animation_start_HostBindingHandler() { return ctx.start(); }); | 
					
						
							| 
									
										
										
										
											2020-02-01 13:19:31 +01:00
										 |  |  |             $r3$.ɵɵlistener("mousedown", function MyComponent_mousedown_HostBindingHandler() { return ctx.mousedown(); })("mouseup", function MyComponent_mouseup_HostBindingHandler() { return ctx.mouseup(); })("click", function MyComponent_click_HostBindingHandler() { return ctx.click(); }); | 
					
						
							| 
									
										
										
										
											2019-11-12 02:15:24 +09:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect template'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:05:06 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 13:34:42 -07:00
										 |  |  |   describe('non bindable behavior', () => { | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |     const getAppFiles = (template: string = ''): MockDirectory => ({ | 
					
						
							|  |  |  |       app: { | 
					
						
							|  |  |  |         'example.ts': `
 | 
					
						
							|  |  |  |           import {Component, NgModule} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @Component({ | 
					
						
							|  |  |  |             selector: 'my-app', | 
					
						
							|  |  |  |             template: \`${template}\`
 | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           export class MyComponent { | 
					
						
							|  |  |  |             name = 'John Doe'; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           @NgModule({declarations: [MyComponent]}) | 
					
						
							|  |  |  |           export class MyModule {}`
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 18:05:46 -07:00
										 |  |  |     it('should generate the proper update instructions for interpolated properties', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h{{eight}}i{{nine}}j"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h{{eight}}i"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d{{four}}e"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c{{three}}d"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b{{two}}c"></div> | 
					
						
							|  |  |  |         <div title="a{{one}}b"></div> | 
					
						
							|  |  |  |         <div title="{{one}}"></div> | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |       … | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolateV("title", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate8("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate7("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate6("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate5("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate4("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate3("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate2("title", "a", ctx.one, "b", ctx.two, "c"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate1("title", "a", ctx.one, "b"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           i0.ɵɵpropertyInterpolate("title", ctx.one); | 
					
						
							| 
									
										
										
										
											2019-04-20 18:05:46 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |       … | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect handling of interpolated properties'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-15 19:53:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should generate the proper update instructions for interpolated attributes', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h{{eight}}i{{nine}}j"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h{{eight}}i"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g{{seven}}h"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f{{six}}g"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e{{five}}f"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d{{four}}e"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c{{three}}d"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b{{two}}c"></div> | 
					
						
							|  |  |  |         <div attr.title="a{{one}}b"></div> | 
					
						
							|  |  |  |         <div attr.title="{{one}}"></div> | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |       … | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolateV("title", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate8("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate7("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate6("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate5("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate4("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate3("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate2("title", "a", ctx.one, "b", ctx.two, "c"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:21:24 -07:00
										 |  |  |           i0.ɵɵattributeInterpolate1("title", "a", ctx.one, "b"); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |           i0.ɵɵadvance(1); | 
					
						
							| 
									
										
										
										
											2019-05-15 20:24:29 -07:00
										 |  |  |           i0.ɵɵattribute("title", ctx.one); | 
					
						
							| 
									
										
										
										
											2019-05-15 19:53:13 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |       … | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect handling of interpolated properties'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |     it('should keep local ref for host element', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |         <b ngNonBindable #myRef id="my-id"> | 
					
						
							|  |  |  |           <i>Hello {{ name }}!</i> | 
					
						
							|  |  |  |         </b> | 
					
						
							|  |  |  |         {{ myRef.id }} | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-10-29 22:20:25 +01:00
										 |  |  |         consts: [["id", "my-id"], ["myRef", ""]], | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |         template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-10-29 22:20:25 +01:00
										 |  |  |             $i0$.ɵɵelementStart(0, "b", 0, 1); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵdisableBindings(); | 
					
						
							|  |  |  |             $i0$.ɵɵelementStart(2, "i"); | 
					
						
							|  |  |  |             $i0$.ɵɵtext(3, "Hello {{ name }}!"); | 
					
						
							|  |  |  |             $i0$.ɵɵelementEnd(); | 
					
						
							|  |  |  |             $i0$.ɵɵenableBindings(); | 
					
						
							|  |  |  |             $i0$.ɵɵelementEnd(); | 
					
						
							|  |  |  |             $i0$.ɵɵtext(4); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             const $_r0$ = $i0$.ɵɵreference(1); | 
					
						
							| 
									
										
										
										
											2019-09-06 23:43:16 +02:00
										 |  |  |             $r3$.ɵɵadvance(4); | 
					
						
							| 
									
										
										
										
											2019-04-23 20:40:05 -07:00
										 |  |  |             $i0$.ɵɵtextInterpolate1(" ", $_r0$.id, " "); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2018-09-26 14:33:48 -07:00
										 |  |  |       expectEmit(result.source, template, 'Incorrect handling of local refs for host element'); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not have local refs for nested elements', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |        <div ngNonBindable> | 
					
						
							|  |  |  |          <input value="one" #myInput> {{ myInput.value }} | 
					
						
							|  |  |  |        </div> | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         consts: [["value", "one", "#myInput", ""]], | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |         template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |             $i0$.ɵɵdisableBindings(); | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             $i0$.ɵɵelement(1, "input", 0); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵtext(2, " {{ myInput.value }} "); | 
					
						
							|  |  |  |             $i0$.ɵɵenableBindings(); | 
					
						
							|  |  |  |             $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2018-09-26 14:33:48 -07:00
										 |  |  |       expectEmit(result.source, template, 'Incorrect handling of local refs for nested elements'); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-09-26 15:15:06 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should not process property bindings and listeners', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |         <div ngNonBindable> | 
					
						
							|  |  |  |           <div [id]="my-id" (click)="onclick"></div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         … | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |         consts: [["[id]", "my-id", "(click)", "onclick"]], | 
					
						
							| 
									
										
										
										
											2018-09-26 15:15:06 -07:00
										 |  |  |         template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵelementStart(0, "div"); | 
					
						
							|  |  |  |             $i0$.ɵɵdisableBindings(); | 
					
						
							| 
									
										
										
										
											2019-09-23 20:08:51 +02:00
										 |  |  |             $i0$.ɵɵelement(1, "div", 0); | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵenableBindings(); | 
					
						
							|  |  |  |             $i0$.ɵɵelementEnd(); | 
					
						
							| 
									
										
										
										
											2018-09-26 15:15:06 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							| 
									
										
										
										
											2018-09-26 16:02:40 -07:00
										 |  |  |       expectEmit(result.source, template, 'Incorrect handling of property bindings and listeners'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should not generate extra instructions for elements with no children', () => { | 
					
						
							|  |  |  |       const files: MockDirectory = getAppFiles(`
 | 
					
						
							|  |  |  |         <div ngNonBindable></div> | 
					
						
							|  |  |  |       `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const template = `
 | 
					
						
							|  |  |  |         template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							|  |  |  |           if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |             $i0$.ɵɵelement(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-09-26 16:02:40 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect handling of elements with no children'); | 
					
						
							| 
									
										
										
										
											2018-09-26 15:15:06 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-09-26 13:19:04 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  | }); |