X Tutup
Skip to content
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
7 changes: 2 additions & 5 deletions src/transformation/builtins/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ export function transformFunctionPrototypeCall(
const expressionName = expression.name.text;
switch (expressionName) {
case "apply":
return lua.createCallExpression(
caller,
[params[0], createUnpackCall(context, params[1], node.arguments[1])],
node
);
const nonContextArgs = params.length > 1 ? [createUnpackCall(context, params[1], node.arguments[1])] : [];
return lua.createCallExpression(caller, [params[0], ...nonContextArgs], node);
case "bind":
return transformLuaLibFunction(context, LuaLibFeature.FunctionBind, node, caller, ...params);
case "call":
Expand Down
8 changes: 8 additions & 0 deletions test/unit/functions/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ test("Function apply", () => {
`.expectToMatchJsResult();
});

// Fix #1226: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1226
test("function apply without arguments should not lead to exception", () => {
util.testFunction`
const f = function (this: number) { return this + 3; }
return f.apply(4);
`.expectToMatchJsResult();
});

test("Function call", () => {
util.testFunction`
const abc = function (this: { a: number }, a: string) { return this.a + a; }
Expand Down
X Tutup