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
1 change: 1 addition & 0 deletions src/CompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum LuaTarget {
Lua51 = "5.1",
Lua52 = "5.2",
Lua53 = "5.3",
Lua54 = "5.4",
LuaJIT = "JIT",
}

Expand Down
1 change: 1 addition & 0 deletions test/cli/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe("tsconfig", () => {
["luaTarget", "5.1", { luaTarget: tstl.LuaTarget.Lua51 }],
["luaTarget", "5.2", { luaTarget: tstl.LuaTarget.Lua52 }],
["luaTarget", "5.3", { luaTarget: tstl.LuaTarget.Lua53 }],
["luaTarget", "5.4", { luaTarget: tstl.LuaTarget.Lua54 }],
["luaTarget", "jit", { luaTarget: tstl.LuaTarget.LuaJIT }],

["luaBundle", "foo", { luaBundle: "foo" }],
Expand Down
100 changes: 100 additions & 0 deletions test/unit/__snapshots__/expressions.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,87 @@ ____exports.__result = a | b
return ____exports"
`;

exports[`Bitop [5.4] ("~a") 1`] = `
"local ____exports = {}
____exports.__result = ~a
return ____exports"
`;

exports[`Bitop [5.4] ("a&=b") 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a & b
return a
end)()
return ____exports"
`;

exports[`Bitop [5.4] ("a&b") 1`] = `
"local ____exports = {}
____exports.__result = a & b
return ____exports"
`;

exports[`Bitop [5.4] ("a<<=b") 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a << b
return a
end)()
return ____exports"
`;

exports[`Bitop [5.4] ("a<<b") 1`] = `
"local ____exports = {}
____exports.__result = a << b
return ____exports"
`;

exports[`Bitop [5.4] ("a>>>=b") 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a >> b
return a
end)()
return ____exports"
`;

exports[`Bitop [5.4] ("a>>>b") 1`] = `
"local ____exports = {}
____exports.__result = a >> b
return ____exports"
`;

exports[`Bitop [5.4] ("a^=b") 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a ~ b
return a
end)()
return ____exports"
`;

exports[`Bitop [5.4] ("a^b") 1`] = `
"local ____exports = {}
____exports.__result = a ~ b
return ____exports"
`;

exports[`Bitop [5.4] ("a|=b") 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a | b
return a
end)()
return ____exports"
`;

exports[`Bitop [5.4] ("a|b") 1`] = `
"local ____exports = {}
____exports.__result = a | b
return ____exports"
`;

exports[`Bitop [JIT] ("~a") 1`] = `
"local ____exports = {}
____exports.__result = bit.bnot(a)
Expand Down Expand Up @@ -553,3 +634,22 @@ return ____exports"
`;

exports[`Unsupported bitop 5.3 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;

exports[`Unsupported bitop 5.4 ("a>>=b"): code 1`] = `
"local ____exports = {}
____exports.__result = (function()
a = a >> b
return a
end)()
return ____exports"
`;

exports[`Unsupported bitop 5.4 ("a>>=b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;

exports[`Unsupported bitop 5.4 ("a>>b"): code 1`] = `
"local ____exports = {}
____exports.__result = a >> b
return ____exports"
`;

exports[`Unsupported bitop 5.4 ("a>>b"): diagnostics 1`] = `"main.ts(1,25): error TSTL: Right shift operator is not supported for target Lua 5.3. Use \`>>>\` instead."`;
1 change: 1 addition & 0 deletions test/unit/builtins/math.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ util.testEachVersion("Math.atan2", () => util.testExpression`Math.atan2(4, 5)`,
[tstl.LuaTarget.Lua51]: builder => builder.tap(expectMathAtan2),
[tstl.LuaTarget.Lua52]: builder => builder.tap(expectMathAtan2),
[tstl.LuaTarget.Lua53]: builder => builder.tap(expectMathAtan),
[tstl.LuaTarget.Lua54]: builder => builder.tap(expectMathAtan2),
});

test("Math.atan2(4, 5)", () => {
Expand Down
20 changes: 17 additions & 3 deletions test/unit/expressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ test.each(["a+=b", "a-=b", "a*=b", "a/=b", "a%=b", "a**=b"])("Binary expressions
});

const supportedInAll = ["~a", "a&b", "a&=b", "a|b", "a|=b", "a^b", "a^=b", "a<<b", "a<<=b", "a>>>b", "a>>>=b"];
const unsupportedIn53 = ["a>>b", "a>>=b"];
const allBinaryOperators = [...supportedInAll, ...unsupportedIn53];
const unsupportedIn53And54 = ["a>>b", "a>>=b"];
const allBinaryOperators = [...supportedInAll, ...unsupportedIn53And54];
test.each(allBinaryOperators)("Bitop [5.1] (%p)", input => {
// Bit operations not supported in 5.1, expect an exception
util.testExpression(input)
Expand Down Expand Up @@ -77,13 +77,27 @@ test.each(supportedInAll)("Bitop [5.3] (%p)", input => {
.expectLuaToMatchSnapshot();
});

test.each(unsupportedIn53)("Unsupported bitop 5.3 (%p)", input => {
test.each(supportedInAll)("Bitop [5.4] (%p)", input => {
util.testExpression(input)
.setOptions({ luaTarget: tstl.LuaTarget.Lua54, luaLibImport: tstl.LuaLibImportKind.None })
.disableSemanticCheck()
.expectLuaToMatchSnapshot();
});

test.each(unsupportedIn53And54)("Unsupported bitop 5.3 (%p)", input => {
util.testExpression(input)
.setOptions({ luaTarget: tstl.LuaTarget.Lua53, luaLibImport: tstl.LuaLibImportKind.None })
.disableSemanticCheck()
.expectDiagnosticsToMatchSnapshot([unsupportedRightShiftOperator.code]);
});

test.each(unsupportedIn53And54)("Unsupported bitop 5.4 (%p)", input => {
util.testExpression(input)
.setOptions({ luaTarget: tstl.LuaTarget.Lua54, luaLibImport: tstl.LuaLibImportKind.None })
.disableSemanticCheck()
.expectDiagnosticsToMatchSnapshot([unsupportedRightShiftOperator.code]);
});

test.each(["1+1", "-1+1", "1*30+4", "1*(3+4)", "1*(3+4*2)", "10-(4+5)"])(
"Binary expressions ordering parentheses (%p)",
input => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/language-extensions/operators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LuaTarget } from "../../../src";
import { unsupportedForTarget } from "../../../src/transformation/utils/diagnostics";

const operatorsProjectOptions: tstl.CompilerOptions = {
luaTarget: LuaTarget.Lua53,
luaTarget: LuaTarget.Lua54,
types: [path.resolve(__dirname, "../../../language-extensions")],
};

Expand Down
1 change: 1 addition & 0 deletions test/unit/loops.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ for (const testCase of [
[tstl.LuaTarget.Lua51]: builder => builder.expectDiagnosticsToMatchSnapshot([unsupportedForTarget.code]),
[tstl.LuaTarget.Lua52]: expectContinueGotoLabel,
[tstl.LuaTarget.Lua53]: expectContinueGotoLabel,
[tstl.LuaTarget.Lua54]: expectContinueGotoLabel,
[tstl.LuaTarget.LuaJIT]: expectContinueGotoLabel,
});
}
Expand Down
6 changes: 4 additions & 2 deletions test/unit/spread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ describe("in function call", () => {
[tstl.LuaTarget.LuaJIT]: builder => builder.tap(expectUnpack),
[tstl.LuaTarget.Lua51]: builder => builder.tap(expectUnpack),
[tstl.LuaTarget.Lua52]: builder => builder.tap(expectTableUnpack),
[tstl.LuaTarget.Lua53]: builder => builder.tap(expectTableUnpack).expectToMatchJsResult(),
[tstl.LuaTarget.Lua53]: builder => builder.tap(expectTableUnpack),
[tstl.LuaTarget.Lua54]: builder => builder.tap(expectTableUnpack).expectToMatchJsResult(),
}
);
});
Expand All @@ -88,7 +89,8 @@ describe("in array literal", () => {
[tstl.LuaTarget.LuaJIT]: builder => builder.tap(expectUnpack),
[tstl.LuaTarget.Lua51]: builder => builder.tap(expectUnpack),
[tstl.LuaTarget.Lua52]: builder => builder.tap(expectTableUnpack),
[tstl.LuaTarget.Lua53]: builder => builder.tap(expectTableUnpack).expectToMatchJsResult(),
[tstl.LuaTarget.Lua53]: builder => builder.tap(expectTableUnpack),
[tstl.LuaTarget.Lua54]: builder => builder.tap(expectTableUnpack).expectToMatchJsResult(),
});

test("of array literal /w OmittedExpression", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jest/no-standalone-expect */
import * as nativeAssert from "assert";
import { lauxlib, lua, lualib } from "lua-wasm-bindings/dist/lua.53";
import { lauxlib, lua, lualib } from "lua-wasm-bindings/dist/lua.54";
import { LUA_OK } from "lua-wasm-bindings/dist/lua";
import * as fs from "fs";
import { stringify } from "javascript-stringify";
Expand Down Expand Up @@ -109,7 +109,7 @@ export abstract class TestBuilder {
}

private options: tstl.CompilerOptions = {
luaTarget: tstl.LuaTarget.Lua53,
luaTarget: tstl.LuaTarget.Lua54,
noHeader: true,
skipLibCheck: true,
target: ts.ScriptTarget.ES2017,
Expand Down