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
12 changes: 6 additions & 6 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,12 @@ export class LuaTransformer {

headerStatements.push(...defaultValueDeclarations);

// Push spread operator here
if (spreadIdentifier) {
const spreadTable = this.wrapInTable(tstl.createDotsLiteral());
headerStatements.push(tstl.createVariableDeclarationStatement(spreadIdentifier, spreadTable));
}

// Add object binding patterns
let identifierIndex = 0;
const bindingPatternDeclarations: tstl.Statement[] = [];
Expand All @@ -1181,12 +1187,6 @@ export class LuaTransformer {

headerStatements.push(...bindingPatternDeclarations);

// Push spread operator here
if (spreadIdentifier) {
const spreadTable = this.wrapInTable(tstl.createDotsLiteral());
headerStatements.push(tstl.createVariableDeclarationStatement(spreadIdentifier, spreadTable));
}

const bodyStatements = this.performHoisting(this.transformStatements(body.statements));

const scope = this.popScope();
Expand Down
12 changes: 12 additions & 0 deletions test/unit/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,16 @@ export class FunctionTests {
}`;
Expect(util.transpileAndExecute("return foo;", undefined, undefined, code)).toBe("foo");
}

@Test("Function rest binding pattern")
public functionRestBindingPattern(): void {
const result = util.transpileAndExecute(
`function bar(foo: string, ...[bar, baz]: [string, string]) {
return bar + baz + foo;
}
return bar("abc", "def", "xyz");
`);

Expect(result).toBe("defxyzabc");
}
}