Skip to content

Commit 3054adb

Browse files
lollekoPerryvw
authored andcommitted
Fixed JIT using table.unpack (#258)
* Fixed JIT using table.unpack sry * Fixed test for JIT unpack * Moved transpileDestructingAssignmentValue from 5.1 to 5.0
1 parent abb9f07 commit 3054adb

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

src/Transpiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ export abstract class LuaTranspiler {
16231623
}
16241624

16251625
public transpileDestructingAssignmentValue(node: ts.Expression): string {
1626-
throw TSTLErrors.UnsupportedForTarget("Destructing statements", this.options.luaTarget, node);
1626+
return `unpack(${this.transpileExpression(node)})`;
16271627
}
16281628

16291629
public transpileVariableDeclaration(node: ts.VariableDeclaration): string {

src/targets/Transpiler.51.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ import { TSHelper as tsHelper } from "../TSHelper";
44
import * as ts from "typescript";
55

66
export class LuaTranspiler51 extends LuaTranspiler {
7-
/** @override */
8-
public transpileDestructingAssignmentValue(node: ts.Expression): string {
9-
return `unpack(${this.transpileExpression(node)})`;
10-
}
7+
118
}

src/targets/Transpiler.JIT.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ export class LuaTranspilerJIT extends LuaTranspiler52 {
3737

3838
/** @override */
3939
public transpileDestructingAssignmentValue(node: ts.Expression): string {
40-
return `table.unpack(${this.transpileExpression(node)})`;
40+
return `unpack(${this.transpileExpression(node)})`;
4141
}
4242
}

test/unit/assignmentDestructuring.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export class AssignmentDestructuringTests {
3535
this.assignmentDestruturingTs, {luaTarget: LuaTarget.LuaJIT, luaLibImport: "none"}
3636
);
3737
// Assert
38-
Expect(lua).toBe(`local a,b=table.unpack(myFunc());`);
38+
Expect(lua).toBe(`local a,b=unpack(myFunc());`);
3939
}
4040
}

0 commit comments

Comments
 (0)