File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,9 @@ export class TransformHelper {
1616 ts . createCall ( requireIdentifier , [ ts . createLiteralTypeNode ( moduleSpecifier ) ] , [ moduleSpecifier ] ) ;
1717 return this . createLuaVariableStatement ( identifier , requireCall ) ;
1818 }
19+
20+ public static flatten < T > ( arr : T [ ] ) : T [ ] {
21+ const flat = [ ] . concat ( ...arr ) ;
22+ return flat . some ( Array . isArray ) ? this . flatten ( flat ) : flat ;
23+ }
1924}
Original file line number Diff line number Diff line change @@ -283,8 +283,8 @@ export class LuaTransformer {
283283
284284 // Transform moduleblock to block and visit it
285285 if ( node . body && ts . isModuleBlock ( node . body ) ) {
286- const bodyBlock = this . visitBlock ( ts . createBlock ( node . body . statements ) ) as ts . Block ;
287- // result.push(bodyBlock);
286+ const bodyBlock = this . visitModuleBlock ( node . body ) as ts . Block ;
287+ result . push ( bodyBlock ) ;
288288 }
289289
290290 this . currentNamespace = previousNamespace ;
@@ -446,11 +446,12 @@ export class LuaTransformer {
446446 public visitComputedPropertyName ( node : ts . ComputedPropertyName ) : ts . VisitResult < ts . ComputedPropertyName > {
447447 return node ;
448448 }
449- public visitBlock ( node : ts . Block ) : ts . Block {
450- return ts . updateBlock ( node , node . statements . map ( s => this . visitor ( s ) ) as ts . Statement [ ] ) ;
449+ public visitBlock ( node : ts . Block ) : ts . VisitResult < ts . Block > {
450+ return ts . updateBlock (
451+ node , transformHelper . flatten ( node . statements . map ( s => this . visitor ( s ) ) as ts . Statement [ ] ) ) ;
451452 }
452- public visitModuleBlock ( node : ts . ModuleBlock ) : ts . VisitResult < ts . ModuleBlock > {
453- return node ;
453+ public visitModuleBlock ( node : ts . ModuleBlock ) : ts . VisitResult < ts . Block > {
454+ return this . visitBlock ( ts . createBlock ( node . statements ) ) ;
454455 }
455456 public visitEndOfFileToken ( node : ts . EndOfFileToken ) : ts . VisitResult < ts . EndOfFileToken > {
456457 return node ;
You can’t perform that action at this time.
0 commit comments