@@ -48,7 +48,6 @@ export interface TranspilationResult {
4848
4949export interface GetTranspilationResultOptions {
5050 program : ts . Program ;
51- options : CompilerOptions ;
5251 customTransformers ?: ts . CustomTransformers ;
5352 sourceFiles ?: ts . SourceFile [ ] ;
5453 printer ?: LuaPrinter ;
@@ -57,13 +56,14 @@ export interface GetTranspilationResultOptions {
5756
5857export function getTranspilationResult ( {
5958 program,
60- options,
6159 customTransformers = { } ,
6260 sourceFiles : targetSourceFiles ,
63- printer = new LuaPrinter ( options ) ,
64- transformer = new LuaTransformer ( program , options ) ,
61+ printer,
62+ transformer,
6563} : GetTranspilationResultOptions ) : TranspilationResult {
66- const { noEmit, emitDeclarationOnly, noEmitOnError } = options ;
64+ const options = program . getCompilerOptions ( ) ;
65+ printer = printer || new LuaPrinter ( options ) ;
66+ transformer = transformer || new LuaTransformer ( program , options ) ;
6767
6868 const diagnostics : ts . Diagnostic [ ] = [ ] ;
6969 const transpiledFiles = new Map < string , TranspiledFile > ( ) ;
@@ -75,7 +75,7 @@ export function getTranspilationResult({
7575 }
7676 } ;
7777
78- if ( noEmitOnError ) {
78+ if ( options . noEmitOnError ) {
7979 const preEmitDiagnostics = [
8080 ...program . getOptionsDiagnostics ( ) ,
8181 ...program . getGlobalDiagnostics ( ) ,
@@ -102,9 +102,9 @@ export function getTranspilationResult({
102102
103103 const processSourceFile = ( sourceFile : ts . SourceFile ) => {
104104 try {
105- const [ luaAST , lualibFeatureSet ] = transformer . transformSourceFile ( sourceFile ) ;
106- if ( ! noEmit && ! emitDeclarationOnly ) {
107- const [ lua , sourceMap ] = printer . print (
105+ const [ luaAST , lualibFeatureSet ] = transformer ! . transformSourceFile ( sourceFile ) ;
106+ if ( ! options . noEmit && ! options . emitDeclarationOnly ) {
107+ const [ lua , sourceMap ] = printer ! . print (
108108 luaAST ,
109109 lualibFeatureSet ,
110110 sourceFile . fileName
@@ -146,13 +146,12 @@ export function getTranspilationResult({
146146
147147 const isEmittableJsonFile = ( sourceFile : ts . SourceFile ) =>
148148 sourceFile . flags & ts . NodeFlags . JsonFile &&
149- ! emitDeclarationOnly &&
149+ ! options . emitDeclarationOnly &&
150150 ! program . isSourceFileFromExternalLibrary ( sourceFile ) ;
151151
152152 // We always have to emit to get transformer diagnostics
153- const programOptions = program . getCompilerOptions ( ) ;
154- const programNoEmit = programOptions . noEmit ;
155- programOptions . noEmit = false ;
153+ const oldNoEmit = options . noEmit ;
154+ options . noEmit = false ;
156155
157156 if ( targetSourceFiles ) {
158157 for ( const sourceFile of targetSourceFiles ) {
@@ -177,9 +176,9 @@ export function getTranspilationResult({
177176 . forEach ( processSourceFile ) ;
178177 }
179178
180- programOptions . noEmit = programNoEmit ;
179+ options . noEmit = oldNoEmit ;
181180
182- if ( noEmit || ( noEmitOnError && diagnostics . length > 0 ) ) {
181+ if ( options . noEmit || ( options . noEmitOnError && diagnostics . length > 0 ) ) {
183182 transpiledFiles . clear ( ) ;
184183 }
185184
0 commit comments