fix(compiler): emit preamble in generated files.
This commit is contained in:
		
							parent
							
								
									5ef6e6366f
								
							
						
					
					
						commit
						b1055a5edb
					
				| @ -24,19 +24,21 @@ export class TypeScriptNodeEmitter { | ||||
|     // stmts.
 | ||||
|     const statements: any[] = [].concat( | ||||
|         ...stmts.map(stmt => stmt.visitStatement(converter, null)).filter(stmt => stmt != null)); | ||||
|     const newSourceFile = ts.updateSourceFileNode( | ||||
|         sourceFile, [...converter.getReexports(), ...converter.getImports(), ...statements]); | ||||
|     const preambleStmts: ts.Statement[] = []; | ||||
|     if (preamble) { | ||||
|       if (preamble.startsWith('/*') && preamble.endsWith('*/')) { | ||||
|         preamble = preamble.substr(2, preamble.length - 4); | ||||
|       } | ||||
|       if (!statements.length) { | ||||
|         statements.push(ts.createEmptyStatement()); | ||||
|       } | ||||
|       statements[0] = ts.setSyntheticLeadingComments( | ||||
|           statements[0], | ||||
|       const commentStmt = ts.createNotEmittedStatement(sourceFile); | ||||
|       ts.setSyntheticLeadingComments( | ||||
|           commentStmt, | ||||
|           [{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()]; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -11,6 +11,13 @@ import * as ts from 'typescript'; | ||||
| 
 | ||||
| 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[]): () => | ||||
|     (sourceFile: ts.SourceFile) => ts.SourceFile { | ||||
|   return function() { | ||||
| @ -20,10 +27,10 @@ export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[ | ||||
|     return function(sourceFile: ts.SourceFile): ts.SourceFile { | ||||
|       const g = map.get(sourceFile.fileName); | ||||
|       if (g && g.stmts) { | ||||
|         const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts); | ||||
|         const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts, PREAMBLE); | ||||
|         return newSourceFile; | ||||
|       } | ||||
|       return sourceFile; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user