@@ -4,6 +4,7 @@ import { CompilerOptions, isBundleEnabled } from "../CompilerOptions";
44import { getLuaLibBundle } from "../LuaLib" ;
55import { normalizeSlashes , trimExtension } from "../utils" ;
66import { getBundleResult } from "./bundle" ;
7+ import { getPlugins } from "./plugins" ;
78import { resolveDependencies } from "./resolve" ;
89import { getProgramTranspileResult , TranspileOptions } from "./transpile" ;
910import { EmitFile , EmitHost , ProcessedFile } from "./utils" ;
@@ -29,23 +30,31 @@ export class Transpiler {
2930
3031 public emit ( emitOptions : EmitOptions ) : EmitResult {
3132 const { program, writeFile = this . emitHost . writeFile } = emitOptions ;
32- const verbose = ( program . getCompilerOptions ( ) as CompilerOptions ) . tstlVerbose ;
33- const { diagnostics, transpiledFiles : freshFiles } = getProgramTranspileResult (
34- this . emitHost ,
35- writeFile ,
36- emitOptions
37- ) ;
33+ const options = program . getCompilerOptions ( ) as CompilerOptions ;
34+
35+ const { diagnostics : getPluginsDiagnostics , plugins } = getPlugins ( program ) ;
36+
37+ const { diagnostics, transpiledFiles : freshFiles } = getProgramTranspileResult ( this . emitHost , writeFile , {
38+ ...emitOptions ,
39+ plugins,
40+ } ) ;
3841
3942 const { emitPlan } = this . getEmitPlan ( program , diagnostics , freshFiles ) ;
4043
41- if ( verbose ) {
44+ if ( options . tstlVerbose ) {
4245 console . log ( "Emitting output" ) ;
4346 }
4447
45- const options = program . getCompilerOptions ( ) ;
48+ for ( const plugin of plugins ) {
49+ if ( plugin . beforeEmit ) {
50+ const beforeEmitPluginDiagnostics = plugin . beforeEmit ( program , options , this . emitHost , emitPlan ) ?? [ ] ;
51+ diagnostics . push ( ...beforeEmitPluginDiagnostics ) ;
52+ }
53+ }
54+
4655 const emitBOM = options . emitBOM ?? false ;
4756 for ( const { outputPath, code, sourceMap, sourceFiles } of emitPlan ) {
48- if ( verbose ) {
57+ if ( options . tstlVerbose ) {
4958 console . log ( `Emitting ${ normalizeSlashes ( outputPath ) } ` ) ;
5059 }
5160
@@ -55,11 +64,11 @@ export class Transpiler {
5564 }
5665 }
5766
58- if ( verbose ) {
67+ if ( options . tstlVerbose ) {
5968 console . log ( "Emit finished!" ) ;
6069 }
6170
62- return { diagnostics, emitSkipped : emitPlan . length === 0 } ;
71+ return { diagnostics : getPluginsDiagnostics . concat ( diagnostics ) , emitSkipped : emitPlan . length === 0 } ;
6372 }
6473
6574 protected getEmitPlan (
0 commit comments