| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-18 15:39:26 -07:00
										 |  |  | import {ViewEncapsulation} from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 16:27:53 -08:00
										 |  |  | import {CompileDirectiveMetadata, CompileDirectiveSummary, CompileIdentifierMetadata, CompileTokenMetadata} from '../compile_metadata'; | 
					
						
							| 
									
										
										
										
											2016-10-19 13:18:33 -07:00
										 |  |  | import {createSharedBindingVariablesIfNeeded} from '../compiler_util/expression_converter'; | 
					
						
							| 
									
										
										
										
											2016-10-24 11:11:31 -07:00
										 |  |  | import {createDiTokenExpression, createInlineArray} from '../compiler_util/identifier_util'; | 
					
						
							| 
									
										
										
										
											2016-10-06 15:10:27 -07:00
										 |  |  | import {isPresent} from '../facade/lang'; | 
					
						
							| 
									
										
										
										
											2016-09-18 15:39:26 -07:00
										 |  |  | import {Identifiers, identifierToken, resolveIdentifier} from '../identifiers'; | 
					
						
							| 
									
										
										
										
											2016-10-21 13:37:51 -07:00
										 |  |  | import {createClassStmt} from '../output/class_builder'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import * as o from '../output/output_ast'; | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  | import {ParseSourceSpan} from '../parse_util'; | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  | import {ChangeDetectorStatus, ViewType, isDefaultChangeDetectionStrategy} from '../private_import_core'; | 
					
						
							| 
									
										
										
										
											2016-09-18 15:39:26 -07:00
										 |  |  | import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {CompileElement, CompileNode} from './compile_element'; | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  | import {CompileView, CompileViewRootNode, CompileViewRootNodeType} from './compile_view'; | 
					
						
							| 
									
										
										
										
											2016-06-27 20:00:30 -07:00
										 |  |  | import {ChangeDetectorStatusEnum, DetectChangesVars, InjectMethodVars, ViewConstructorVars, ViewEncapsulationEnum, ViewProperties, ViewTypeEnum} from './constants'; | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  | import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDependency} from './deps'; | 
					
						
							|  |  |  | import {getViewClassName} from './util'; | 
					
						
							| 
									
										
										
										
											2016-05-25 12:46:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | const IMPLICIT_TEMPLATE_VAR = '\$implicit'; | 
					
						
							|  |  |  | const CLASS_ATTR = 'class'; | 
					
						
							|  |  |  | const STYLE_ATTR = 'style'; | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  | const NG_CONTAINER_TAG = 'ng-container'; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | var parentRenderNodeVar = o.variable('parentRenderNode'); | 
					
						
							|  |  |  | var rootSelectorVar = o.variable('rootSelector'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | export function buildView( | 
					
						
							|  |  |  |     view: CompileView, template: TemplateAst[], | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |     targetDependencies: | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |         Array<ViewClassDependency|ComponentFactoryDependency|DirectiveWrapperDependency>): number { | 
					
						
							| 
									
										
										
										
											2016-04-27 11:22:44 -07:00
										 |  |  |   var builderVisitor = new ViewBuilderVisitor(view, targetDependencies); | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |   const parentEl = | 
					
						
							|  |  |  |       view.declarationElement.isNull() ? view.declarationElement : view.declarationElement.parent; | 
					
						
							|  |  |  |   templateVisitAll(builderVisitor, template, parentEl); | 
					
						
							| 
									
										
										
										
											2016-11-01 14:21:40 -07:00
										 |  |  |   if (view.viewType === ViewType.EMBEDDED || view.viewType === ViewType.HOST) { | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |     view.lastRenderNode = builderVisitor.getOrCreateLastRenderNode(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   return builderVisitor.nestedViewCount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 11:22:44 -07:00
										 |  |  | export function finishView(view: CompileView, targetStatements: o.Statement[]) { | 
					
						
							|  |  |  |   view.afterNodes(); | 
					
						
							|  |  |  |   createViewTopLevelStmts(view, targetStatements); | 
					
						
							|  |  |  |   view.nodes.forEach((node) => { | 
					
						
							|  |  |  |     if (node instanceof CompileElement && node.hasEmbeddedView) { | 
					
						
							|  |  |  |       finishView(node.embeddedView, targetStatements); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ViewBuilderVisitor implements TemplateAstVisitor { | 
					
						
							|  |  |  |   nestedViewCount: number = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:23 -07:00
										 |  |  |   constructor( | 
					
						
							|  |  |  |       public view: CompileView, | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |       public targetDependencies: | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |           Array<ViewClassDependency|ComponentFactoryDependency|DirectiveWrapperDependency>) {} | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private _isRootNode(parent: CompileElement): boolean { return parent.view !== this.view; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |   private _addRootNodeAndProject(node: CompileNode) { | 
					
						
							|  |  |  |     var projectedNode = _getOuterContainerOrSelf(node); | 
					
						
							|  |  |  |     var parent = projectedNode.parent; | 
					
						
							|  |  |  |     var ngContentIndex = (<any>projectedNode.sourceAst).ngContentIndex; | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |     var viewContainer = | 
					
						
							|  |  |  |         (node instanceof CompileElement && node.hasViewContainer) ? node.viewContainer : null; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     if (this._isRootNode(parent)) { | 
					
						
							|  |  |  |       if (this.view.viewType !== ViewType.COMPONENT) { | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |         this.view.rootNodes.push(new CompileViewRootNode( | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |             viewContainer ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node, | 
					
						
							|  |  |  |             viewContainer || node.renderNode)); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else if (isPresent(parent.component) && isPresent(ngContentIndex)) { | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |       parent.addContentNode( | 
					
						
							|  |  |  |           ngContentIndex, | 
					
						
							|  |  |  |           new CompileViewRootNode( | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |               viewContainer ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node, | 
					
						
							|  |  |  |               viewContainer || node.renderNode)); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private _getParentRenderNode(parent: CompileElement): o.Expression { | 
					
						
							| 
									
										
										
										
											2016-06-15 08:50:41 -07:00
										 |  |  |     parent = _getOuterContainerParentOrSelf(parent); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     if (this._isRootNode(parent)) { | 
					
						
							|  |  |  |       if (this.view.viewType === ViewType.COMPONENT) { | 
					
						
							|  |  |  |         return parentRenderNodeVar; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         // root node of an embedded/host view
 | 
					
						
							|  |  |  |         return o.NULL_EXPR; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return isPresent(parent.component) && | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |               parent.component.template.encapsulation !== ViewEncapsulation.Native ? | 
					
						
							|  |  |  |           o.NULL_EXPR : | 
					
						
							|  |  |  |           parent.renderNode; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |   getOrCreateLastRenderNode(): o.Expression { | 
					
						
							|  |  |  |     const view = this.view; | 
					
						
							|  |  |  |     if (view.rootNodes.length === 0 || | 
					
						
							|  |  |  |         view.rootNodes[view.rootNodes.length - 1].type !== CompileViewRootNodeType.Node) { | 
					
						
							|  |  |  |       var fieldName = `_el_${view.nodes.length}`; | 
					
						
							|  |  |  |       view.fields.push( | 
					
						
							|  |  |  |           new o.ClassField(fieldName, o.importType(view.genConfig.renderTypes.renderElement))); | 
					
						
							|  |  |  |       view.createMethod.addStmt(o.THIS_EXPR.prop(fieldName) | 
					
						
							|  |  |  |                                     .set(ViewProperties.renderer.callMethod( | 
					
						
							|  |  |  |                                         'createTemplateAnchor', [o.NULL_EXPR, o.NULL_EXPR])) | 
					
						
							|  |  |  |                                     .toStmt()); | 
					
						
							|  |  |  |       view.rootNodes.push( | 
					
						
							| 
									
										
										
										
											2016-10-31 15:46:24 -07:00
										 |  |  |           new CompileViewRootNode(CompileViewRootNodeType.Node, o.THIS_EXPR.prop(fieldName))); | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     return view.rootNodes[view.rootNodes.length - 1].expr; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   visitBoundText(ast: BoundTextAst, parent: CompileElement): any { | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |     return this._visitText(ast, '', parent); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   visitText(ast: TextAst, parent: CompileElement): any { | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |     return this._visitText(ast, ast.value, parent); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |   private _visitText(ast: TemplateAst, value: string, parent: CompileElement): o.Expression { | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     var fieldName = `_text_${this.view.nodes.length}`; | 
					
						
							| 
									
										
										
										
											2016-04-30 16:13:03 -07:00
										 |  |  |     this.view.fields.push( | 
					
						
							|  |  |  |         new o.ClassField(fieldName, o.importType(this.view.genConfig.renderTypes.renderText))); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     var renderNode = o.THIS_EXPR.prop(fieldName); | 
					
						
							|  |  |  |     var compileNode = new CompileNode(parent, this.view, this.view.nodes.length, renderNode, ast); | 
					
						
							|  |  |  |     var createRenderNode = | 
					
						
							|  |  |  |         o.THIS_EXPR.prop(fieldName) | 
					
						
							|  |  |  |             .set(ViewProperties.renderer.callMethod( | 
					
						
							|  |  |  |                 'createText', | 
					
						
							|  |  |  |                 [ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                   this._getParentRenderNode(parent), o.literal(value), | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |                   this.view.createMethod.resetDebugInfoExpr(this.view.nodes.length, ast) | 
					
						
							|  |  |  |                 ])) | 
					
						
							|  |  |  |             .toStmt(); | 
					
						
							|  |  |  |     this.view.nodes.push(compileNode); | 
					
						
							|  |  |  |     this.view.createMethod.addStmt(createRenderNode); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |     this._addRootNodeAndProject(compileNode); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     return renderNode; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitNgContent(ast: NgContentAst, parent: CompileElement): any { | 
					
						
							|  |  |  |     // the projected nodes originate from a different view, so we don't
 | 
					
						
							|  |  |  |     // have debug information for them...
 | 
					
						
							|  |  |  |     this.view.createMethod.resetDebugInfo(null, ast); | 
					
						
							|  |  |  |     var parentRenderNode = this._getParentRenderNode(parent); | 
					
						
							|  |  |  |     if (parentRenderNode !== o.NULL_EXPR) { | 
					
						
							|  |  |  |       this.view.createMethod.addStmt( | 
					
						
							| 
									
										
										
										
											2016-11-02 17:54:05 -07:00
										 |  |  |           o.THIS_EXPR.callMethod('projectNodes', [parentRenderNode, o.literal(ast.index)]) | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |               .toStmt()); | 
					
						
							|  |  |  |     } else if (this._isRootNode(parent)) { | 
					
						
							|  |  |  |       if (this.view.viewType !== ViewType.COMPONENT) { | 
					
						
							|  |  |  |         // store root nodes only for embedded/host views
 | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |         this.view.rootNodes.push( | 
					
						
							|  |  |  |             new CompileViewRootNode(CompileViewRootNodeType.NgContent, null, ast.index)); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       if (isPresent(parent.component) && isPresent(ast.ngContentIndex)) { | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |         parent.addContentNode( | 
					
						
							|  |  |  |             ast.ngContentIndex, | 
					
						
							|  |  |  |             new CompileViewRootNode(CompileViewRootNodeType.NgContent, null, ast.index)); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitElement(ast: ElementAst, parent: CompileElement): any { | 
					
						
							|  |  |  |     var nodeIndex = this.view.nodes.length; | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |     var createRenderNodeExpr: o.Expression; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     var debugContextExpr = this.view.createMethod.resetDebugInfoExpr(nodeIndex, ast); | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |     var directives = ast.directives.map(directiveAst => directiveAst.directive); | 
					
						
							|  |  |  |     var component = directives.find(directive => directive.isComponent); | 
					
						
							|  |  |  |     if (ast.name === NG_CONTAINER_TAG) { | 
					
						
							|  |  |  |       createRenderNodeExpr = ViewProperties.renderer.callMethod( | 
					
						
							|  |  |  |           'createTemplateAnchor', [this._getParentRenderNode(parent), debugContextExpr]); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |       const htmlAttrs = _readHtmlAttrs(ast.attrs); | 
					
						
							| 
									
										
										
										
											2016-10-24 11:11:31 -07:00
										 |  |  |       const attrNameAndValues = createInlineArray( | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |           _mergeHtmlAndDirectiveAttrs(htmlAttrs, directives).map(v => o.literal(v))); | 
					
						
							|  |  |  |       if (nodeIndex === 0 && this.view.viewType === ViewType.HOST) { | 
					
						
							|  |  |  |         createRenderNodeExpr = | 
					
						
							|  |  |  |             o.importExpr(resolveIdentifier(Identifiers.selectOrCreateRenderHostElement)).callFn([ | 
					
						
							|  |  |  |               ViewProperties.renderer, o.literal(ast.name), attrNameAndValues, rootSelectorVar, | 
					
						
							|  |  |  |               debugContextExpr | 
					
						
							|  |  |  |             ]); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |         createRenderNodeExpr = | 
					
						
							|  |  |  |             o.importExpr(resolveIdentifier(Identifiers.createRenderElement)).callFn([ | 
					
						
							|  |  |  |               ViewProperties.renderer, this._getParentRenderNode(parent), o.literal(ast.name), | 
					
						
							|  |  |  |               attrNameAndValues, debugContextExpr | 
					
						
							|  |  |  |             ]); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     var fieldName = `_el_${nodeIndex}`; | 
					
						
							|  |  |  |     this.view.fields.push( | 
					
						
							| 
									
										
										
										
											2016-04-30 16:13:03 -07:00
										 |  |  |         new o.ClassField(fieldName, o.importType(this.view.genConfig.renderTypes.renderElement))); | 
					
						
							| 
									
										
										
										
											2016-04-18 13:24:42 -07:00
										 |  |  |     this.view.createMethod.addStmt(o.THIS_EXPR.prop(fieldName).set(createRenderNodeExpr).toStmt()); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     var renderNode = o.THIS_EXPR.prop(fieldName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     var compileElement = new CompileElement( | 
					
						
							|  |  |  |         parent, this.view, nodeIndex, renderNode, ast, component, directives, ast.providers, | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |         ast.hasViewContainer, false, ast.references, this.targetDependencies); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     this.view.nodes.push(compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  |     var compViewExpr: o.ReadPropExpr = null; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     if (isPresent(component)) { | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:23 -07:00
										 |  |  |       let nestedComponentIdentifier = | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |           new CompileIdentifierMetadata({name: getViewClassName(component, 0)}); | 
					
						
							| 
									
										
										
										
											2016-06-24 08:46:43 -07:00
										 |  |  |       this.targetDependencies.push( | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |           new ViewClassDependency(component.type, nestedComponentIdentifier)); | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  |       compViewExpr = o.THIS_EXPR.prop(`compView_${nodeIndex}`);  // fix highlighting: `
 | 
					
						
							|  |  |  |       this.view.fields.push(new o.ClassField( | 
					
						
							|  |  |  |           compViewExpr.name, | 
					
						
							|  |  |  |           o.importType(resolveIdentifier(Identifiers.AppView), [o.importType(component.type)]))); | 
					
						
							|  |  |  |       this.view.viewChildren.push(compViewExpr); | 
					
						
							| 
									
										
										
										
											2016-04-18 13:24:42 -07:00
										 |  |  |       compileElement.setComponentView(compViewExpr); | 
					
						
							| 
									
										
										
										
											2016-11-01 11:45:27 -07:00
										 |  |  |       this.view.createMethod.addStmt( | 
					
						
							|  |  |  |           compViewExpr | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |               .set(o.importExpr(nestedComponentIdentifier).instantiate([ | 
					
						
							| 
									
										
										
										
											2016-11-01 11:45:27 -07:00
										 |  |  |                 ViewProperties.viewUtils, o.THIS_EXPR, o.literal(nodeIndex), renderNode | 
					
						
							|  |  |  |               ])) | 
					
						
							|  |  |  |               .toStmt()); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     compileElement.beforeChildren(); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |     this._addRootNodeAndProject(compileElement); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     templateVisitAll(this, ast.children, compileElement); | 
					
						
							|  |  |  |     compileElement.afterChildren(this.view.nodes.length - nodeIndex - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isPresent(compViewExpr)) { | 
					
						
							|  |  |  |       this.view.createMethod.addStmt( | 
					
						
							| 
									
										
										
										
											2016-11-02 07:36:31 -07:00
										 |  |  |           compViewExpr.callMethod('create', [compileElement.getComponent()]).toStmt()); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitEmbeddedTemplate(ast: EmbeddedTemplateAst, parent: CompileElement): any { | 
					
						
							|  |  |  |     var nodeIndex = this.view.nodes.length; | 
					
						
							|  |  |  |     var fieldName = `_anchor_${nodeIndex}`; | 
					
						
							|  |  |  |     this.view.fields.push( | 
					
						
							| 
									
										
										
										
											2016-04-30 16:13:03 -07:00
										 |  |  |         new o.ClassField(fieldName, o.importType(this.view.genConfig.renderTypes.renderComment))); | 
					
						
							| 
									
										
										
										
											2016-04-18 13:24:42 -07:00
										 |  |  |     this.view.createMethod.addStmt( | 
					
						
							|  |  |  |         o.THIS_EXPR.prop(fieldName) | 
					
						
							|  |  |  |             .set(ViewProperties.renderer.callMethod( | 
					
						
							|  |  |  |                 'createTemplateAnchor', | 
					
						
							|  |  |  |                 [ | 
					
						
							|  |  |  |                   this._getParentRenderNode(parent), | 
					
						
							|  |  |  |                   this.view.createMethod.resetDebugInfoExpr(nodeIndex, ast) | 
					
						
							|  |  |  |                 ])) | 
					
						
							|  |  |  |             .toStmt()); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     var renderNode = o.THIS_EXPR.prop(fieldName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 19:52:24 -07:00
										 |  |  |     var templateVariableBindings = ast.variables.map( | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |         varAst => [varAst.value.length > 0 ? varAst.value : IMPLICIT_TEMPLATE_VAR, varAst.name]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var directives = ast.directives.map(directiveAst => directiveAst.directive); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     var compileElement = new CompileElement( | 
					
						
							|  |  |  |         parent, this.view, nodeIndex, renderNode, ast, null, directives, ast.providers, | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |         ast.hasViewContainer, true, ast.references, this.targetDependencies); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     this.view.nodes.push(compileElement); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.nestedViewCount++; | 
					
						
							|  |  |  |     var embeddedView = new CompileView( | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         this.view.component, this.view.genConfig, this.view.pipeMetas, o.NULL_EXPR, | 
					
						
							| 
									
										
										
										
											2016-09-23 16:37:04 -04:00
										 |  |  |         this.view.animations, this.view.viewIndex + this.nestedViewCount, compileElement, | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         templateVariableBindings); | 
					
						
							| 
									
										
										
										
											2016-04-27 11:22:44 -07:00
										 |  |  |     this.nestedViewCount += buildView(embeddedView, ast.children, this.targetDependencies); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     compileElement.beforeChildren(); | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  |     this._addRootNodeAndProject(compileElement); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     compileElement.afterChildren(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitAttr(ast: AttrAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitDirective(ast: DirectiveAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitEvent(ast: BoundEventAst, eventTargetAndNames: Map<string, BoundEventAst>): any { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 19:52:24 -07:00
										 |  |  |   visitReference(ast: ReferenceAst, ctx: any): any { return null; } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   visitVariable(ast: VariableAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any { return null; } | 
					
						
							|  |  |  |   visitElementProperty(ast: BoundElementPropertyAst, context: any): any { return null; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:31:04 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Walks up the nodes while the direct parent is a container. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Returns the outer container or the node itself when it is not a direct child of a container. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @internal | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function _getOuterContainerOrSelf(node: CompileNode): CompileNode { | 
					
						
							|  |  |  |   const view = node.view; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (_isNgContainer(node.parent, view)) { | 
					
						
							|  |  |  |     node = node.parent; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Walks up the nodes while they are container and returns the first parent which is not. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Returns the parent of the outer container or the node itself when it is not a container. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @internal | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function _getOuterContainerParentOrSelf(el: CompileElement): CompileElement { | 
					
						
							|  |  |  |   const view = el.view; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (_isNgContainer(el, view)) { | 
					
						
							|  |  |  |     el = el.parent; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return el; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function _isNgContainer(node: CompileNode, view: CompileView): boolean { | 
					
						
							|  |  |  |   return !node.isNull() && (<ElementAst>node.sourceAst).name === NG_CONTAINER_TAG && | 
					
						
							|  |  |  |       node.view === view; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | function _mergeHtmlAndDirectiveAttrs( | 
					
						
							| 
									
										
										
										
											2016-11-10 16:27:53 -08:00
										 |  |  |     declaredHtmlAttrs: {[key: string]: string}, directives: CompileDirectiveSummary[]): string[] { | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |   const mapResult: {[key: string]: string} = {}; | 
					
						
							|  |  |  |   Object.keys(declaredHtmlAttrs).forEach(key => { mapResult[key] = declaredHtmlAttrs[key]; }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   directives.forEach(directiveMeta => { | 
					
						
							| 
									
										
										
										
											2016-10-03 16:46:05 -07:00
										 |  |  |     Object.keys(directiveMeta.hostAttributes).forEach(name => { | 
					
						
							|  |  |  |       const value = directiveMeta.hostAttributes[name]; | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |       const prevValue = mapResult[name]; | 
					
						
							|  |  |  |       mapResult[name] = isPresent(prevValue) ? mergeAttributeValue(name, prevValue, value) : value; | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-10-19 09:17:36 -07:00
										 |  |  |   const arrResult: string[] = []; | 
					
						
							|  |  |  |   // Note: We need to sort to get a defined output order
 | 
					
						
							|  |  |  |   // for tests and for caching generated artifacts...
 | 
					
						
							|  |  |  |   Object.keys(mapResult).sort().forEach( | 
					
						
							|  |  |  |       (attrName) => { arrResult.push(attrName, mapResult[attrName]); }); | 
					
						
							|  |  |  |   return arrResult; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function _readHtmlAttrs(attrs: AttrAst[]): {[key: string]: string} { | 
					
						
							|  |  |  |   var htmlAttrs: {[key: string]: string} = {}; | 
					
						
							|  |  |  |   attrs.forEach((ast) => { htmlAttrs[ast.name] = ast.value; }); | 
					
						
							|  |  |  |   return htmlAttrs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function mergeAttributeValue(attrName: string, attrValue1: string, attrValue2: string): string { | 
					
						
							|  |  |  |   if (attrName == CLASS_ATTR || attrName == STYLE_ATTR) { | 
					
						
							|  |  |  |     return `${attrValue1} ${attrValue2}`; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return attrValue2; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createViewTopLevelStmts(view: CompileView, targetStatements: o.Statement[]) { | 
					
						
							|  |  |  |   var nodeDebugInfosVar: o.Expression = o.NULL_EXPR; | 
					
						
							|  |  |  |   if (view.genConfig.genDebugInfo) { | 
					
						
							| 
									
										
											  
											
												feat: security implementation in Angular 2.
Summary:
This adds basic security hooks to Angular 2.
* `SecurityContext` is a private API between core, compiler, and
  platform-browser. `SecurityContext` communicates what context a value is used
  in across template parser, compiler, and sanitization at runtime.
* `SanitizationService` is the bare bones interface to sanitize values for a
  particular context.
* `SchemaElementRegistry.securityContext(tagName, attributeOrPropertyName)`
  determines the security context for an attribute or property (it turns out
  attributes and properties match for the purposes of sanitization).
Based on these hooks:
* `DomSchemaElementRegistry` decides what sanitization applies in a particular
  context.
* `DomSanitizationService` implements `SanitizationService` and adds *Safe
  Value*s, i.e. the ability to mark a value as safe and not requiring further
  sanitization.
* `url_sanitizer` and `style_sanitizer` sanitize URLs and Styles, respectively
  (surprise!).
`DomSanitizationService` is the default implementation bound for browser
applications, in the three contexts (browser rendering, web worker rendering,
server side rendering).
BREAKING CHANGES:
*** SECURITY WARNING ***
Angular 2 Release Candidates do not implement proper contextual escaping yet.
Make sure to correctly escape all values that go into the DOM.
*** SECURITY WARNING ***
Reviewers: IgorMinar
Differential Revision: https://reviews.angular.io/D103
											
										 
											2016-04-29 16:04:08 -07:00
										 |  |  |     nodeDebugInfosVar = o.variable( | 
					
						
							| 
									
										
										
										
											2016-05-03 18:49:59 -07:00
										 |  |  |         `nodeDebugInfos_${view.component.type.name}${view.viewIndex}`);  // fix highlighting: `
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     targetStatements.push( | 
					
						
							|  |  |  |         (<o.ReadVarExpr>nodeDebugInfosVar) | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |             .set(o.literalArr( | 
					
						
							|  |  |  |                 view.nodes.map(createStaticNodeDebugInfo), | 
					
						
							|  |  |  |                 new o.ArrayType( | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |                     new o.ExternalType(resolveIdentifier(Identifiers.StaticNodeDebugInfo)), | 
					
						
							|  |  |  |                     [o.TypeModifier.Const]))) | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |             .toDeclStmt(null, [o.StmtModifier.Final])); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat: security implementation in Angular 2.
Summary:
This adds basic security hooks to Angular 2.
* `SecurityContext` is a private API between core, compiler, and
  platform-browser. `SecurityContext` communicates what context a value is used
  in across template parser, compiler, and sanitization at runtime.
* `SanitizationService` is the bare bones interface to sanitize values for a
  particular context.
* `SchemaElementRegistry.securityContext(tagName, attributeOrPropertyName)`
  determines the security context for an attribute or property (it turns out
  attributes and properties match for the purposes of sanitization).
Based on these hooks:
* `DomSchemaElementRegistry` decides what sanitization applies in a particular
  context.
* `DomSanitizationService` implements `SanitizationService` and adds *Safe
  Value*s, i.e. the ability to mark a value as safe and not requiring further
  sanitization.
* `url_sanitizer` and `style_sanitizer` sanitize URLs and Styles, respectively
  (surprise!).
`DomSanitizationService` is the default implementation bound for browser
applications, in the three contexts (browser rendering, web worker rendering,
server side rendering).
BREAKING CHANGES:
*** SECURITY WARNING ***
Angular 2 Release Candidates do not implement proper contextual escaping yet.
Make sure to correctly escape all values that go into the DOM.
*** SECURITY WARNING ***
Reviewers: IgorMinar
Differential Revision: https://reviews.angular.io/D103
											
										 
											2016-04-29 16:04:08 -07:00
										 |  |  |   var renderCompTypeVar: o.ReadVarExpr = | 
					
						
							|  |  |  |       o.variable(`renderType_${view.component.type.name}`);  // fix highlighting: `
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   if (view.viewIndex === 0) { | 
					
						
							| 
									
										
										
										
											2016-11-02 08:11:10 -07:00
										 |  |  |     let templateUrlInfo: string; | 
					
						
							|  |  |  |     if (view.component.template.templateUrl == view.component.type.moduleUrl) { | 
					
						
							|  |  |  |       templateUrlInfo = | 
					
						
							|  |  |  |           `${view.component.type.moduleUrl} class ${view.component.type.name} - inline template`; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       templateUrlInfo = view.component.template.templateUrl; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |     targetStatements.push( | 
					
						
							| 
									
										
										
										
											2016-11-02 08:11:10 -07:00
										 |  |  |         renderCompTypeVar | 
					
						
							|  |  |  |             .set(o.importExpr(resolveIdentifier(Identifiers.createRenderComponentType)).callFn([ | 
					
						
							|  |  |  |               view.genConfig.genDebugInfo ? o.literal(templateUrlInfo) : o.literal(''), | 
					
						
							|  |  |  |               o.literal(view.component.template.ngContentSelectors.length), | 
					
						
							|  |  |  |               ViewEncapsulationEnum.fromValue(view.component.template.encapsulation), | 
					
						
							|  |  |  |               view.styles, | 
					
						
							|  |  |  |               o.literalMap(view.animations.map( | 
					
						
							|  |  |  |                   (entry): [string, o.Expression] => [entry.name, entry.fnExp])), | 
					
						
							|  |  |  |             ])) | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |             .toDeclStmt(o.importType(resolveIdentifier(Identifiers.RenderComponentType)))); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var viewClass = createViewClass(view, renderCompTypeVar, nodeDebugInfosVar); | 
					
						
							|  |  |  |   targetStatements.push(viewClass); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createStaticNodeDebugInfo(node: CompileNode): o.Expression { | 
					
						
							|  |  |  |   var compileElement = node instanceof CompileElement ? node : null; | 
					
						
							|  |  |  |   var providerTokens: o.Expression[] = []; | 
					
						
							|  |  |  |   var componentToken: o.Expression = o.NULL_EXPR; | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |   var varTokenEntries: any[] = []; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   if (isPresent(compileElement)) { | 
					
						
							|  |  |  |     providerTokens = compileElement.getProviderTokens(); | 
					
						
							|  |  |  |     if (isPresent(compileElement.component)) { | 
					
						
							|  |  |  |       componentToken = createDiTokenExpression(identifierToken(compileElement.component.type)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-03 16:46:05 -07:00
										 |  |  |     Object.keys(compileElement.referenceTokens).forEach(varName => { | 
					
						
							|  |  |  |       const token = compileElement.referenceTokens[varName]; | 
					
						
							|  |  |  |       varTokenEntries.push( | 
					
						
							|  |  |  |           [varName, isPresent(token) ? createDiTokenExpression(token) : o.NULL_EXPR]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |   return o.importExpr(resolveIdentifier(Identifiers.StaticNodeDebugInfo)) | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       .instantiate( | 
					
						
							|  |  |  |           [ | 
					
						
							|  |  |  |             o.literalArr(providerTokens, new o.ArrayType(o.DYNAMIC_TYPE, [o.TypeModifier.Const])), | 
					
						
							|  |  |  |             componentToken, | 
					
						
							|  |  |  |             o.literalMap(varTokenEntries, new o.MapType(o.DYNAMIC_TYPE, [o.TypeModifier.Const])) | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |           o.importType( | 
					
						
							|  |  |  |               resolveIdentifier(Identifiers.StaticNodeDebugInfo), null, [o.TypeModifier.Const])); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | function createViewClass( | 
					
						
							|  |  |  |     view: CompileView, renderCompTypeVar: o.ReadVarExpr, | 
					
						
							|  |  |  |     nodeDebugInfosVar: o.Expression): o.ClassStmt { | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   var viewConstructorArgs = [ | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |     new o.FnParam( | 
					
						
							|  |  |  |         ViewConstructorVars.viewUtils.name, o.importType(resolveIdentifier(Identifiers.ViewUtils))), | 
					
						
							|  |  |  |     new o.FnParam( | 
					
						
							| 
									
										
										
										
											2016-11-01 09:35:03 -07:00
										 |  |  |         ViewConstructorVars.parentView.name, | 
					
						
							|  |  |  |         o.importType(resolveIdentifier(Identifiers.AppView), [o.DYNAMIC_TYPE])), | 
					
						
							|  |  |  |     new o.FnParam(ViewConstructorVars.parentIndex.name, o.NUMBER_TYPE), | 
					
						
							|  |  |  |     new o.FnParam(ViewConstructorVars.parentElement.name, o.DYNAMIC_TYPE) | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2016-04-29 09:11:57 -07:00
										 |  |  |   var superConstructorArgs = [ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     o.variable(view.className), renderCompTypeVar, ViewTypeEnum.fromValue(view.viewType), | 
					
						
							| 
									
										
										
										
											2016-11-01 11:45:27 -07:00
										 |  |  |     ViewConstructorVars.viewUtils, ViewConstructorVars.parentView, ViewConstructorVars.parentIndex, | 
					
						
							| 
									
										
										
										
											2016-11-01 09:35:03 -07:00
										 |  |  |     ViewConstructorVars.parentElement, | 
					
						
							| 
									
										
										
										
											2016-06-27 20:00:30 -07:00
										 |  |  |     ChangeDetectorStatusEnum.fromValue(getChangeDetectionMode(view)) | 
					
						
							| 
									
										
										
										
											2016-04-29 09:11:57 -07:00
										 |  |  |   ]; | 
					
						
							|  |  |  |   if (view.genConfig.genDebugInfo) { | 
					
						
							|  |  |  |     superConstructorArgs.push(nodeDebugInfosVar); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-03 15:32:44 -07:00
										 |  |  |   if (view.viewType === ViewType.EMBEDDED) { | 
					
						
							|  |  |  |     viewConstructorArgs.push(new o.FnParam( | 
					
						
							|  |  |  |         'declaredViewContainer', o.importType(resolveIdentifier(Identifiers.ViewContainer)))); | 
					
						
							|  |  |  |     superConstructorArgs.push(o.variable('declaredViewContainer')); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   var viewMethods = [ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     new o.ClassMethod( | 
					
						
							|  |  |  |         'createInternal', [new o.FnParam(rootSelectorVar.name, o.STRING_TYPE)], | 
					
						
							| 
									
										
										
										
											2016-11-02 07:36:31 -07:00
										 |  |  |         generateCreateMethod(view), | 
					
						
							|  |  |  |         o.importType(resolveIdentifier(Identifiers.ComponentRef), [o.DYNAMIC_TYPE])), | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     new o.ClassMethod( | 
					
						
							|  |  |  |         'injectorGetInternal', | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           new o.FnParam(InjectMethodVars.token.name, o.DYNAMIC_TYPE), | 
					
						
							|  |  |  |           // Note: Can't use o.INT_TYPE here as the method in AppView uses number
 | 
					
						
							|  |  |  |           new o.FnParam(InjectMethodVars.requestNodeIndex.name, o.NUMBER_TYPE), | 
					
						
							|  |  |  |           new o.FnParam(InjectMethodVars.notFoundResult.name, o.DYNAMIC_TYPE) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         addReturnValuefNotEmpty(view.injectorGetMethod.finish(), InjectMethodVars.notFoundResult), | 
					
						
							|  |  |  |         o.DYNAMIC_TYPE), | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     new o.ClassMethod( | 
					
						
							|  |  |  |         'detectChangesInternal', [new o.FnParam(DetectChangesVars.throwOnChange.name, o.BOOL_TYPE)], | 
					
						
							|  |  |  |         generateDetectChangesMethod(view)), | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     new o.ClassMethod('dirtyParentQueriesInternal', [], view.dirtyParentQueriesMethod.finish()), | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  |     new o.ClassMethod('destroyInternal', [], generateDestroyMethod(view)), | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |     new o.ClassMethod('detachInternal', [], view.detachMethod.finish()), | 
					
						
							| 
									
										
										
										
											2016-11-01 10:29:25 -07:00
										 |  |  |     generateVisitRootNodesMethod(view), generateVisitProjectableNodesMethod(view), | 
					
						
							|  |  |  |     generateCreateEmbeddedViewsMethod(view) | 
					
						
							| 
									
										
										
										
											2016-10-21 13:37:51 -07:00
										 |  |  |   ].filter((method) => method.body.length > 0); | 
					
						
							| 
									
										
										
										
											2016-04-29 09:11:57 -07:00
										 |  |  |   var superClass = view.genConfig.genDebugInfo ? Identifiers.DebugAppView : Identifiers.AppView; | 
					
						
							| 
									
										
										
										
											2016-10-21 13:37:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   var viewClass = createClassStmt({ | 
					
						
							|  |  |  |     name: view.className, | 
					
						
							|  |  |  |     parent: o.importExpr(resolveIdentifier(superClass), [getContextType(view)]), | 
					
						
							|  |  |  |     parentArgs: superConstructorArgs, | 
					
						
							|  |  |  |     ctorParams: viewConstructorArgs, | 
					
						
							|  |  |  |     builders: [{methods: viewMethods}, view] | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   return viewClass; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  | function generateDestroyMethod(view: CompileView): o.Statement[] { | 
					
						
							|  |  |  |   const stmts: o.Statement[] = []; | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |   view.viewContainers.forEach((viewContainer) => { | 
					
						
							|  |  |  |     stmts.push(viewContainer.callMethod('destroyNestedViews', []).toStmt()); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  |   view.viewChildren.forEach( | 
					
						
							|  |  |  |       (viewChild) => { stmts.push(viewChild.callMethod('destroy', []).toStmt()); }); | 
					
						
							|  |  |  |   stmts.push(...view.destroyMethod.finish()); | 
					
						
							|  |  |  |   return stmts; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | function generateCreateMethod(view: CompileView): o.Statement[] { | 
					
						
							|  |  |  |   var parentRenderNodeExpr: o.Expression = o.NULL_EXPR; | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |   var parentRenderNodeStmts: any[] = []; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   if (view.viewType === ViewType.COMPONENT) { | 
					
						
							| 
									
										
										
										
											2016-11-01 09:35:03 -07:00
										 |  |  |     parentRenderNodeExpr = | 
					
						
							|  |  |  |         ViewProperties.renderer.callMethod('createViewRoot', [o.THIS_EXPR.prop('parentElement')]); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     parentRenderNodeStmts = | 
					
						
							|  |  |  |         [parentRenderNodeVar.set(parentRenderNodeExpr) | 
					
						
							|  |  |  |              .toDeclStmt( | 
					
						
							|  |  |  |                  o.importType(view.genConfig.renderTypes.renderNode), [o.StmtModifier.Final])]; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-13 17:05:17 -07:00
										 |  |  |   var resultExpr: o.Expression; | 
					
						
							|  |  |  |   if (view.viewType === ViewType.HOST) { | 
					
						
							| 
									
										
										
										
											2016-11-01 08:21:39 -07:00
										 |  |  |     const hostEl = <CompileElement>view.nodes[0]; | 
					
						
							| 
									
										
										
										
											2016-11-02 07:36:31 -07:00
										 |  |  |     resultExpr = | 
					
						
							|  |  |  |         o.importExpr(resolveIdentifier(Identifiers.ComponentRef_), [o.DYNAMIC_TYPE]).instantiate([ | 
					
						
							|  |  |  |           o.literal(hostEl.nodeIndex), o.THIS_EXPR, hostEl.renderNode, hostEl.getComponent() | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2016-04-13 17:05:17 -07:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     resultExpr = o.NULL_EXPR; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-02 17:54:05 -07:00
										 |  |  |   let allNodesExpr: o.Expression = | 
					
						
							| 
									
										
										
										
											2016-11-03 11:16:28 -07:00
										 |  |  |       ViewProperties.renderer.cast(o.DYNAMIC_TYPE) | 
					
						
							|  |  |  |           .prop('directRenderer') | 
					
						
							| 
									
										
										
										
											2016-11-02 17:54:05 -07:00
										 |  |  |           .conditional(o.NULL_EXPR, o.literalArr(view.nodes.map(node => node.renderNode))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |   return parentRenderNodeStmts.concat(view.createMethod.finish(), [ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     o.THIS_EXPR | 
					
						
							|  |  |  |         .callMethod( | 
					
						
							|  |  |  |             'init', | 
					
						
							|  |  |  |             [ | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  |               view.lastRenderNode, | 
					
						
							| 
									
										
										
										
											2016-11-02 17:54:05 -07:00
										 |  |  |               allNodesExpr, | 
					
						
							| 
									
										
										
										
											2016-10-31 15:38:15 -07:00
										 |  |  |               view.disposables.length ? o.literalArr(view.disposables) : o.NULL_EXPR, | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |             ]) | 
					
						
							|  |  |  |         .toStmt(), | 
					
						
							|  |  |  |     new o.ReturnStatement(resultExpr) | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function generateDetectChangesMethod(view: CompileView): o.Statement[] { | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |   var stmts: any[] = []; | 
					
						
							| 
									
										
										
										
											2016-09-01 23:24:26 +03:00
										 |  |  |   if (view.animationBindingsMethod.isEmpty() && view.detectChangesInInputsMethod.isEmpty() && | 
					
						
							|  |  |  |       view.updateContentQueriesMethod.isEmpty() && | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       view.afterContentLifecycleCallbacksMethod.isEmpty() && | 
					
						
							| 
									
										
										
										
											2016-04-20 18:10:19 -07:00
										 |  |  |       view.detectChangesRenderPropertiesMethod.isEmpty() && | 
					
						
							| 
									
										
										
										
											2016-11-04 08:51:16 -07:00
										 |  |  |       view.updateViewQueriesMethod.isEmpty() && view.afterViewLifecycleCallbacksMethod.isEmpty() && | 
					
						
							|  |  |  |       view.viewContainers.length === 0 && view.viewChildren.length === 0) { | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     return stmts; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-10-21 15:14:44 -07:00
										 |  |  |   stmts.push(...view.animationBindingsMethod.finish()); | 
					
						
							|  |  |  |   stmts.push(...view.detectChangesInInputsMethod.finish()); | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |   view.viewContainers.forEach((viewContainer) => { | 
					
						
							| 
									
										
										
										
											2016-10-31 10:31:48 -07:00
										 |  |  |     stmts.push( | 
					
						
							| 
									
										
										
										
											2016-11-01 11:12:25 -07:00
										 |  |  |         viewContainer.callMethod('detectChangesInNestedViews', [DetectChangesVars.throwOnChange]) | 
					
						
							| 
									
										
										
										
											2016-10-31 10:31:48 -07:00
										 |  |  |             .toStmt()); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   var afterContentStmts = view.updateContentQueriesMethod.finish().concat( | 
					
						
							|  |  |  |       view.afterContentLifecycleCallbacksMethod.finish()); | 
					
						
							|  |  |  |   if (afterContentStmts.length > 0) { | 
					
						
							|  |  |  |     stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterContentStmts)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-10-21 15:14:44 -07:00
										 |  |  |   stmts.push(...view.detectChangesRenderPropertiesMethod.finish()); | 
					
						
							| 
									
										
										
										
											2016-10-31 10:10:13 -07:00
										 |  |  |   view.viewChildren.forEach((viewChild) => { | 
					
						
							|  |  |  |     stmts.push(viewChild.callMethod('detectChanges', [DetectChangesVars.throwOnChange]).toStmt()); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   var afterViewStmts = | 
					
						
							|  |  |  |       view.updateViewQueriesMethod.finish().concat(view.afterViewLifecycleCallbacksMethod.finish()); | 
					
						
							|  |  |  |   if (afterViewStmts.length > 0) { | 
					
						
							|  |  |  |     stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterViewStmts)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 14:53:01 -07:00
										 |  |  |   var varStmts: any[] = []; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   var readVars = o.findReadVarNames(stmts); | 
					
						
							| 
									
										
										
										
											2016-09-18 15:39:26 -07:00
										 |  |  |   if (readVars.has(DetectChangesVars.changed.name)) { | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     varStmts.push(DetectChangesVars.changed.set(o.literal(true)).toDeclStmt(o.BOOL_TYPE)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-09-18 15:39:26 -07:00
										 |  |  |   if (readVars.has(DetectChangesVars.changes.name)) { | 
					
						
							| 
									
										
										
										
											2016-08-24 17:39:49 -07:00
										 |  |  |     varStmts.push( | 
					
						
							|  |  |  |         DetectChangesVars.changes.set(o.NULL_EXPR) | 
					
						
							|  |  |  |             .toDeclStmt(new o.MapType(o.importType(resolveIdentifier(Identifiers.SimpleChange))))); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-10-19 13:18:33 -07:00
										 |  |  |   varStmts.push(...createSharedBindingVariablesIfNeeded(stmts)); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   return varStmts.concat(stmts); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function addReturnValuefNotEmpty(statements: o.Statement[], value: o.Expression): o.Statement[] { | 
					
						
							|  |  |  |   if (statements.length > 0) { | 
					
						
							|  |  |  |     return statements.concat([new o.ReturnStatement(value)]); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return statements; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getContextType(view: CompileView): o.Type { | 
					
						
							| 
									
										
										
										
											2016-04-28 14:00:31 -07:00
										 |  |  |   if (view.viewType === ViewType.COMPONENT) { | 
					
						
							|  |  |  |     return o.importType(view.component.type); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return o.DYNAMIC_TYPE; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 20:00:30 -07:00
										 |  |  | function getChangeDetectionMode(view: CompileView): ChangeDetectorStatus { | 
					
						
							|  |  |  |   var mode: ChangeDetectorStatus; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   if (view.viewType === ViewType.COMPONENT) { | 
					
						
							|  |  |  |     mode = isDefaultChangeDetectionStrategy(view.component.changeDetection) ? | 
					
						
							| 
									
										
										
										
											2016-06-27 20:00:30 -07:00
										 |  |  |         ChangeDetectorStatus.CheckAlways : | 
					
						
							|  |  |  |         ChangeDetectorStatus.CheckOnce; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-06-27 20:00:30 -07:00
										 |  |  |     mode = ChangeDetectorStatus.CheckAlways; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   return mode; | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-31 14:41:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | function generateVisitRootNodesMethod(view: CompileView): o.ClassMethod { | 
					
						
							|  |  |  |   const cbVar = o.variable('cb'); | 
					
						
							|  |  |  |   const ctxVar = o.variable('ctx'); | 
					
						
							|  |  |  |   const stmts: o.Statement[] = generateVisitNodesStmts(view.rootNodes, cbVar, ctxVar); | 
					
						
							|  |  |  |   return new o.ClassMethod( | 
					
						
							|  |  |  |       'visitRootNodesInternal', | 
					
						
							|  |  |  |       [new o.FnParam(cbVar.name, o.DYNAMIC_TYPE), new o.FnParam(ctxVar.name, o.DYNAMIC_TYPE)], | 
					
						
							|  |  |  |       stmts); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function generateVisitProjectableNodesMethod(view: CompileView): o.ClassMethod { | 
					
						
							|  |  |  |   const nodeIndexVar = o.variable('nodeIndex'); | 
					
						
							|  |  |  |   const ngContentIndexVar = o.variable('ngContentIndex'); | 
					
						
							|  |  |  |   const cbVar = o.variable('cb'); | 
					
						
							|  |  |  |   const ctxVar = o.variable('ctx'); | 
					
						
							|  |  |  |   const stmts: o.Statement[] = []; | 
					
						
							|  |  |  |   view.nodes.forEach((node) => { | 
					
						
							|  |  |  |     if (node instanceof CompileElement && node.component) { | 
					
						
							|  |  |  |       node.contentNodesByNgContentIndex.forEach((projectedNodes, ngContentIndex) => { | 
					
						
							|  |  |  |         stmts.push(new o.IfStmt( | 
					
						
							|  |  |  |             nodeIndexVar.equals(o.literal(node.nodeIndex)) | 
					
						
							|  |  |  |                 .and(ngContentIndexVar.equals(o.literal(ngContentIndex))), | 
					
						
							|  |  |  |             generateVisitNodesStmts(projectedNodes, cbVar, ctxVar))); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return new o.ClassMethod( | 
					
						
							|  |  |  |       'visitProjectableNodesInternal', | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         new o.FnParam(nodeIndexVar.name, o.NUMBER_TYPE), | 
					
						
							|  |  |  |         new o.FnParam(ngContentIndexVar.name, o.NUMBER_TYPE), | 
					
						
							|  |  |  |         new o.FnParam(cbVar.name, o.DYNAMIC_TYPE), new o.FnParam(ctxVar.name, o.DYNAMIC_TYPE) | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       stmts); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function generateVisitNodesStmts( | 
					
						
							|  |  |  |     nodes: CompileViewRootNode[], cb: o.Expression, ctx: o.Expression): o.Statement[] { | 
					
						
							|  |  |  |   const stmts: o.Statement[] = []; | 
					
						
							|  |  |  |   nodes.forEach((node) => { | 
					
						
							|  |  |  |     switch (node.type) { | 
					
						
							|  |  |  |       case CompileViewRootNodeType.Node: | 
					
						
							|  |  |  |         stmts.push(cb.callFn([node.expr, ctx]).toStmt()); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case CompileViewRootNodeType.ViewContainer: | 
					
						
							|  |  |  |         stmts.push(cb.callFn([node.expr.prop('nativeElement'), ctx]).toStmt()); | 
					
						
							|  |  |  |         stmts.push(node.expr.callMethod('visitNestedViewRootNodes', [cb, ctx]).toStmt()); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case CompileViewRootNodeType.NgContent: | 
					
						
							|  |  |  |         stmts.push( | 
					
						
							|  |  |  |             o.THIS_EXPR.callMethod('visitProjectedNodes', [o.literal(node.ngContentIndex), cb, ctx]) | 
					
						
							|  |  |  |                 .toStmt()); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return stmts; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-11-01 10:29:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 15:32:44 -07:00
										 |  |  | function generateCreateEmbeddedViewsMethod(view: CompileView): o.ClassMethod { | 
					
						
							| 
									
										
										
										
											2016-11-01 10:29:25 -07:00
										 |  |  |   const nodeIndexVar = o.variable('nodeIndex'); | 
					
						
							|  |  |  |   const stmts: o.Statement[] = []; | 
					
						
							|  |  |  |   view.nodes.forEach((node) => { | 
					
						
							|  |  |  |     if (node instanceof CompileElement) { | 
					
						
							|  |  |  |       if (node.embeddedView) { | 
					
						
							|  |  |  |         const parentNodeIndex = node.isRootElement() ? null : node.parent.nodeIndex; | 
					
						
							|  |  |  |         stmts.push(new o.IfStmt( | 
					
						
							|  |  |  |             nodeIndexVar.equals(o.literal(node.nodeIndex)), | 
					
						
							| 
									
										
										
										
											2016-11-02 08:36:23 -07:00
										 |  |  |             [new o.ReturnStatement(node.embeddedView.classExpr.instantiate([ | 
					
						
							| 
									
										
										
										
											2016-11-03 15:32:44 -07:00
										 |  |  |               ViewProperties.viewUtils, o.THIS_EXPR, o.literal(node.nodeIndex), node.renderNode, | 
					
						
							|  |  |  |               node.viewContainer | 
					
						
							| 
									
										
										
										
											2016-11-01 10:29:25 -07:00
										 |  |  |             ]))])); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-11-03 15:32:44 -07:00
										 |  |  |   if (stmts.length > 0) { | 
					
						
							|  |  |  |     stmts.push(new o.ReturnStatement(o.NULL_EXPR)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-01 10:29:25 -07:00
										 |  |  |   return new o.ClassMethod( | 
					
						
							|  |  |  |       'createEmbeddedViewInternal', [new o.FnParam(nodeIndexVar.name, o.NUMBER_TYPE)], stmts, | 
					
						
							|  |  |  |       o.importType(resolveIdentifier(Identifiers.AppView), [o.DYNAMIC_TYPE])); | 
					
						
							|  |  |  | } |