1
+ /// <reference path="..\compiler\transformer.ts"/>
2
+ /// <reference path="transpile.ts"/>
3
+ namespace ts {
4
+ /**
5
+ * Transform one or more source files using the supplied transformers.
6
+ * @param source A `SourceFile` or an array of `SourceFiles`.
7
+ * @param transformers An array of `Transformer` callbacks used to process the transformation.
8
+ */
9
+ export function transform ( source : SourceFile | SourceFile [ ] , transformers : Transformer [ ] ) {
10
+ const diagnostics : Diagnostic [ ] = [ ] ;
11
+ const compilerOptions : CompilerOptions = { } ;
12
+ const sourceFiles = isArray ( source ) ? source : [ source ] ;
13
+ const fileMap = arrayToMap ( sourceFiles , sourceFile => sourceFile . fileName ) ;
14
+ const emitHost : EmitHost = {
15
+ getCompilerOptions : ( ) => compilerOptions ,
16
+ getCanonicalFileName : fileName => fileName ,
17
+ getCommonSourceDirectory : ( ) => "" ,
18
+ getCurrentDirectory : ( ) => "" ,
19
+ getNewLine : ( ) => "\n" ,
20
+ getSourceFile : fileName => fileMap . get ( fileName ) ,
21
+ getSourceFileByPath : fileName => fileMap . get ( fileName ) ,
22
+ getSourceFiles : ( ) => sourceFiles ,
23
+ isSourceFileFromExternalLibrary : ( ) => false ,
24
+ isEmitBlocked : ( ) => false ,
25
+ writeFile : ( ) => Debug . fail ( "'writeFile()' is not supported during transformation." )
26
+ } ;
27
+ return transformFiles ( /*resolver*/ undefined , emitHost , sourceFiles , transformers ) ;
28
+ }
29
+ }
0 commit comments