Skip to content

Commit 9795e99

Browse files
authored
Fix tagged template literals when the tag is returned from a function call (#1639)
1 parent 2bb9a46 commit 9795e99

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/transformation/visitors/call.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function transformContextualCallExpression(
159159
);
160160
return lua.createCallExpression(expression, transformedArguments, node);
161161
}
162-
} else if (ts.isIdentifier(left)) {
162+
} else if (ts.isIdentifier(left) || ts.isCallExpression(left)) {
163163
const callContext = context.isStrict ? ts.factory.createNull() : ts.factory.createIdentifier("_G");
164164
let expression: lua.Expression;
165165
[expression, transformedArguments] = transformCallWithArguments(

test/unit/templateLiterals.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,26 @@ test.each(["string", "'string literal type'", "string & unknown"])(
8383
.expectToMatchJsResult();
8484
}
8585
);
86+
87+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1637
88+
test("tagged template literal returned from function call (#1637)", () => {
89+
util.testModule`
90+
function templateFactory() {
91+
return (template: TemplateStringsArray) => {
92+
return "bar";
93+
}
94+
}
95+
export let result = templateFactory()\`foo\`;
96+
`.expectToEqual({ result: "bar" });
97+
});
98+
99+
test("tagged template literal returned from function call, explicit no context (#1637)", () => {
100+
util.testModule`
101+
function templateFactory() {
102+
return function(this: void, template: TemplateStringsArray) {
103+
return "bar";
104+
}
105+
}
106+
export let result = templateFactory()\`foo\`;
107+
`.expectToEqual({ result: "bar" });
108+
});

0 commit comments

Comments
 (0)