Skip to content

Fix tagged template literals when the tag is returned from a function call #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transformation/visitors/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function transformContextualCallExpression(
);
return lua.createCallExpression(expression, transformedArguments, node);
}
} else if (ts.isIdentifier(left)) {
} else if (ts.isIdentifier(left) || ts.isCallExpression(left)) {
const callContext = context.isStrict ? ts.factory.createNull() : ts.factory.createIdentifier("_G");
let expression: lua.Expression;
[expression, transformedArguments] = transformCallWithArguments(
Expand Down
23 changes: 23 additions & 0 deletions test/unit/templateLiterals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,26 @@ test.each(["string", "'string literal type'", "string & unknown"])(
.expectToMatchJsResult();
}
);

// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1637
test("tagged template literal returned from function call (#1637)", () => {
util.testModule`
function templateFactory() {
return (template: TemplateStringsArray) => {
return "bar";
}
}
export let result = templateFactory()\`foo\`;
`.expectToEqual({ result: "bar" });
});

test("tagged template literal returned from function call, explicit no context (#1637)", () => {
util.testModule`
function templateFactory() {
return function(this: void, template: TemplateStringsArray) {
return "bar";
}
}
export let result = templateFactory()\`foo\`;
`.expectToEqual({ result: "bar" });
});
Loading