2016-04-28 17:50:03 -07:00
|
|
|
import {Injectable} from '@angular/core';
|
2016-01-06 14:13:44 -08:00
|
|
|
import * as o from '../output/output_ast';
|
|
|
|
import {CompileElement} from './compile_element';
|
|
|
|
import {CompileView} from './compile_view';
|
2016-04-27 11:22:44 -07:00
|
|
|
import {buildView, finishView, ViewCompileDependency} from './view_builder';
|
|
|
|
import {bindView} from './view_binder';
|
2016-01-06 14:13:44 -08:00
|
|
|
import {CompileDirectiveMetadata, CompilePipeMetadata} from '../compile_metadata';
|
|
|
|
import {TemplateAst} from '../template_ast';
|
|
|
|
import {CompilerConfig} from '../config';
|
|
|
|
|
2016-05-25 12:46:22 -07:00
|
|
|
import {AnimationCompiler} from '../animation/animation_compiler';
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
export class ViewCompileResult {
|
|
|
|
constructor(public statements: o.Statement[], public viewFactoryVar: string,
|
|
|
|
public dependencies: ViewCompileDependency[]) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ViewCompiler {
|
2016-05-25 12:46:22 -07:00
|
|
|
private _animationCompiler = new AnimationCompiler();
|
2016-01-06 14:13:44 -08:00
|
|
|
constructor(private _genConfig: CompilerConfig) {}
|
|
|
|
|
|
|
|
compileComponent(component: CompileDirectiveMetadata, template: TemplateAst[],
|
|
|
|
styles: o.Expression, pipes: CompilePipeMetadata[]): ViewCompileResult {
|
2016-06-08 15:45:15 -07:00
|
|
|
var dependencies: any[] /** TODO #9100 */ = [];
|
2016-05-25 12:46:22 -07:00
|
|
|
var compiledAnimations = this._animationCompiler.compileComponent(component);
|
2016-06-08 15:45:15 -07:00
|
|
|
var statements: any[] /** TODO #9100 */ = [];
|
2016-05-25 12:46:22 -07:00
|
|
|
compiledAnimations.map(entry => {
|
|
|
|
statements.push(entry.statesMapStatement);
|
|
|
|
statements.push(entry.fnStatement);
|
|
|
|
});
|
|
|
|
var view = new CompileView(component, this._genConfig, pipes, styles, compiledAnimations, 0,
|
2016-01-06 14:13:44 -08:00
|
|
|
CompileElement.createNull(), []);
|
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.
|
|
|
|
bindView(view, template);
|
|
|
|
finishView(view, statements);
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
return new ViewCompileResult(statements, view.viewFactory.name, dependencies);
|
|
|
|
}
|
|
|
|
}
|