@@ -685,20 +685,15 @@ export abstract class LuaTranspiler {
685685
686686 public transpileReturn ( node : ts . ReturnStatement ) : string {
687687 if ( node . expression ) {
688- // If parent function is a TupleReturn function
689- // and return expression is an array literal, leave out brackets.
690- const declaration = tsHelper . findFirstNodeAbove ( node , ( n ) : n is ts . Node =>
691- ts . isFunctionDeclaration ( n ) || ts . isMethodDeclaration ( n ) ) ;
692- let isTupleReturn = false ;
693- if ( declaration ) {
694- const decorators = tsHelper . getCustomDecorators (
695- this . checker . getTypeAtLocation ( declaration ) ,
696- this . checker
697- ) ;
698- isTupleReturn = decorators . has ( DecoratorKind . TupleReturn ) ;
699- }
700- if ( isTupleReturn && ts . isArrayLiteralExpression ( node . expression ) ) {
701- return "return " + node . expression . elements . map ( elem => this . transpileExpression ( elem ) ) . join ( "," ) ;
688+ if ( tsHelper . isInTupleReturnFunction ( node , this . checker ) ) {
689+ // Parent function is a TupleReturn function
690+ if ( ts . isArrayLiteralExpression ( node . expression ) ) {
691+ // If return expression is an array literal, leave out brackets.
692+ return "return " + node . expression . elements . map ( elem => this . transpileExpression ( elem ) ) . join ( "," ) ;
693+ } else if ( ! tsHelper . isTupleReturnCall ( node . expression , this . checker ) ) {
694+ // If return expression is not another TupleReturn call, unpack it
695+ return `return ${ this . transpileDestructingAssignmentValue ( node . expression ) } ` ;
696+ }
702697 }
703698
704699 return "return " + this . transpileExpression ( node . expression ) ;
@@ -1085,12 +1080,15 @@ export abstract class LuaTranspiler {
10851080 let callPath ;
10861081
10871082 const isTupleReturn = tsHelper . isTupleReturnCall ( node , this . checker ) ;
1083+ const isTupleReturnForward = node . parent && ts . isReturnStatement ( node . parent )
1084+ && tsHelper . isInTupleReturnFunction ( node , this . checker ) ;
10881085 const isInDestructingAssignment = tsHelper . isInDestructingAssignment ( node ) ;
10891086 const returnValueIsUsed = node . parent && ! ts . isExpressionStatement ( node . parent ) ;
10901087
10911088 if ( ts . isPropertyAccessExpression ( node . expression ) ) {
10921089 const result = this . transpilePropertyCall ( node ) ;
1093- return isTupleReturn && ! isInDestructingAssignment && returnValueIsUsed ? `({ ${ result } })` : result ;
1090+ return isTupleReturn && ! isTupleReturnForward && ! isInDestructingAssignment && returnValueIsUsed
1091+ ? `({ ${ result } })` : result ;
10941092 }
10951093
10961094 // Handle super calls properly
@@ -1102,7 +1100,7 @@ export abstract class LuaTranspiler {
11021100
11031101 callPath = this . transpileExpression ( node . expression ) ;
11041102 params = this . transpileArguments ( node . arguments ) ;
1105- return isTupleReturn && ! isInDestructingAssignment && returnValueIsUsed
1103+ return isTupleReturn && ! isTupleReturnForward && ! isInDestructingAssignment && returnValueIsUsed
11061104 ? `({ ${ callPath } (${ params } ) })` : `${ callPath } (${ params } )` ;
11071105 }
11081106
0 commit comments