feat(compiler-cli): new compiler api and command-line using TypeScript transformers
This commit is contained in:

committed by
Matias Niemelä

parent
43c187b624
commit
3097083277
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {GeneratedFile} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {TypeScriptNodeEmitter} from './node_emitter';
|
||||
|
||||
export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[]): () =>
|
||||
(sourceFile: ts.SourceFile) => ts.SourceFile {
|
||||
return function() {
|
||||
const map = new Map(generatedFiles.filter(g => g.stmts && g.stmts.length)
|
||||
.map<[string, GeneratedFile]>(g => [g.genFileUrl, g]));
|
||||
const emitter = new TypeScriptNodeEmitter();
|
||||
return function(sourceFile: ts.SourceFile): ts.SourceFile {
|
||||
const g = map.get(sourceFile.fileName);
|
||||
if (g && g.stmts) {
|
||||
const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts);
|
||||
return newSourceFile;
|
||||
}
|
||||
return sourceFile;
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user