Skip to content

Commit 5cb7b09

Browse files
committed
Merge branch 'master' into feature/glua-target
2 parents f24e6ff + 8c6f4ef commit 5cb7b09

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/Transpiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,8 @@ export abstract class LuaTranspiler {
12131213
return this.transpileLuaLibFunction(LuaLibFeature.ArrayConcat, caller, params);
12141214
case "push":
12151215
return this.transpileLuaLibFunction(LuaLibFeature.ArrayPush, caller, params);
1216+
case "pop":
1217+
return `table.remove(${caller})`;
12161218
case "forEach":
12171219
return this.transpileLuaLibFunction(LuaLibFeature.ArrayForEach, caller, params);
12181220
case "indexOf":
@@ -1803,6 +1805,8 @@ export abstract class LuaTranspiler {
18031805
if (ts.isPropertyAssignment(element)) {
18041806
const expression = this.transpileExpression(element.initializer);
18051807
properties.push(`${name} = ${expression}`);
1808+
} else if (ts.isShorthandPropertyAssignment(element)) {
1809+
properties.push(`${name} = ${name}`);
18061810
} else {
18071811
throw TSTLErrors.UnsupportedKind("object literal element", element.kind, node);
18081812
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local f = function(x) return ({x = x}) end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const f = x => ({ x });

test/unit/lualib/lualib.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,38 @@ export class LuaLibArrayTests {
262262
Expect(result).toBe(JSON.stringify([0].concat(inp)));
263263
}
264264

265+
@TestCase("[1, 2, 3]", [3, 2])
266+
@TestCase("[1, 2, 3, null]", [3, 2])
267+
@Test("array.pop")
268+
public arrayPop(array: string, expected) {
269+
{
270+
// Transpile
271+
const lua = util.transpileString(
272+
`let testArray = ${array};
273+
let val = testArray.pop();
274+
return val`);
275+
276+
// Execute
277+
const result = util.executeLua(lua);
278+
279+
// Assert
280+
Expect(result).toBe(expected[0]);
281+
}
282+
{
283+
// Transpile
284+
const lua = util.transpileString(
285+
`let testArray = ${array};
286+
testArray.pop();
287+
return testArray.length`);
288+
289+
// Execute
290+
const result = util.executeLua(lua);
291+
292+
// Assert
293+
Expect(result).toBe(expected[1]);
294+
}
295+
}
296+
265297
@TestCase("true", "4", "5", 4)
266298
@TestCase("false", "4", "5", 5)
267299
@TestCase("3", "4", "5", 4)
@@ -276,7 +308,7 @@ export class LuaLibArrayTests {
276308
// Assert
277309
Expect(result).toBe(expected);
278310
}
279-
311+
280312
@TestCase("true", 11)
281313
@TestCase("false", 13)
282314
@TestCase("a < 4", 13)

test/unit/objectLiteral.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ export class ObjectLiteralTests {
1010
@TestCase(`{["a"]:3,b:"4"}`, `{["a"] = 3,b = "4"}`)
1111
@TestCase(`{["a"+123]:3,b:"4"}`, `{["a" .. 123] = 3,b = "4"}`)
1212
@TestCase(`{[myFunc()]:3,b:"4"}`, `{[myFunc()] = 3,b = "4"}`)
13+
@TestCase(`{x}`, `{x = x}`)
1314
@Test("Object Literal")
1415
public objectLiteral(inp: string, out: string) {
1516
var lua = util.transpileString(`const myvar = ${inp};`)
1617
Expect(lua).toBe(`local myvar = ${out}`);
1718
}
19+
20+
@TestCase("3", 3)
21+
@Test("Shorthand Property Assignment")
22+
public ShorthandPropertyAssignment(input: string, expected: number): void {
23+
const lua = util.transpileString(`const x = ${input}; const o = {x}; return o.x;`);
24+
const result = util.executeLua(lua);
25+
Expect(result).toBe(expected);
26+
}
1827
}

0 commit comments

Comments
 (0)