@@ -4,8 +4,7 @@ import { CompilerOptions, validateOptions } from "../../CompilerOptions";
44import { createPrinter } from "../../LuaPrinter" ;
55import { createVisitorMap , transformSourceFile } from "../../transformation" ;
66import { assert , isNonNull } from "../../utils" ;
7- import { Module } from "../module" ;
8- import { TranspilerHost } from "../transpiler" ;
7+ import { Transpilation } from "../transpilation" ;
98import { getPlugins , Plugin } from "./plugins" ;
109import { getTransformers } from "./transformers" ;
1110
@@ -19,21 +18,16 @@ export interface TranspileOptions {
1918}
2019
2120export function emitProgramModules (
22- host : TranspilerHost ,
21+ transpilation : Transpilation ,
2322 writeFileResult : ts . WriteFileCallback ,
2423 { program, sourceFiles : targetSourceFiles , customTransformers = { } , plugins : customPlugins = [ ] } : TranspileOptions
2524) {
2625 const options = program . getCompilerOptions ( ) as CompilerOptions ;
2726
28- const diagnostics = validateOptions ( options ) ;
29- let modules : Module [ ] = [ ] ;
27+ transpilation . diagnostics . push ( ...validateOptions ( options ) ) ;
3028
3129 if ( options . noEmitOnError ) {
32- const preEmitDiagnostics = [
33- ...diagnostics ,
34- ...program . getOptionsDiagnostics ( ) ,
35- ...program . getGlobalDiagnostics ( ) ,
36- ] ;
30+ const preEmitDiagnostics = [ ...program . getOptionsDiagnostics ( ) , ...program . getGlobalDiagnostics ( ) ] ;
3731
3832 if ( targetSourceFiles ) {
3933 for ( const sourceFile of targetSourceFiles ) {
@@ -50,11 +44,12 @@ export function emitProgramModules(
5044 }
5145
5246 if ( preEmitDiagnostics . length > 0 ) {
53- return { diagnostics : preEmitDiagnostics , modules } ;
47+ transpilation . diagnostics . push ( ...preEmitDiagnostics ) ;
48+ return ;
5449 }
5550 }
5651
57- const plugins = getPlugins ( program , diagnostics , customPlugins ) ;
52+ const plugins = getPlugins ( transpilation , customPlugins ) ;
5853 const visitorMap = createVisitorMap ( plugins . map ( p => p . visitors ) . filter ( isNonNull ) ) ;
5954 const printer = createPrinter ( plugins . map ( p => p . printer ) . filter ( isNonNull ) ) ;
6055 const processSourceFile = ( sourceFile : ts . SourceFile ) => {
@@ -64,21 +59,21 @@ export function emitProgramModules(
6459 visitorMap
6560 ) ;
6661
67- diagnostics . push ( ...transformDiagnostics ) ;
62+ transpilation . diagnostics . push ( ...transformDiagnostics ) ;
6863 if ( ! options . noEmit && ! options . emitDeclarationOnly ) {
69- const printResult = printer ( program , host , sourceFile . fileName , luaAst , luaLibFeatures ) ;
64+ const printResult = printer ( program , transpilation . host , sourceFile . fileName , luaAst , luaLibFeatures ) ;
7065
7166 let fileName : string ;
7267 if ( path . isAbsolute ( sourceFile . fileName ) ) {
7368 fileName = sourceFile . fileName ;
7469 } else {
75- const currentDirectory = host . getCurrentDirectory ( ) ;
70+ const currentDirectory = transpilation . host . getCurrentDirectory ( ) ;
7671 // Having no absolute path in path.resolve would make it fallback to real cwd
7772 assert ( path . isAbsolute ( currentDirectory ) , `Invalid path: ${ currentDirectory } ` ) ;
7873 fileName = path . resolve ( currentDirectory , sourceFile . fileName ) ;
7974 }
8075
81- modules . push ( {
76+ transpilation . modules . push ( {
8277 sourceFiles : [ sourceFile ] ,
8378 request : fileName ,
8479 isBuilt : false ,
@@ -87,7 +82,7 @@ export function emitProgramModules(
8782 }
8883 } ;
8984
90- const transformers = getTransformers ( program , diagnostics , customTransformers , processSourceFile ) ;
85+ const transformers = getTransformers ( transpilation , customTransformers , processSourceFile ) ;
9186
9287 const isEmittableJsonFile = ( sourceFile : ts . SourceFile ) =>
9388 sourceFile . flags & ts . NodeFlags . JsonFile &&
@@ -109,21 +104,17 @@ export function emitProgramModules(
109104 if ( isEmittableJsonFile ( file ) ) {
110105 processSourceFile ( file ) ;
111106 } else {
112- diagnostics . push ( ...program . emit ( file , writeFile , undefined , false , transformers ) . diagnostics ) ;
107+ const { diagnostics } = program . emit ( file , writeFile , undefined , false , transformers ) ;
108+ transpilation . diagnostics . push ( ...diagnostics ) ;
113109 }
114110 }
115111 } else {
116- diagnostics . push ( ...program . emit ( undefined , writeFile , undefined , false , transformers ) . diagnostics ) ;
112+ const { diagnostics } = program . emit ( undefined , writeFile , undefined , false , transformers ) ;
113+ transpilation . diagnostics . push ( ...diagnostics ) ;
117114
118115 // JSON files don't get through transformers and aren't written when outDir is the same as rootDir
119116 program . getSourceFiles ( ) . filter ( isEmittableJsonFile ) . forEach ( processSourceFile ) ;
120117 }
121118
122119 options . noEmit = oldNoEmit ;
123-
124- if ( options . noEmit || ( options . noEmitOnError && diagnostics . length > 0 ) ) {
125- modules = [ ] ;
126- }
127-
128- return { diagnostics, modules } ;
129120}
0 commit comments