@@ -16,8 +16,15 @@ import { isMultiReturnCall } from "./language-extensions/multi";
1616import { annotationRemoved } from "../utils/diagnostics" ;
1717import { isGlobalVarargConstant } from "./language-extensions/vararg" ;
1818
19+ function skipOuterExpressionParents ( node : ts . Node ) {
20+ while ( ts . isOuterExpression ( node ) ) {
21+ node = node . parent ;
22+ }
23+ return node ;
24+ }
25+
1926export function isOptimizedVarArgSpread ( context : TransformationContext , symbol : ts . Symbol , identifier : ts . Identifier ) {
20- if ( ! ts . isSpreadElement ( identifier . parent ) ) {
27+ if ( ! ts . isSpreadElement ( skipOuterExpressionParents ( identifier . parent ) ) ) {
2128 return false ;
2229 }
2330
@@ -63,20 +70,21 @@ export function isOptimizedVarArgSpread(context: TransformationContext, symbol:
6370
6471// TODO: Currently it's also used as an array member
6572export const transformSpreadElement : FunctionVisitor < ts . SpreadElement > = ( node , context ) => {
66- if ( ts . isIdentifier ( node . expression ) ) {
67- if ( isVarargType ( context , node . expression ) ) {
73+ const tsInnerExpression = ts . skipOuterExpressions ( node . expression ) ;
74+ if ( ts . isIdentifier ( tsInnerExpression ) ) {
75+ if ( isVarargType ( context , tsInnerExpression ) ) {
6876 context . diagnostics . push ( annotationRemoved ( node , AnnotationKind . Vararg ) ) ;
6977 }
70- const symbol = context . checker . getSymbolAtLocation ( node . expression ) ;
71- if ( symbol && isOptimizedVarArgSpread ( context , symbol , node . expression ) ) {
78+ const symbol = context . checker . getSymbolAtLocation ( tsInnerExpression ) ;
79+ if ( symbol && isOptimizedVarArgSpread ( context , symbol , tsInnerExpression ) ) {
7280 return lua . createDotsLiteral ( node ) ;
7381 }
7482 }
7583
7684 const innerExpression = context . transformExpression ( node . expression ) ;
77- if ( isMultiReturnCall ( context , node . expression ) ) return innerExpression ;
85+ if ( isMultiReturnCall ( context , tsInnerExpression ) ) return innerExpression ;
7886
79- const type = context . checker . getTypeAtLocation ( node . expression ) ;
87+ const type = context . checker . getTypeAtLocation ( node . expression ) ; // not ts-inner expression, in case of casts
8088 if ( isArrayType ( context , type ) ) {
8189 return createUnpackCall ( context , innerExpression , node ) ;
8290 }
0 commit comments