@@ -16,26 +16,6 @@ import {
1616import { invalidMultiFunctionReturnType } from "../utils/diagnostics" ;
1717import { isInAsyncFunction } from "../utils/typescript" ;
1818
19- function transformReturnExpressionForTryCatch ( context : TransformationContext , node : ts . Expression ) : lua . Expression {
20- const innerNode = ts . skipOuterExpressions ( node , ts . OuterExpressionKinds . Assertions ) ;
21-
22- if ( ts . isCallExpression ( innerNode ) ) {
23- if ( isMultiFunctionCall ( context , innerNode ) ) {
24- const type = context . checker . getContextualType ( node ) ;
25- if ( type && ! canBeMultiReturnType ( type ) ) {
26- context . diagnostics . push ( invalidMultiFunctionReturnType ( innerNode ) ) ;
27- }
28- return wrapInTable ( ...transformArguments ( context , innerNode . arguments ) ) ;
29- }
30-
31- if ( returnsMultiType ( context , innerNode ) && ! shouldMultiReturnCallBeWrapped ( context , innerNode ) ) {
32- return wrapInTable ( context . transformExpression ( node ) ) ;
33- }
34- }
35-
36- return context . transformExpression ( node ) ;
37- }
38-
3919function transformExpressionsInReturn ( context : TransformationContext , node : ts . Expression ) : lua . Expression [ ] {
4020 const expressionType = context . checker . getTypeAtLocation ( node ) ;
4121
@@ -70,6 +50,26 @@ export function transformExpressionBodyToReturnStatement(
7050 return createReturnStatement ( context , expressions , node ) ;
7151}
7252
53+ function transformReturnExpressionForTryCatch ( context : TransformationContext , node : ts . Expression ) : lua . Expression {
54+ const innerNode = ts . skipOuterExpressions ( node , ts . OuterExpressionKinds . Assertions ) ;
55+
56+ if ( ts . isCallExpression ( innerNode ) ) {
57+ if ( isMultiFunctionCall ( context , innerNode ) ) {
58+ const type = context . checker . getContextualType ( node ) ;
59+ if ( type && ! canBeMultiReturnType ( type ) ) {
60+ context . diagnostics . push ( invalidMultiFunctionReturnType ( innerNode ) ) ;
61+ }
62+ return wrapInTable ( ...transformArguments ( context , innerNode . arguments ) ) ;
63+ }
64+
65+ if ( returnsMultiType ( context , innerNode ) && ! shouldMultiReturnCallBeWrapped ( context , innerNode ) ) {
66+ return wrapInTable ( context . transformExpression ( node ) ) ;
67+ }
68+ }
69+
70+ return context . transformExpression ( node ) ;
71+ }
72+
7373export const transformReturnStatement : FunctionVisitor < ts . ReturnStatement > = ( statement , context ) => {
7474 const asyncTryScope = isInAsyncFunction ( statement ) ? findAsyncTryScopeInStack ( context ) : undefined ;
7575
0 commit comments