Skip to content

Commit 8d99864

Browse files
committed
Added spread argument to methods and fixed indentation issue
1 parent 8780346 commit 8d99864

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/Transpiler.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ export class LuaTranspiler {
11751175

11761176
// Push spread operator here
11771177
if (spreadIdentifier !== "") {
1178-
result += ` local ${spreadIdentifier} = { ... }\n`;
1178+
result += this.indent + `local ${spreadIdentifier} = { ... }\n`;
11791179
}
11801180

11811181
result += this.transpileBlock(body);
@@ -1198,17 +1198,35 @@ export class LuaTranspiler {
11981198

11991199
// Build parameter string
12001200
const paramNames: string[] = ["self"];
1201-
parameters.forEach((param) => {
1202-
paramNames.push((param.name as ts.Identifier).escapedText as string);
1203-
});
12041201

1202+
let spreadIdentifier = "";
1203+
1204+
// Only push parameter name to paramName array if it isn't a spread parameter
1205+
for (const param of parameters) {
1206+
const paramName = (param.name as ts.Identifier).escapedText as string;
1207+
1208+
// This parameter is a spread parameter (...param)
1209+
if (!param.dotDotDotToken) {
1210+
paramNames.push(paramName);
1211+
} else {
1212+
spreadIdentifier = paramName;
1213+
// Push the spread operator into the paramNames array
1214+
paramNames.push("...");
1215+
}
1216+
}
12051217
// Parameters with default values
12061218
const defaultValueParams = node.parameters.filter((declaration) => declaration.initializer !== undefined);
12071219

12081220
// Build function header
12091221
result += this.indent + `function ${callPath}${methodName}(${paramNames.join(",")})\n`;
12101222

12111223
this.pushIndent();
1224+
1225+
// Push spread operator here
1226+
if (spreadIdentifier !== "") {
1227+
result += this.indent + `local ${spreadIdentifier} = { ... }\n`;
1228+
}
1229+
12121230
result += this.transpileParameterDefaultValues(defaultValueParams);
12131231
result += this.transpileBlock(body);
12141232
this.popIndent();
File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MyClass = MyClass or {}
2+
MyClass.__index = MyClass
3+
function MyClass.new(construct, ...)
4+
local instance = setmetatable({}, MyClass)
5+
if construct and MyClass.constructor then MyClass.constructor(instance, ...) end
6+
return instance
7+
end
8+
function MyClass.constructor(self)
9+
end
10+
function MyClass.varargsFunction(self,a,...)
11+
local b = { ... }
12+
end
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class MyClass {
2+
varargsFunction(a: string, ...b: string[]): void {}
3+
}

0 commit comments

Comments
 (0)