| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |     compileAngular: true, | 
					
						
							|  |  |  |     compileAnimations: false, | 
					
						
							|  |  |  |     compileCommon: 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) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵE(0, "div"); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |           $i0$.ɵT(1); | 
					
						
							|  |  |  |           $i0$.ɵe(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵt(1, $i0$.ɵi1("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-07-12 15:10:55 -07:00
										 |  |  |       template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵEe(0, "a"); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵp(0, "title", $i0$.ɵb($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-07-12 15:10:55 -07:00
										 |  |  |       template:function MyComponent_Template(rf, $ctx$){ | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         if (rf & 1) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵEe(0, "a"); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (rf & 2) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:10:55 -07:00
										 |  |  |           $i0$.ɵp(0, "title", $i0$.ɵi1("Hello ", $ctx$.name, "")); | 
					
						
							| 
									
										
										
										
											2018-05-15 21:07:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       }`;
 | 
					
						
							|  |  |  |       const result = compile(files, angularFiles); | 
					
						
							|  |  |  |       expectEmit(result.source, template, 'Incorrect interpolated property binding'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |