@@ -397,7 +397,7 @@ export class LuaTransformer {
397397 // exports.className = baseName.new()
398398 const classVar = this . createLocalOrGlobalDeclaration ( className , rhs , undefined , statement ) ;
399399
400- result . push ( classVar ) ;
400+ result . push ( ... classVar ) ;
401401 } else {
402402 // {}
403403 let rhs : tstl . Expression = tstl . createTableExpression ( ) ;
@@ -412,7 +412,7 @@ export class LuaTransformer {
412412 // exports.className = {}
413413 const classVar = this . createLocalOrGlobalDeclaration ( className , rhs , undefined , statement ) ;
414414
415- result . push ( classVar ) ;
415+ result . push ( ... classVar ) ;
416416 }
417417
418418 // className.__index
@@ -815,26 +815,26 @@ export class LuaTransformer {
815815
816816 const membersOnly = tsHelper . getCustomDecorators ( type , this . checker ) . has ( DecoratorKind . CompileMembersOnly ) ;
817817
818- const result = [ ] ;
818+ const result : tstl . Statement [ ] = [ ] ;
819819
820820 if ( ! membersOnly ) {
821821 const name = this . transformIdentifier ( enumDeclaration . name ) ;
822822 const table = tstl . createTableExpression ( ) ;
823- result . push ( this . createLocalOrGlobalDeclaration ( name , table , undefined , enumDeclaration ) ) ;
823+ result . push ( ... this . createLocalOrGlobalDeclaration ( name , table , undefined , enumDeclaration ) ) ;
824824 }
825825
826826 for ( const enumMember of this . computeEnumMembers ( enumDeclaration ) ) {
827827 const memberName = this . transformPropertyName ( enumMember . name ) ;
828828 if ( membersOnly ) {
829829 if ( tstl . isIdentifier ( memberName ) ) {
830- result . push ( this . createLocalOrGlobalDeclaration (
830+ result . push ( ... this . createLocalOrGlobalDeclaration (
831831 memberName ,
832832 enumMember . value ,
833833 undefined ,
834834 enumDeclaration
835835 ) ) ;
836836 } else {
837- result . push ( this . createLocalOrGlobalDeclaration (
837+ result . push ( ... this . createLocalOrGlobalDeclaration (
838838 tstl . createIdentifier ( enumMember . name . getText ( ) , undefined , enumMember . name ) ,
839839 enumMember . value ,
840840 undefined ,
@@ -886,7 +886,7 @@ export class LuaTransformer {
886886 } ) ;
887887 }
888888
889- public transformFunctionDeclaration ( functionDeclaration : ts . FunctionDeclaration ) : tstl . Statement {
889+ public transformFunctionDeclaration ( functionDeclaration : ts . FunctionDeclaration ) : StatementVisitResult {
890890 // Don't transform functions without body (overload declarations)
891891 if ( ! functionDeclaration . body ) {
892892 return undefined ;
@@ -1353,26 +1353,30 @@ export class LuaTransformer {
13531353 public transformTryStatement ( statement : ts . TryStatement ) : StatementVisitResult {
13541354 const pCall = tstl . createIdentifier ( "pcall" ) ;
13551355 const tryBlock = this . transformBlock ( statement . tryBlock ) ;
1356- const tryResult = tstl . createIdentifier ( "____TS_try" ) ;
1356+ const tryCall = tstl . createCallExpression ( pCall , [ tstl . createFunctionExpression ( tryBlock ) ] ) ;
13571357
1358- const returnVariables = statement . catchClause && statement . catchClause . variableDeclaration
1359- ? [ tryResult , this . transformIdentifier ( statement . catchClause . variableDeclaration . name as ts . Identifier ) ]
1360- : [ tryResult ] ;
1358+ const result : tstl . Statement [ ] = [ ] ;
13611359
1362- const catchAssignment = tstl . createVariableDeclarationStatement (
1363- returnVariables ,
1364- tstl . createCallExpression ( pCall , [ tstl . createFunctionExpression ( tryBlock ) ] )
1365- ) ;
1360+ if ( statement . catchClause ) {
1361+ const tryResult = tstl . createIdentifier ( "____TS_try" ) ;
13661362
1367- const result : tstl . Statement [ ] = [ catchAssignment ] ;
1363+ const returnVariables = statement . catchClause && statement . catchClause . variableDeclaration
1364+ ? [ tryResult , this . transformIdentifier ( statement . catchClause . variableDeclaration . name as ts . Identifier ) ]
1365+ : [ tryResult ] ;
1366+
1367+ const catchAssignment = tstl . createVariableDeclarationStatement ( returnVariables , tryCall ) ;
1368+
1369+ result . push ( catchAssignment ) ;
13681370
1369- if ( statement . catchClause ) {
13701371 const notTryResult = tstl . createUnaryExpression ( tryResult , tstl . SyntaxKind . NotOperator ) ;
13711372 result . push ( tstl . createIfStatement ( notTryResult , this . transformBlock ( statement . catchClause . block ) ) ) ;
1373+
1374+ } else {
1375+ result . push ( tstl . createExpressionStatement ( tryCall ) ) ;
13721376 }
13731377
13741378 if ( statement . finallyBlock ) {
1375- result . push ( ... this . transformBlock ( statement . finallyBlock ) . statements ) ;
1379+ result . push ( tstl . createDoStatement ( this . transformBlock ( statement . finallyBlock ) . statements ) ) ;
13761380 }
13771381
13781382 return tstl . createDoStatement (
@@ -2931,16 +2935,17 @@ export class LuaTransformer {
29312935 rhs : tstl . Expression ,
29322936 parent ?: tstl . Node ,
29332937 tsOriginal ?: ts . Node
2934- ) : tstl . Statement
2938+ ) : tstl . Statement [ ]
29352939 {
2940+ const statements : tstl . Statement [ ] = [ ] ;
29362941 if ( this . isModule
29372942 || this . currentNamespace
29382943 || ( tsOriginal && tsHelper . findFirstNodeAbove ( tsOriginal , ts . isFunctionLike ) )
29392944 ) {
2940- return tstl . createVariableDeclarationStatement ( lhs , rhs , parent , tsOriginal ) ;
2941- } else {
2942- return tstl . createAssignmentStatement ( lhs , rhs , parent , tsOriginal ) ;
2945+ statements . push ( tstl . createVariableDeclarationStatement ( lhs , undefined , parent ) ) ;
29432946 }
2947+ statements . push ( tstl . createAssignmentStatement ( lhs , rhs , parent , tsOriginal ) ) ;
2948+ return statements ;
29442949 }
29452950
29462951 private validateFunctionAssignment ( node : ts . Node , fromType : ts . Type , toType : ts . Type , toName ?: string ) : void {
0 commit comments