@@ -227,32 +227,32 @@ export class LuaPrinter {
227227 }
228228
229229 protected printFile ( file : lua . File ) : SourceNode {
230- let header = file . trivia ;
230+ let sourceChunks : SourceChunk [ ] = [ file . trivia ] ;
231231
232232 if ( ! this . options . noHeader ) {
233- header += tstlHeader ;
233+ sourceChunks . push ( tstlHeader ) ;
234234 }
235- let statements = file . statements ;
236235
237236 const luaLibImport = this . options . luaLibImport ?? LuaLibImportKind . Require ;
238237 if ( luaLibImport === LuaLibImportKind . Require && file . luaLibFeatures . size > 0 ) {
239238 // Import lualib features
240- const importStatements = loadImportedLualibFeatures ( file . luaLibFeatures , this . emitHost ) ;
241-
242- statements = importStatements . concat ( statements ) ;
239+ sourceChunks = this . printStatementArray ( loadImportedLualibFeatures ( file . luaLibFeatures , this . emitHost ) ) ;
243240 } else if ( luaLibImport === LuaLibImportKind . Inline && file . luaLibFeatures . size > 0 ) {
244241 // Inline lualib features
245- header += "-- Lua Library inline imports\n" ;
246- header += loadInlineLualibFeatures ( file . luaLibFeatures , this . emitHost ) ;
242+ sourceChunks . push ( "-- Lua Library inline imports\n" ) ;
243+ sourceChunks . push ( loadInlineLualibFeatures ( file . luaLibFeatures , this . emitHost ) ) ;
247244 }
248245
249246 if ( this . options . sourceMapTraceback && ! isBundleEnabled ( this . options ) ) {
250247 // In bundle mode the traceback is being generated for the entire file in getBundleResult
251248 // Otherwise, traceback is being generated locally
252- header += `${ LuaPrinter . sourceMapTracebackPlaceholder } \n` ;
249+ sourceChunks . push ( `${ LuaPrinter . sourceMapTracebackPlaceholder } \n` ) ;
253250 }
254251
255- return this . concatNodes ( header , ...this . printStatementArray ( statements ) ) ;
252+ // Print reest of the statements in file
253+ sourceChunks . push ( ...this . printStatementArray ( file . statements ) ) ;
254+
255+ return this . concatNodes ( ...sourceChunks ) ;
256256 }
257257
258258 protected pushIndent ( ) : void {
0 commit comments