Skip to content

Commit bf051fa

Browse files
committed
Fix #1292
1 parent 7b25b3b commit bf051fa

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/transformation/visitors/call.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
303316
export function getCalledExpression(node: ts.CallExpression): ts.Expression {
304317
function unwrapExpression(expression: ts.Expression): ts.Expression {
305318
expression = ts.skipOuterExpressions(expression);

src/typescript-internal.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ declare module "typescript" {
2828

2929
function transformJsx(context: TransformationContext): (x: SourceFile) => SourceFile;
3030

31+
function nodeIsSynthesized(range: TextRange): boolean;
32+
3133
export type OuterExpression =
3234
| ParenthesizedExpression
3335
| TypeAssertion

0 commit comments

Comments
 (0)