diff --git a/src/Transpiler.ts b/src/Transpiler.ts index 058055a4d..82deb5b86 100644 --- a/src/Transpiler.ts +++ b/src/Transpiler.ts @@ -1151,14 +1151,33 @@ export class LuaTranspiler { // Build parameter string const paramNames: string[] = []; - parameters.forEach((param) => { - paramNames.push((param.name as ts.Identifier).escapedText as string); - }); + + let spreadIdentifier = ""; + + // Only push parameter name to paramName array if it isn't a spread parameter + for (const param of parameters) { + const paramName = (param.name as ts.Identifier).escapedText as string; + + // This parameter is a spread parameter (...param) + if (!param.dotDotDotToken) { + paramNames.push(paramName); + } else { + spreadIdentifier = paramName; + // Push the spread operator into the paramNames array + paramNames.push("..."); + } + } // Build function header result += this.indent + this.accessPrefix(node) + `function ${methodName}(${paramNames.join(",")})\n`; this.pushIndent(); + + // Push spread operator here + if (spreadIdentifier !== "") { + result += ` local ${spreadIdentifier} = { ... }\n`; + } + result += this.transpileBlock(body); this.popIndent(); diff --git a/test/translation/lua/varargs.lua b/test/translation/lua/varargs.lua new file mode 100644 index 000000000..78d60a18e --- /dev/null +++ b/test/translation/lua/varargs.lua @@ -0,0 +1,3 @@ +function varargsFunction(a,...) + local b = { ... } +end diff --git a/test/translation/ts/varargs.ts b/test/translation/ts/varargs.ts new file mode 100644 index 000000000..3b015a4d6 --- /dev/null +++ b/test/translation/ts/varargs.ts @@ -0,0 +1 @@ +function varargsFunction(a: string, ...b: string[]): void {}