@@ -271,12 +271,9 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
271271 ) ;
272272 }
273273
274- const signatureDeclaration = signature ?. getDeclaration ( ) ;
275-
276274 let callPath : lua . Expression ;
277275 let parameters : lua . Expression [ ] ;
278- const isContextualCall =
279- ! signatureDeclaration || getDeclarationContextType ( context , signatureDeclaration ) !== ContextType . Void ;
276+ const isContextualCall = isContextualCallExpression ( context , node , signature ) ;
280277 if ( ! isContextualCall ) {
281278 [ callPath , parameters ] = transformCallAndArguments ( context , calledExpression , node . arguments , signature ) ;
282279 } else {
@@ -288,8 +285,7 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
288285 calledExpression ,
289286 node . arguments ,
290287 signature ,
291- // Only pass context if noImplicitSelf is not configured
292- context . options . noImplicitSelf ? undefined : callContext
288+ callContext
293289 ) ;
294290 }
295291
@@ -300,6 +296,23 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
300296 return wrapResultInTable ? wrapInTable ( callExpression ) : callExpression ;
301297} ;
302298
299+ function isContextualCallExpression (
300+ context : TransformationContext ,
301+ node : ts . CallExpression ,
302+ signature : ts . Signature | undefined
303+ ) : boolean {
304+ const declaration = signature ?. getDeclaration ( ) ;
305+ if ( ! declaration ) {
306+ if ( ts . nodeIsSynthesized ( node . expression ) ) {
307+ // this includes JSX createElement calls
308+ // For this we use noImplicitSelf option
309+ return ! context . options . noImplicitSelf ;
310+ }
311+ return true ;
312+ }
313+ return getDeclarationContextType ( context , declaration ) !== ContextType . Void ;
314+ }
315+
303316export function getCalledExpression ( node : ts . CallExpression ) : ts . Expression {
304317 function unwrapExpression ( expression : ts . Expression ) : ts . Expression {
305318 expression = ts . skipOuterExpressions ( expression ) ;
0 commit comments