@@ -24,16 +24,17 @@ let compilerOptions = main.COMPILER_OPTIONS;
24
24
let defaultLibFileName = ts . getDefaultLibFileName ( compilerOptions ) ;
25
25
let libSourceFiles : Map < string , ts . SourceFile > = new Map ( ) ;
26
26
27
- export function parseFiles ( nameToContent : StringMap ) : ts . Program {
27
+ export function parseFiles (
28
+ nameToContent : StringMap , customCompilerOptions : ts . CompilerOptions ) : ts . Program {
28
29
let result : string ;
29
- let compilerHost = ts . createCompilerHost ( compilerOptions ) ;
30
+ let compilerHost = ts . createCompilerHost ( customCompilerOptions ) ;
30
31
compilerHost . getSourceFile = ( sourceName ) => {
31
32
let sourcePath = sourceName ;
32
33
if ( sourcePath === defaultLibFileName ) {
33
- sourcePath = ts . getDefaultLibFilePath ( compilerOptions ) ;
34
+ sourcePath = ts . getDefaultLibFilePath ( customCompilerOptions ) ;
34
35
} else if ( nameToContent . hasOwnProperty ( sourcePath ) ) {
35
36
return ts . createSourceFile (
36
- sourcePath , nameToContent [ sourcePath ] , compilerOptions . target , true ) ;
37
+ sourcePath , nameToContent [ sourcePath ] , customCompilerOptions . target , true ) ;
37
38
} else if ( ! fs . existsSync ( sourcePath ) ) {
38
39
return undefined ;
39
40
}
@@ -43,7 +44,7 @@ export function parseFiles(nameToContent: StringMap): ts.Program {
43
44
// Cache to avoid excessive test times.
44
45
libSourceFiles . set (
45
46
sourcePath ,
46
- ts . createSourceFile ( sourcePath , contents , main . COMPILER_OPTIONS . target , true ) ) ;
47
+ ts . createSourceFile ( sourcePath , contents , customCompilerOptions . target , true ) ) ;
47
48
}
48
49
return libSourceFiles . get ( sourcePath ) ;
49
50
} ;
@@ -61,7 +62,7 @@ export function parseFiles(nameToContent: StringMap): ts.Program {
61
62
62
63
// Create a program from inputs
63
64
let entryPoints = Object . keys ( nameToContent ) ;
64
- let program : ts . Program = ts . createProgram ( entryPoints , compilerOptions , compilerHost ) ;
65
+ let program : ts . Program = ts . createProgram ( entryPoints , customCompilerOptions , compilerHost ) ;
65
66
if ( program . getSyntacticDiagnostics ( ) . length > 0 ) {
66
67
// Throw first error.
67
68
let first = program . getSyntacticDiagnostics ( ) [ 0 ] ;
@@ -76,6 +77,7 @@ export function translateSources(contents: Input, options?: main.TranspilerOptio
76
77
options = options || { } ;
77
78
// Default to quick stack traces.
78
79
if ( ! options . hasOwnProperty ( 'failFast' ) ) options . failFast = true ;
80
+
79
81
let namesToContent : StringMap ;
80
82
if ( typeof contents === 'string' ) {
81
83
namesToContent = { } ;
@@ -85,7 +87,7 @@ export function translateSources(contents: Input, options?: main.TranspilerOptio
85
87
}
86
88
options . enforceUnderscoreConventions = true ;
87
89
let transpiler = new main . Transpiler ( options ) ;
88
- let program = parseFiles ( namesToContent ) ;
90
+ let program = parseFiles ( namesToContent , transpiler . getCompilerOptions ( ) ) ;
89
91
return transpiler . translateProgram ( program ) ;
90
92
}
91
93
0 commit comments