@@ -131,6 +131,7 @@ export class LuaTransformer {
131131 const combinedStatements = bundle . sourceFiles . reduce (
132132 ( statements : tstl . Statement [ ] , sourceFile : ts . SourceFile ) => {
133133 this . currentSourceFile = sourceFile ;
134+ this . visitedExportEquals = false ;
134135 this . isModule = tsHelper . isFileModule ( sourceFile ) ;
135136 const originalSourceFile = ts . getParseTreeNode ( sourceFile , ts . isSourceFile ) || sourceFile ;
136137 this . resolver = this . checker . getEmitResolver ( originalSourceFile ) ;
@@ -169,16 +170,18 @@ export class LuaTransformer {
169170 statements = this . performHoisting ( this . transformStatements ( sourceFile . statements ) ) ;
170171 this . popScope ( ) ;
171172
172- if ( this . isModule && ! this . isWithinBundle ) {
173- // If export equals was not used. Create the exports table.
174- // local exports = {}
175- if ( ! this . visitedExportEquals ) {
176- statements . unshift (
177- tstl . createVariableDeclarationStatement (
178- this . createExportsIdentifier ( ) ,
179- tstl . createTableExpression ( )
180- )
181- ) ;
173+ if ( this . isModule ) {
174+ if ( ! this . isWithinBundle ) {
175+ // If export equals was not used. Create the exports table.
176+ // local exports = {}
177+ if ( ! this . visitedExportEquals ) {
178+ statements . unshift (
179+ tstl . createVariableDeclarationStatement (
180+ this . createExportsIdentifier ( ) ,
181+ tstl . createTableExpression ( )
182+ )
183+ ) ;
184+ }
182185 }
183186
184187 // return exports
@@ -192,11 +195,10 @@ export class LuaTransformer {
192195 tstl . createStringLiteral ( "preload" )
193196 ) ;
194197 const exportPath = tsHelper . getExportPath ( sourceFile . fileName , this . options ) ;
198+ const moduleParameters = this . visitedExportEquals ? undefined : [ this . createExportsIdentifier ( ) ] ;
195199 const packagePreloadDeclaration = tstl . createAssignmentStatement (
196200 tstl . createTableIndexExpression ( packagePreload , tstl . createStringLiteral ( exportPath ) ) ,
197- tstl . createFunctionExpression ( tstl . createBlock ( statements , sourceFile ) , [
198- this . createExportsIdentifier ( ) ,
199- ] )
201+ tstl . createFunctionExpression ( tstl . createBlock ( statements , sourceFile ) , moduleParameters )
200202 ) ;
201203 return tstl . createBlock ( [ packagePreloadDeclaration ] , sourceFile ) ;
202204 }
0 commit comments