@@ -3,7 +3,7 @@ import * as lua from "../../LuaAST";
33import { transformBuiltinCallExpression } from "../builtins" ;
44import { FunctionVisitor , TransformationContext } from "../context" ;
55import { validateAssignment } from "../utils/assignment-validation" ;
6- import { ContextType , getDeclarationContextType } from "../utils/function-context" ;
6+ import { ContextType , getCallContextType } from "../utils/function-context" ;
77import { wrapInTable } from "../utils/lua-ast" ;
88import { isValidLuaIdentifier } from "../utils/safe-names" ;
99import { isExpressionWithEvaluationEffect } from "../utils/typescript" ;
@@ -117,16 +117,15 @@ function transformElementAccessCall(
117117export function transformContextualCallExpression (
118118 context : TransformationContext ,
119119 node : ts . CallExpression | ts . TaggedTemplateExpression ,
120- args : ts . Expression [ ] | ts . NodeArray < ts . Expression > ,
121- signature ?: ts . Signature
120+ args : ts . Expression [ ] | ts . NodeArray < ts . Expression >
122121) : lua . Expression {
123122 if ( ts . isOptionalChain ( node ) ) {
124123 return transformOptionalChain ( context , node ) ;
125124 }
126125 const left = ts . isCallExpression ( node ) ? getCalledExpression ( node ) : node . tag ;
127126
128127 let { precedingStatements : argPrecedingStatements , result : transformedArguments } =
129- transformInPrecedingStatementScope ( context , ( ) => transformArguments ( context , args , signature ) ) ;
128+ transformInPrecedingStatementScope ( context , ( ) => transformArguments ( context , args ) ) ;
130129
131130 if (
132131 ts . isPropertyAccessExpression ( left ) &&
@@ -189,10 +188,9 @@ function transformPropertyCall(
189188 return lua . createCallExpression ( context . transformExpression ( node . expression ) , parameters , node ) ;
190189 }
191190
192- const signatureDeclaration = signature ?. getDeclaration ( ) ;
193- if ( ! signatureDeclaration || getDeclarationContextType ( context , signatureDeclaration ) !== ContextType . Void ) {
191+ if ( getCallContextType ( context , node ) !== ContextType . Void ) {
194192 // table:name()
195- return transformContextualCallExpression ( context , node , node . arguments , signature ) ;
193+ return transformContextualCallExpression ( context , node , node . arguments ) ;
196194 } else {
197195 // table.name()
198196 const [ callPath , parameters ] = transformCallAndArguments ( context , node . expression , node . arguments , signature ) ;
@@ -202,14 +200,12 @@ function transformPropertyCall(
202200}
203201
204202function transformElementCall ( context : TransformationContext , node : ts . CallExpression ) : lua . Expression {
205- const signature = context . checker . getResolvedSignature ( node ) ;
206- const signatureDeclaration = signature ?. getDeclaration ( ) ;
207- if ( ! signatureDeclaration || getDeclarationContextType ( context , signatureDeclaration ) !== ContextType . Void ) {
203+ if ( getCallContextType ( context , node ) !== ContextType . Void ) {
208204 // A contextual parameter must be given to this call expression
209- return transformContextualCallExpression ( context , node , node . arguments , signature ) ;
205+ return transformContextualCallExpression ( context , node , node . arguments ) ;
210206 } else {
211207 // No context
212- const [ expression , parameters ] = transformCallAndArguments ( context , node . expression , node . arguments , signature ) ;
208+ const [ expression , parameters ] = transformCallAndArguments ( context , node . expression , node . arguments ) ;
213209 return lua . createCallExpression ( expression , parameters , node ) ;
214210 }
215211}
@@ -267,7 +263,9 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
267263
268264 let callPath : lua . Expression ;
269265 let parameters : lua . Expression [ ] ;
270- const isContextualCall = isContextualCallExpression ( context , signature ) ;
266+
267+ const isContextualCall = getCallContextType ( context , node ) !== ContextType . Void ;
268+
271269 if ( ! isContextualCall ) {
272270 [ callPath , parameters ] = transformCallAndArguments ( context , calledExpression , node . arguments , signature ) ;
273271 } else {
@@ -290,14 +288,6 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
290288 return wrapResultInTable ? wrapInTable ( callExpression ) : callExpression ;
291289} ;
292290
293- function isContextualCallExpression ( context : TransformationContext , signature : ts . Signature | undefined ) : boolean {
294- const declaration = signature ?. getDeclaration ( ) ;
295- if ( ! declaration ) {
296- return ! context . options . noImplicitSelf ;
297- }
298- return getDeclarationContextType ( context , declaration ) !== ContextType . Void ;
299- }
300-
301291export function getCalledExpression ( node : ts . CallExpression ) : ts . Expression {
302292 return ts . skipOuterExpressions ( node . expression ) ;
303293}
0 commit comments