fix(compiler): emit preamble in generated files.
This commit is contained in:
parent
5ef6e6366f
commit
b1055a5edb
|
@ -24,19 +24,21 @@ export class TypeScriptNodeEmitter {
|
||||||
// stmts.
|
// stmts.
|
||||||
const statements: any[] = [].concat(
|
const statements: any[] = [].concat(
|
||||||
...stmts.map(stmt => stmt.visitStatement(converter, null)).filter(stmt => stmt != null));
|
...stmts.map(stmt => stmt.visitStatement(converter, null)).filter(stmt => stmt != null));
|
||||||
const newSourceFile = ts.updateSourceFileNode(
|
const preambleStmts: ts.Statement[] = [];
|
||||||
sourceFile, [...converter.getReexports(), ...converter.getImports(), ...statements]);
|
|
||||||
if (preamble) {
|
if (preamble) {
|
||||||
if (preamble.startsWith('/*') && preamble.endsWith('*/')) {
|
if (preamble.startsWith('/*') && preamble.endsWith('*/')) {
|
||||||
preamble = preamble.substr(2, preamble.length - 4);
|
preamble = preamble.substr(2, preamble.length - 4);
|
||||||
}
|
}
|
||||||
if (!statements.length) {
|
const commentStmt = ts.createNotEmittedStatement(sourceFile);
|
||||||
statements.push(ts.createEmptyStatement());
|
ts.setSyntheticLeadingComments(
|
||||||
}
|
commentStmt,
|
||||||
statements[0] = ts.setSyntheticLeadingComments(
|
|
||||||
statements[0],
|
|
||||||
[{kind: ts.SyntaxKind.MultiLineCommentTrivia, text: preamble, pos: -1, end: -1}]);
|
[{kind: ts.SyntaxKind.MultiLineCommentTrivia, text: preamble, pos: -1, end: -1}]);
|
||||||
|
ts.setEmitFlags(commentStmt, ts.EmitFlags.CustomPrologue);
|
||||||
|
preambleStmts.push(commentStmt);
|
||||||
}
|
}
|
||||||
|
const newSourceFile = ts.updateSourceFileNode(
|
||||||
|
sourceFile,
|
||||||
|
[...preambleStmts, ...converter.getReexports(), ...converter.getImports(), ...statements]);
|
||||||
return [newSourceFile, converter.getNodeMap()];
|
return [newSourceFile, converter.getNodeMap()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,13 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {TypeScriptNodeEmitter} from './node_emitter';
|
import {TypeScriptNodeEmitter} from './node_emitter';
|
||||||
|
|
||||||
|
const PREAMBLE = `/**
|
||||||
|
* @fileoverview This file is generated by the Angular template compiler.
|
||||||
|
* Do not edit.
|
||||||
|
* @suppress {suspiciousCode,uselessCode,missingProperties,missingOverride}
|
||||||
|
* tslint:disable
|
||||||
|
*/`;
|
||||||
|
|
||||||
export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[]): () =>
|
export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[]): () =>
|
||||||
(sourceFile: ts.SourceFile) => ts.SourceFile {
|
(sourceFile: ts.SourceFile) => ts.SourceFile {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -20,7 +27,7 @@ export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[
|
||||||
return function(sourceFile: ts.SourceFile): ts.SourceFile {
|
return function(sourceFile: ts.SourceFile): ts.SourceFile {
|
||||||
const g = map.get(sourceFile.fileName);
|
const g = map.get(sourceFile.fileName);
|
||||||
if (g && g.stmts) {
|
if (g && g.stmts) {
|
||||||
const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts);
|
const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts, PREAMBLE);
|
||||||
return newSourceFile;
|
return newSourceFile;
|
||||||
}
|
}
|
||||||
return sourceFile;
|
return sourceFile;
|
||||||
|
|
Loading…
Reference in New Issue