refactor(compiler): emit OutputAst and not sources (#16832)

This is in preparation for creating typescript nodes
directly from `OutputAst` nodes.
This commit is contained in:
Tobias Bosch
2017-05-17 11:21:08 -07:00
committed by Chuck Jazdzewski
parent 6123b9c0c6
commit de8d7c65f2
8 changed files with 102 additions and 70 deletions

View File

@ -33,8 +33,7 @@ export class AotCompiler {
private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler,
private _ngModuleCompiler: NgModuleCompiler, private _outputEmitter: OutputEmitter,
private _summaryResolver: SummaryResolver<StaticSymbol>, private _localeId: string|null,
private _translationFormat: string|null, private _genFilePreamble: string|null,
private _symbolResolver: StaticSymbolResolver) {}
private _translationFormat: string|null, private _symbolResolver: StaticSymbolResolver) {}
clearCache() { this._metadataResolver.clearCache(); }
@ -273,10 +272,7 @@ export class AotCompiler {
}
private _codegenSourceModule(srcFileUrl: string, ctx: OutputContext): GeneratedFile {
return new GeneratedFile(
srcFileUrl, ctx.genFilePath,
this._outputEmitter.emitStatements(
sourceUrl(srcFileUrl), ctx.genFilePath, ctx.statements, this._genFilePreamble));
return new GeneratedFile(srcFileUrl, ctx.genFilePath, ctx.statements);
}
}

View File

@ -72,6 +72,6 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
const compiler = new AotCompiler(
config, compilerHost, resolver, tmplParser, new StyleCompiler(urlResolver), viewCompiler,
new NgModuleCompiler(), new TypeScriptEmitter(), summaryResolver, options.locale || null,
options.i18nFormat || null, options.genFilePreamble || null, symbolResolver);
options.i18nFormat || null, symbolResolver);
return {compiler, reflector: staticReflector};
}

View File

@ -14,6 +14,4 @@ export interface AotCompilerOptions {
translations?: string;
missingTranslation?: MissingTranslationStrategy;
enableLegacyTemplate?: boolean;
/** preamble for all generated source files */
genFilePreamble?: string;
}

View File

@ -6,6 +6,30 @@
* found in the LICENSE file at https://angular.io/license
*/
import {sourceUrl} from '../compile_metadata';
import {Statement} from '../output/output_ast';
import {TypeScriptEmitter} from '../output/ts_emitter';
export class GeneratedFile {
constructor(public srcFileUrl: string, public genFileUrl: string, public source: string) {}
public source: string|null;
public stmts: Statement[]|null;
constructor(
public srcFileUrl: string, public genFileUrl: string, sourceOrStmts: string|Statement[]) {
if (typeof sourceOrStmts === 'string') {
this.source = sourceOrStmts;
this.stmts = null;
} else {
this.source = null;
this.stmts = sourceOrStmts;
}
}
}
export function toTypeScript(file: GeneratedFile, preamble: string = ''): string {
if (!file.stmts) {
throw new Error(`Illegal state: No stmts present on GeneratedFile ${file.genFileUrl}`);
}
return new TypeScriptEmitter().emitStatements(
sourceUrl(file.srcFileUrl), file.genFileUrl, file.stmts, preamble);
}