X Tutup
Skip to content

Commit abb9f07

Browse files
authored
Made LuaJIT use table.unpack for destructing assignments (#257)
1 parent 34d3f4a commit abb9f07

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/targets/Transpiler.JIT.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ export class LuaTranspilerJIT extends LuaTranspiler52 {
3434
throw TSTLErrors.UnsupportedKind("bitwise operator", node.operatorToken.kind, node);
3535
}
3636
}
37+
38+
/** @override */
39+
public transpileDestructingAssignmentValue(node: ts.Expression): string {
40+
return `table.unpack(${this.transpileExpression(node)})`;
41+
}
3742
}

test/unit/assignmentDestructuring.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class AssignmentDestructuringTests {
99
let [a, b] = myFunc();`;
1010

1111
@Test("Assignment destructuring [5.1]")
12-
public assignmentDestructuring51() {
12+
public assignmentDestructuring51(): void {
1313
// Transpile
1414
const lua = util.transpileString(
1515
this.assignmentDestruturingTs, {luaTarget: LuaTarget.Lua51, luaLibImport: "none"}
@@ -19,12 +19,22 @@ export class AssignmentDestructuringTests {
1919
}
2020

2121
@Test("Assignment destructuring [5.2]")
22-
public tupleDestructing52() {
22+
public tupleDestructing52(): void {
2323
// Transpile
2424
const lua = util.transpileString(
2525
this.assignmentDestruturingTs, {luaTarget: LuaTarget.Lua52, luaLibImport: "none"}
2626
);
2727
// Assert
2828
Expect(lua).toBe(`local a,b=table.unpack(myFunc());`);
2929
}
30+
31+
@Test("Assignment destructuring [JIT]")
32+
public assignmentDestructuringJIT(): void {
33+
// Transpile
34+
const lua = util.transpileString(
35+
this.assignmentDestruturingTs, {luaTarget: LuaTarget.LuaJIT, luaLibImport: "none"}
36+
);
37+
// Assert
38+
Expect(lua).toBe(`local a,b=table.unpack(myFunc());`);
39+
}
3040
}

0 commit comments

Comments
 (0)
X Tutup