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-04-28 17:50:03 -07:00
|
|
|
import {Injectable} from '@angular/core';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
2016-10-18 17:16:51 -07:00
|
|
|
import {AnimationEntryCompileResult} from '../animation/animation_compiler';
|
2016-06-08 16:38:52 -07:00
|
|
|
import {CompileDirectiveMetadata, CompilePipeMetadata} from '../compile_metadata';
|
|
|
|
import {CompilerConfig} from '../config';
|
2016-01-06 14:13:44 -08:00
|
|
|
import * as o from '../output/output_ast';
|
2016-07-21 11:41:25 -07:00
|
|
|
import {TemplateAst} from '../template_parser/template_ast';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
import {CompileElement} from './compile_element';
|
|
|
|
import {CompileView} from './compile_view';
|
2016-10-13 16:34:37 -07:00
|
|
|
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
2016-04-27 11:22:44 -07:00
|
|
|
import {bindView} from './view_binder';
|
2016-10-13 16:34:37 -07:00
|
|
|
import {buildView, finishView} from './view_builder';
|
2016-06-22 14:06:23 -07:00
|
|
|
|
2016-10-13 16:34:37 -07:00
|
|
|
export {ComponentFactoryDependency, DirectiveWrapperDependency, ViewFactoryDependency} from './deps';
|
2016-05-25 12:46:22 -07:00
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
export class ViewCompileResult {
|
2016-06-08 16:38:52 -07:00
|
|
|
constructor(
|
|
|
|
public statements: o.Statement[], public viewFactoryVar: string,
|
2016-10-13 16:34:37 -07:00
|
|
|
public dependencies:
|
|
|
|
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency>) {}
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ViewCompiler {
|
|
|
|
constructor(private _genConfig: CompilerConfig) {}
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
compileComponent(
|
|
|
|
component: CompileDirectiveMetadata, template: TemplateAst[], styles: o.Expression,
|
2016-09-23 16:37:04 -04:00
|
|
|
pipes: CompilePipeMetadata[],
|
|
|
|
compiledAnimations: AnimationEntryCompileResult[]): ViewCompileResult {
|
2016-10-13 16:34:37 -07:00
|
|
|
const dependencies:
|
|
|
|
Array<ViewFactoryDependency|ComponentFactoryDependency|DirectiveWrapperDependency> = [];
|
2016-09-23 16:37:04 -04:00
|
|
|
const view = new CompileView(
|
|
|
|
component, this._genConfig, pipes, styles, compiledAnimations, 0,
|
2016-06-08 16:38:52 -07:00
|
|
|
CompileElement.createNull(), []);
|
2016-09-23 16:37:04 -04:00
|
|
|
|
|
|
|
const statements: o.Statement[] = [];
|
2016-04-27 11:22:44 -07:00
|
|
|
buildView(view, template, dependencies);
|
|
|
|
// Need to separate binding from creation to be able to refer to
|
|
|
|
// variables that have been declared after usage.
|
2016-09-23 16:37:04 -04:00
|
|
|
bindView(view, template);
|
2016-04-27 11:22:44 -07:00
|
|
|
finishView(view, statements);
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
return new ViewCompileResult(statements, view.viewFactory.name, dependencies);
|
|
|
|
}
|
|
|
|
}
|