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:

committed by
Chuck Jazdzewski

parent
6123b9c0c6
commit
de8d7c65f2
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user