typescript-to-lua 1.10.1 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CompilerOptions.d.ts +2 -2
- package/dist/LuaAST.d.ts +10 -10
- package/dist/LuaLib.d.ts +1 -2
- package/dist/LuaLib.js +0 -1
- package/dist/LuaPrinter.d.ts +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +1 -1
- package/dist/lualib/5.0/NumberToString.lua +1 -1
- package/dist/lualib/5.0/ParseInt.lua +3 -3
- package/dist/lualib/5.0/SetDescriptor.lua +1 -2
- package/dist/lualib/5.0/lualib_bundle.lua +21 -27
- package/dist/lualib/5.0/lualib_module_info.json +0 -7
- package/dist/lualib/universal/ParseInt.lua +3 -3
- package/dist/lualib/universal/SetDescriptor.lua +1 -2
- package/dist/lualib/universal/lualib_bundle.lua +20 -26
- package/dist/lualib/universal/lualib_module_info.json +0 -6
- package/dist/lualib-build/plugin.d.ts +1 -1
- package/dist/lualib-build/util.d.ts +2 -2
- package/dist/transformation/context/context.js +2 -1
- package/dist/transformation/context/visitors.d.ts +8 -7
- package/dist/transformation/utils/annotations.d.ts +1 -1
- package/dist/transformation/utils/diagnostics.d.ts +0 -9
- package/dist/transformation/utils/diagnostics.js +1 -5
- package/dist/transformation/utils/export.js +4 -2
- package/dist/transformation/utils/lua-ast.d.ts +1 -1
- package/dist/transformation/visitors/binary-expression/bit.d.ts +1 -1
- package/dist/transformation/visitors/binary-expression/bit.js +3 -0
- package/dist/transformation/visitors/binary-expression/compound.d.ts +1 -1
- package/dist/transformation/visitors/binary-expression/compound.js +7 -7
- package/dist/transformation/visitors/binary-expression/index.d.ts +2 -2
- package/dist/transformation/visitors/binary-expression/index.js +2 -1
- package/dist/transformation/visitors/class/index.js +8 -4
- package/dist/transformation/visitors/class/utils.d.ts +1 -1
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/language-extensions/call-extension.d.ts +2 -2
- package/dist/transformation/visitors/template.js +2 -2
- package/dist/transformation/visitors/typescript.js +1 -0
- package/dist/transpilation/resolve.js +4 -0
- package/dist/transpilation/utils.d.ts +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +3 -3
- package/dist/lualib/5.0/Modulo50.lua +0 -3
- package/dist/lualib/universal/Modulo50.lua +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
|
|
2
|
+
type OmitIndexSignature<T> = {
|
|
3
3
|
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
4
4
|
};
|
|
5
5
|
export interface TransformerImport {
|
|
@@ -33,7 +33,7 @@ export interface TypeScriptToLuaOptions {
|
|
|
33
33
|
lua51AllowTryCatchInAsyncAwait?: boolean;
|
|
34
34
|
measurePerformance?: boolean;
|
|
35
35
|
}
|
|
36
|
-
export
|
|
36
|
+
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & TypeScriptToLuaOptions & {
|
|
37
37
|
[option: string]: any;
|
|
38
38
|
};
|
|
39
39
|
export declare enum LuaLibImportKind {
|
package/dist/LuaAST.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import { LuaLibFeature } from "./
|
|
2
|
+
import { LuaLibFeature } from "./LuaLib";
|
|
3
3
|
export declare enum SyntaxKind {
|
|
4
4
|
File = 0,
|
|
5
5
|
Block = 1,
|
|
@@ -58,12 +58,12 @@ export declare enum SyntaxKind {
|
|
|
58
58
|
BitwiseLeftShiftOperator = 54,
|
|
59
59
|
BitwiseNotOperator = 55
|
|
60
60
|
}
|
|
61
|
-
export
|
|
62
|
-
export
|
|
63
|
-
export
|
|
64
|
-
export
|
|
65
|
-
export
|
|
66
|
-
export
|
|
61
|
+
export type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;
|
|
62
|
+
export type UnaryOperator = SyntaxKind.NegationOperator | SyntaxKind.LengthOperator | SyntaxKind.NotOperator | UnaryBitwiseOperator;
|
|
63
|
+
export type BinaryBitwiseOperator = SyntaxKind.BitwiseAndOperator | SyntaxKind.BitwiseOrOperator | SyntaxKind.BitwiseExclusiveOrOperator | SyntaxKind.BitwiseRightShiftOperator | SyntaxKind.BitwiseLeftShiftOperator;
|
|
64
|
+
export type BinaryOperator = SyntaxKind.AdditionOperator | SyntaxKind.SubtractionOperator | SyntaxKind.MultiplicationOperator | SyntaxKind.DivisionOperator | SyntaxKind.FloorDivisionOperator | SyntaxKind.ModuloOperator | SyntaxKind.PowerOperator | SyntaxKind.ConcatOperator | SyntaxKind.EqualityOperator | SyntaxKind.InequalityOperator | SyntaxKind.LessThanOperator | SyntaxKind.LessEqualOperator | SyntaxKind.GreaterThanOperator | SyntaxKind.GreaterEqualOperator | SyntaxKind.AndOperator | SyntaxKind.OrOperator | BinaryBitwiseOperator;
|
|
65
|
+
export type Operator = UnaryOperator | BinaryOperator;
|
|
66
|
+
export type SymbolId = number & {
|
|
67
67
|
_symbolIdBrand: any;
|
|
68
68
|
};
|
|
69
69
|
export declare enum NodeFlags {
|
|
@@ -300,13 +300,13 @@ export interface TableIndexExpression extends Expression {
|
|
|
300
300
|
}
|
|
301
301
|
export declare function isTableIndexExpression(node: Node): node is TableIndexExpression;
|
|
302
302
|
export declare function createTableIndexExpression(table: Expression, index: Expression, tsOriginal?: ts.Node): TableIndexExpression;
|
|
303
|
-
export
|
|
303
|
+
export type AssignmentLeftHandSideExpression = Identifier | TableIndexExpression;
|
|
304
304
|
export declare function isAssignmentLeftHandSideExpression(node: Node): node is AssignmentLeftHandSideExpression;
|
|
305
|
-
export
|
|
305
|
+
export type FunctionDefinition = (VariableDeclarationStatement | AssignmentStatement) & {
|
|
306
306
|
right: [FunctionExpression];
|
|
307
307
|
};
|
|
308
308
|
export declare function isFunctionDefinition(statement: VariableDeclarationStatement | AssignmentStatement): statement is FunctionDefinition;
|
|
309
|
-
export
|
|
309
|
+
export type InlineFunctionExpression = FunctionExpression & {
|
|
310
310
|
body: {
|
|
311
311
|
statements: [ReturnStatement & {
|
|
312
312
|
expressions: Expression[];
|
package/dist/LuaLib.d.ts
CHANGED
|
@@ -50,7 +50,6 @@ export declare enum LuaLibFeature {
|
|
|
50
50
|
MathAtan2 = "MathAtan2",
|
|
51
51
|
MathModf = "MathModf",
|
|
52
52
|
MathSign = "MathSign",
|
|
53
|
-
Modulo50 = "Modulo50",
|
|
54
53
|
New = "New",
|
|
55
54
|
Number = "Number",
|
|
56
55
|
NumberIsFinite = "NumberIsFinite",
|
|
@@ -107,7 +106,7 @@ export interface LuaLibFeatureInfo {
|
|
|
107
106
|
dependencies?: LuaLibFeature[];
|
|
108
107
|
exports: string[];
|
|
109
108
|
}
|
|
110
|
-
export
|
|
109
|
+
export type LuaLibModulesInfo = Record<LuaLibFeature, LuaLibFeatureInfo>;
|
|
111
110
|
export declare function resolveLuaLibDir(luaTarget: LuaTarget): string;
|
|
112
111
|
export declare const luaLibModulesInfoFileName = "lualib_module_info.json";
|
|
113
112
|
export declare function getLuaLibModulesInfo(luaTarget: LuaTarget, emitHost: EmitHost): LuaLibModulesInfo;
|
package/dist/LuaLib.js
CHANGED
|
@@ -54,7 +54,6 @@ var LuaLibFeature;
|
|
|
54
54
|
LuaLibFeature["MathAtan2"] = "MathAtan2";
|
|
55
55
|
LuaLibFeature["MathModf"] = "MathModf";
|
|
56
56
|
LuaLibFeature["MathSign"] = "MathSign";
|
|
57
|
-
LuaLibFeature["Modulo50"] = "Modulo50";
|
|
58
57
|
LuaLibFeature["New"] = "New";
|
|
59
58
|
LuaLibFeature["Number"] = "Number";
|
|
60
59
|
LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
|
package/dist/LuaPrinter.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import * as lua from "./LuaAST";
|
|
|
5
5
|
import { EmitHost } from "./transpilation";
|
|
6
6
|
export declare const escapeString: (value: string) => string;
|
|
7
7
|
export declare const tstlHeader = "--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]\n";
|
|
8
|
-
|
|
9
|
-
export
|
|
8
|
+
type SourceChunk = string | SourceNode;
|
|
9
|
+
export type Printer = (program: ts.Program, emitHost: EmitHost, fileName: string, file: lua.File) => PrintResult;
|
|
10
10
|
export interface PrintResult {
|
|
11
11
|
code: string;
|
|
12
12
|
sourceMap: string;
|
package/dist/cli/parse.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
|
|
|
15
15
|
interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
|
|
16
16
|
type: "boolean" | "string" | "json-array-of-objects" | "array";
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
|
|
19
19
|
export declare const optionDeclarations: CommandLineOption[];
|
|
20
20
|
export declare function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine): ParsedCommandLine;
|
|
21
21
|
export declare function parseCommandLine(args: string[]): ParsedCommandLine;
|
package/dist/cli/parse.js
CHANGED
|
@@ -125,7 +125,7 @@ function updateParsedCommandLine(parsedCommandLine, args) {
|
|
|
125
125
|
if (!args[i].startsWith("-"))
|
|
126
126
|
continue;
|
|
127
127
|
const isShorthand = !args[i].startsWith("--");
|
|
128
|
-
const argumentName = args[i].
|
|
128
|
+
const argumentName = args[i].substring(isShorthand ? 1 : 2);
|
|
129
129
|
const option = exports.optionDeclarations.find(option => {
|
|
130
130
|
if (option.name.toLowerCase() === argumentName.toLowerCase())
|
|
131
131
|
return true;
|
|
@@ -9,12 +9,12 @@ do
|
|
|
9
9
|
base = 16
|
|
10
10
|
local ____TS__Match_result__0_0
|
|
11
11
|
if __TS__Match(hexMatch, "-") then
|
|
12
|
-
____TS__Match_result__0_0 = "-" ..
|
|
12
|
+
____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(
|
|
13
13
|
numberString,
|
|
14
14
|
string.len(hexMatch)
|
|
15
15
|
)
|
|
16
16
|
else
|
|
17
|
-
____TS__Match_result__0_0 =
|
|
17
|
+
____TS__Match_result__0_0 = __TS__StringSubstring(
|
|
18
18
|
numberString,
|
|
19
19
|
string.len(hexMatch)
|
|
20
20
|
)
|
|
@@ -29,7 +29,7 @@ do
|
|
|
29
29
|
if base <= 10 then
|
|
30
30
|
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
|
|
31
31
|
else
|
|
32
|
-
____temp_1 =
|
|
32
|
+
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
33
33
|
end
|
|
34
34
|
local allowedDigits = ____temp_1
|
|
35
35
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
@@ -71,8 +71,7 @@ do
|
|
|
71
71
|
if not rawget(metatable, "_descriptors") then
|
|
72
72
|
metatable._descriptors = {}
|
|
73
73
|
end
|
|
74
|
-
|
|
75
|
-
metatable._descriptors[key] = descriptor
|
|
74
|
+
metatable._descriptors[key] = __TS__CloneDescriptor(desc)
|
|
76
75
|
metatable.__index = descriptorIndex
|
|
77
76
|
metatable.__newindex = descriptorNewIndex
|
|
78
77
|
end
|
|
@@ -971,8 +971,7 @@ do
|
|
|
971
971
|
if not rawget(metatable, "_descriptors") then
|
|
972
972
|
metatable._descriptors = {}
|
|
973
973
|
end
|
|
974
|
-
|
|
975
|
-
metatable._descriptors[key] = descriptor
|
|
974
|
+
metatable._descriptors[key] = __TS__CloneDescriptor(desc)
|
|
976
975
|
metatable.__index = descriptorIndex
|
|
977
976
|
metatable.__newindex = descriptorNewIndex
|
|
978
977
|
end
|
|
@@ -1446,10 +1445,6 @@ local function __TS__MathSign(val)
|
|
|
1446
1445
|
return 0
|
|
1447
1446
|
end
|
|
1448
1447
|
|
|
1449
|
-
local function __TS__Modulo50(a, b)
|
|
1450
|
-
return a - math.floor(a / b) * b
|
|
1451
|
-
end
|
|
1452
|
-
|
|
1453
1448
|
local function __TS__Number(value)
|
|
1454
1449
|
local valueType = type(value)
|
|
1455
1450
|
if valueType == "number" then
|
|
@@ -1507,7 +1502,7 @@ do
|
|
|
1507
1502
|
do
|
|
1508
1503
|
result = __TS__StringAccess(
|
|
1509
1504
|
radixChars,
|
|
1510
|
-
|
|
1505
|
+
math.mod(integer, radix)
|
|
1511
1506
|
) .. result
|
|
1512
1507
|
integer = math.floor(integer / radix)
|
|
1513
1508
|
end
|
|
@@ -1673,22 +1668,6 @@ local function __TS__ParseFloat(numberString)
|
|
|
1673
1668
|
return ____number_1
|
|
1674
1669
|
end
|
|
1675
1670
|
|
|
1676
|
-
local function __TS__StringSubstr(self, from, length)
|
|
1677
|
-
if from ~= from then
|
|
1678
|
-
from = 0
|
|
1679
|
-
end
|
|
1680
|
-
if length ~= nil then
|
|
1681
|
-
if length ~= length or length <= 0 then
|
|
1682
|
-
return ""
|
|
1683
|
-
end
|
|
1684
|
-
length = length + from
|
|
1685
|
-
end
|
|
1686
|
-
if from >= 0 then
|
|
1687
|
-
from = from + 1
|
|
1688
|
-
end
|
|
1689
|
-
return string.sub(self, from, length)
|
|
1690
|
-
end
|
|
1691
|
-
|
|
1692
1671
|
local function __TS__StringSubstring(self, start, ____end)
|
|
1693
1672
|
if ____end ~= ____end then
|
|
1694
1673
|
____end = 0
|
|
@@ -1718,12 +1697,12 @@ do
|
|
|
1718
1697
|
base = 16
|
|
1719
1698
|
local ____TS__Match_result__0_0
|
|
1720
1699
|
if __TS__Match(hexMatch, "-") then
|
|
1721
|
-
____TS__Match_result__0_0 = "-" ..
|
|
1700
|
+
____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(
|
|
1722
1701
|
numberString,
|
|
1723
1702
|
string.len(hexMatch)
|
|
1724
1703
|
)
|
|
1725
1704
|
else
|
|
1726
|
-
____TS__Match_result__0_0 =
|
|
1705
|
+
____TS__Match_result__0_0 = __TS__StringSubstring(
|
|
1727
1706
|
numberString,
|
|
1728
1707
|
string.len(hexMatch)
|
|
1729
1708
|
)
|
|
@@ -1738,7 +1717,7 @@ do
|
|
|
1738
1717
|
if base <= 10 then
|
|
1739
1718
|
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
|
|
1740
1719
|
else
|
|
1741
|
-
____temp_1 =
|
|
1720
|
+
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1742
1721
|
end
|
|
1743
1722
|
local allowedDigits = ____temp_1
|
|
1744
1723
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
@@ -2435,6 +2414,22 @@ local function __TS__StringStartsWith(self, searchString, position)
|
|
|
2435
2414
|
) == searchString
|
|
2436
2415
|
end
|
|
2437
2416
|
|
|
2417
|
+
local function __TS__StringSubstr(self, from, length)
|
|
2418
|
+
if from ~= from then
|
|
2419
|
+
from = 0
|
|
2420
|
+
end
|
|
2421
|
+
if length ~= nil then
|
|
2422
|
+
if length ~= length or length <= 0 then
|
|
2423
|
+
return ""
|
|
2424
|
+
end
|
|
2425
|
+
length = length + from
|
|
2426
|
+
end
|
|
2427
|
+
if from >= 0 then
|
|
2428
|
+
from = from + 1
|
|
2429
|
+
end
|
|
2430
|
+
return string.sub(self, from, length)
|
|
2431
|
+
end
|
|
2432
|
+
|
|
2438
2433
|
local function __TS__StringTrim(self)
|
|
2439
2434
|
local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
|
|
2440
2435
|
return result
|
|
@@ -2534,7 +2529,6 @@ return {
|
|
|
2534
2529
|
__TS__MathAtan2 = __TS__MathAtan2,
|
|
2535
2530
|
__TS__MathModf = __TS__MathModf,
|
|
2536
2531
|
__TS__MathSign = __TS__MathSign,
|
|
2537
|
-
__TS__Modulo50 = __TS__Modulo50,
|
|
2538
2532
|
__TS__New = __TS__New,
|
|
2539
2533
|
__TS__Number = __TS__Number,
|
|
2540
2534
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
@@ -319,11 +319,6 @@
|
|
|
319
319
|
"__TS__MathSign"
|
|
320
320
|
]
|
|
321
321
|
},
|
|
322
|
-
"Modulo50": {
|
|
323
|
-
"exports": [
|
|
324
|
-
"__TS__Modulo50"
|
|
325
|
-
]
|
|
326
|
-
},
|
|
327
322
|
"New": {
|
|
328
323
|
"exports": [
|
|
329
324
|
"__TS__New"
|
|
@@ -349,7 +344,6 @@
|
|
|
349
344
|
"__TS__NumberToString"
|
|
350
345
|
],
|
|
351
346
|
"dependencies": [
|
|
352
|
-
"Modulo50",
|
|
353
347
|
"StringAccess",
|
|
354
348
|
"MathModf"
|
|
355
349
|
]
|
|
@@ -419,7 +413,6 @@
|
|
|
419
413
|
"__TS__ParseInt"
|
|
420
414
|
],
|
|
421
415
|
"dependencies": [
|
|
422
|
-
"StringSubstr",
|
|
423
416
|
"StringSubstring",
|
|
424
417
|
"Match"
|
|
425
418
|
]
|
|
@@ -9,9 +9,9 @@ do
|
|
|
9
9
|
base = 16
|
|
10
10
|
local ____TS__Match_result__0_0
|
|
11
11
|
if __TS__Match(hexMatch, "-") then
|
|
12
|
-
____TS__Match_result__0_0 = "-" ..
|
|
12
|
+
____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
|
|
13
13
|
else
|
|
14
|
-
____TS__Match_result__0_0 =
|
|
14
|
+
____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
|
|
15
15
|
end
|
|
16
16
|
numberString = ____TS__Match_result__0_0
|
|
17
17
|
end
|
|
@@ -23,7 +23,7 @@ do
|
|
|
23
23
|
if base <= 10 then
|
|
24
24
|
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
|
|
25
25
|
else
|
|
26
|
-
____temp_1 =
|
|
26
|
+
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
27
27
|
end
|
|
28
28
|
local allowedDigits = ____temp_1
|
|
29
29
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
@@ -71,8 +71,7 @@ do
|
|
|
71
71
|
if not rawget(metatable, "_descriptors") then
|
|
72
72
|
metatable._descriptors = {}
|
|
73
73
|
end
|
|
74
|
-
|
|
75
|
-
metatable._descriptors[key] = descriptor
|
|
74
|
+
metatable._descriptors[key] = __TS__CloneDescriptor(desc)
|
|
76
75
|
metatable.__index = descriptorIndex
|
|
77
76
|
metatable.__newindex = descriptorNewIndex
|
|
78
77
|
end
|
|
@@ -972,8 +972,7 @@ do
|
|
|
972
972
|
if not rawget(metatable, "_descriptors") then
|
|
973
973
|
metatable._descriptors = {}
|
|
974
974
|
end
|
|
975
|
-
|
|
976
|
-
metatable._descriptors[key] = descriptor
|
|
975
|
+
metatable._descriptors[key] = __TS__CloneDescriptor(desc)
|
|
977
976
|
metatable.__index = descriptorIndex
|
|
978
977
|
metatable.__newindex = descriptorNewIndex
|
|
979
978
|
end
|
|
@@ -1385,10 +1384,6 @@ local function __TS__MathSign(val)
|
|
|
1385
1384
|
return 0
|
|
1386
1385
|
end
|
|
1387
1386
|
|
|
1388
|
-
local function __TS__Modulo50(a, b)
|
|
1389
|
-
return a - math.floor(a / b) * b
|
|
1390
|
-
end
|
|
1391
|
-
|
|
1392
1387
|
local function __TS__Number(value)
|
|
1393
1388
|
local valueType = type(value)
|
|
1394
1389
|
if valueType == "number" then
|
|
@@ -1609,22 +1604,6 @@ local function __TS__ParseFloat(numberString)
|
|
|
1609
1604
|
return ____number_1
|
|
1610
1605
|
end
|
|
1611
1606
|
|
|
1612
|
-
local function __TS__StringSubstr(self, from, length)
|
|
1613
|
-
if from ~= from then
|
|
1614
|
-
from = 0
|
|
1615
|
-
end
|
|
1616
|
-
if length ~= nil then
|
|
1617
|
-
if length ~= length or length <= 0 then
|
|
1618
|
-
return ""
|
|
1619
|
-
end
|
|
1620
|
-
length = length + from
|
|
1621
|
-
end
|
|
1622
|
-
if from >= 0 then
|
|
1623
|
-
from = from + 1
|
|
1624
|
-
end
|
|
1625
|
-
return string.sub(self, from, length)
|
|
1626
|
-
end
|
|
1627
|
-
|
|
1628
1607
|
local function __TS__StringSubstring(self, start, ____end)
|
|
1629
1608
|
if ____end ~= ____end then
|
|
1630
1609
|
____end = 0
|
|
@@ -1654,9 +1633,9 @@ do
|
|
|
1654
1633
|
base = 16
|
|
1655
1634
|
local ____TS__Match_result__0_0
|
|
1656
1635
|
if __TS__Match(hexMatch, "-") then
|
|
1657
|
-
____TS__Match_result__0_0 = "-" ..
|
|
1636
|
+
____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
|
|
1658
1637
|
else
|
|
1659
|
-
____TS__Match_result__0_0 =
|
|
1638
|
+
____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
|
|
1660
1639
|
end
|
|
1661
1640
|
numberString = ____TS__Match_result__0_0
|
|
1662
1641
|
end
|
|
@@ -1668,7 +1647,7 @@ do
|
|
|
1668
1647
|
if base <= 10 then
|
|
1669
1648
|
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
|
|
1670
1649
|
else
|
|
1671
|
-
____temp_1 =
|
|
1650
|
+
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1672
1651
|
end
|
|
1673
1652
|
local allowedDigits = ____temp_1
|
|
1674
1653
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
@@ -2378,6 +2357,22 @@ local function __TS__StringStartsWith(self, searchString, position)
|
|
|
2378
2357
|
return string.sub(self, position + 1, #searchString + position) == searchString
|
|
2379
2358
|
end
|
|
2380
2359
|
|
|
2360
|
+
local function __TS__StringSubstr(self, from, length)
|
|
2361
|
+
if from ~= from then
|
|
2362
|
+
from = 0
|
|
2363
|
+
end
|
|
2364
|
+
if length ~= nil then
|
|
2365
|
+
if length ~= length or length <= 0 then
|
|
2366
|
+
return ""
|
|
2367
|
+
end
|
|
2368
|
+
length = length + from
|
|
2369
|
+
end
|
|
2370
|
+
if from >= 0 then
|
|
2371
|
+
from = from + 1
|
|
2372
|
+
end
|
|
2373
|
+
return string.sub(self, from, length)
|
|
2374
|
+
end
|
|
2375
|
+
|
|
2381
2376
|
local function __TS__StringTrim(self)
|
|
2382
2377
|
local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
|
|
2383
2378
|
return result
|
|
@@ -2477,7 +2472,6 @@ return {
|
|
|
2477
2472
|
__TS__MathAtan2 = __TS__MathAtan2,
|
|
2478
2473
|
__TS__MathModf = __TS__MathModf,
|
|
2479
2474
|
__TS__MathSign = __TS__MathSign,
|
|
2480
|
-
__TS__Modulo50 = __TS__Modulo50,
|
|
2481
2475
|
__TS__New = __TS__New,
|
|
2482
2476
|
__TS__Number = __TS__Number,
|
|
2483
2477
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
@@ -319,11 +319,6 @@
|
|
|
319
319
|
"__TS__MathSign"
|
|
320
320
|
]
|
|
321
321
|
},
|
|
322
|
-
"Modulo50": {
|
|
323
|
-
"exports": [
|
|
324
|
-
"__TS__Modulo50"
|
|
325
|
-
]
|
|
326
|
-
},
|
|
327
322
|
"New": {
|
|
328
323
|
"exports": [
|
|
329
324
|
"__TS__New"
|
|
@@ -418,7 +413,6 @@
|
|
|
418
413
|
"__TS__ParseInt"
|
|
419
414
|
],
|
|
420
415
|
"dependencies": [
|
|
421
|
-
"StringSubstr",
|
|
422
416
|
"StringSubstring",
|
|
423
417
|
"Match"
|
|
424
418
|
]
|
|
@@ -7,7 +7,7 @@ export declare const lualibDiagnostic: ((message: string, file?: ts.SourceFile |
|
|
|
7
7
|
};
|
|
8
8
|
declare class LuaLibPlugin implements tstl.Plugin {
|
|
9
9
|
visitors: {
|
|
10
|
-
|
|
10
|
+
308: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
|
|
11
11
|
};
|
|
12
12
|
printer: tstl.Printer;
|
|
13
13
|
afterPrint(program: ts.Program, options: tstl.CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]): ts.Diagnostic[];
|
|
@@ -3,14 +3,14 @@ export declare function isExportTableDeclaration(node: tstl.Node): node is tstl.
|
|
|
3
3
|
left: [];
|
|
4
4
|
};
|
|
5
5
|
export declare function isExportTable(node: tstl.Node): node is tstl.Identifier;
|
|
6
|
-
export
|
|
6
|
+
export type ExportTableIndex = tstl.TableIndexExpression & {
|
|
7
7
|
index: tstl.StringLiteral;
|
|
8
8
|
};
|
|
9
9
|
export declare function isExportTableIndex(node: tstl.Node): node is ExportTableIndex;
|
|
10
10
|
export declare function isExportAlias(node: tstl.Node): node is tstl.VariableDeclarationStatement & {
|
|
11
11
|
right: [ExportTableIndex];
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type ExportAssignment = tstl.AssignmentStatement & {
|
|
14
14
|
left: [ExportTableIndex];
|
|
15
15
|
};
|
|
16
16
|
export declare function isExportAssignment(node: tstl.Node): node is ExportAssignment;
|
|
@@ -48,7 +48,8 @@ class TransformationContext {
|
|
|
48
48
|
transformNodeRaw(node, isExpression) {
|
|
49
49
|
var _a;
|
|
50
50
|
// TODO: Move to visitors?
|
|
51
|
-
if ((
|
|
51
|
+
if (ts.canHaveModifiers(node) &&
|
|
52
|
+
((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword))) {
|
|
52
53
|
return [];
|
|
53
54
|
}
|
|
54
55
|
const nodeVisitors = this.visitorMap.get(node.kind);
|
|
@@ -59,6 +59,7 @@ interface NodesBySyntaxKind {
|
|
|
59
59
|
[ts.SyntaxKind.AsExpression]: ts.AsExpression;
|
|
60
60
|
[ts.SyntaxKind.NonNullExpression]: ts.NonNullExpression;
|
|
61
61
|
[ts.SyntaxKind.MetaProperty]: ts.MetaProperty;
|
|
62
|
+
[ts.SyntaxKind.SatisfiesExpression]: ts.SatisfiesExpression;
|
|
62
63
|
[ts.SyntaxKind.TemplateSpan]: ts.TemplateSpan;
|
|
63
64
|
[ts.SyntaxKind.SemicolonClassElement]: ts.SemicolonClassElement;
|
|
64
65
|
[ts.SyntaxKind.Block]: ts.Block;
|
|
@@ -130,11 +131,11 @@ interface NodesBySyntaxKind {
|
|
|
130
131
|
[ts.SyntaxKind.ThisKeyword]: ts.ThisExpression;
|
|
131
132
|
[ts.SyntaxKind.NotEmittedStatement]: ts.NotEmittedStatement;
|
|
132
133
|
}
|
|
133
|
-
export
|
|
134
|
-
export
|
|
135
|
-
export
|
|
136
|
-
export
|
|
137
|
-
export
|
|
134
|
+
export type ExpressionLikeNode = ts.Expression | ts.QualifiedName | ts.ExternalModuleReference;
|
|
135
|
+
export type StatementLikeNode = ts.Statement;
|
|
136
|
+
export type VisitorResult<T extends ts.Node> = T extends ExpressionLikeNode ? lua.Expression : T extends StatementLikeNode ? OneToManyVisitorResult<lua.Statement> : T extends ts.SourceFile ? lua.File : OneToManyVisitorResult<lua.Node>;
|
|
137
|
+
export type Visitor<T extends ts.Node> = FunctionVisitor<T> | ObjectVisitor<T>;
|
|
138
|
+
export type FunctionVisitor<T extends ts.Node> = (node: T, context: TransformationContext) => VisitorResult<T>;
|
|
138
139
|
export interface ObjectVisitor<T extends ts.Node> {
|
|
139
140
|
transform: FunctionVisitor<T>;
|
|
140
141
|
/**
|
|
@@ -146,8 +147,8 @@ export interface ObjectVisitor<T extends ts.Node> {
|
|
|
146
147
|
*/
|
|
147
148
|
priority?: number;
|
|
148
149
|
}
|
|
149
|
-
export
|
|
150
|
+
export type Visitors = {
|
|
150
151
|
[P in keyof NodesBySyntaxKind]?: Visitor<NodesBySyntaxKind[P]>;
|
|
151
152
|
};
|
|
152
|
-
export
|
|
153
|
+
export type VisitorMap = Map<ts.SyntaxKind, Array<FunctionVisitor<ts.Node>>>;
|
|
153
154
|
export {};
|
|
@@ -10,7 +10,7 @@ export interface Annotation {
|
|
|
10
10
|
kind: AnnotationKind;
|
|
11
11
|
args: string[];
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type AnnotationsMap = Map<AnnotationKind, Annotation>;
|
|
14
14
|
export declare function getSymbolAnnotations(symbol: ts.Symbol): AnnotationsMap;
|
|
15
15
|
export declare function getTypeAnnotations(type: ts.Type): AnnotationsMap;
|
|
16
16
|
export declare function getNodeAnnotations(node: ts.Node): AnnotationsMap;
|
|
@@ -64,21 +64,12 @@ export declare const invalidMultiFunctionUse: ((node: ts.Node, ...args: any[]) =
|
|
|
64
64
|
export declare const invalidMultiFunctionReturnType: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
65
65
|
code: number;
|
|
66
66
|
};
|
|
67
|
-
export declare const invalidMultiTypeToNonArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
68
|
-
code: number;
|
|
69
|
-
};
|
|
70
|
-
export declare const invalidMultiTypeToEmptyPatternOrArrayLiteral: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
71
|
-
code: number;
|
|
72
|
-
};
|
|
73
67
|
export declare const invalidMultiReturnAccess: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
74
68
|
code: number;
|
|
75
69
|
};
|
|
76
70
|
export declare const invalidCallExtensionUse: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
|
|
77
71
|
code: number;
|
|
78
72
|
};
|
|
79
|
-
export declare const annotationRemoved: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
|
|
80
|
-
code: number;
|
|
81
|
-
};
|
|
82
73
|
export declare const annotationDeprecated: ((node: ts.Node, kind: AnnotationKind) => ts.Diagnostic) & {
|
|
83
74
|
code: number;
|
|
84
75
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.
|
|
3
|
+
exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
@@ -49,12 +49,8 @@ exports.invalidAmbientIdentifierName = createErrorDiagnosticFactory((text) => `I
|
|
|
49
49
|
exports.unsupportedVarDeclaration = createErrorDiagnosticFactory("`var` declarations are not supported. Use `let` or `const` instead.");
|
|
50
50
|
exports.invalidMultiFunctionUse = createErrorDiagnosticFactory("The $multi function must be called in a return statement.");
|
|
51
51
|
exports.invalidMultiFunctionReturnType = createErrorDiagnosticFactory("The $multi function cannot be cast to a non-LuaMultiReturn type.");
|
|
52
|
-
exports.invalidMultiTypeToNonArrayLiteral = createErrorDiagnosticFactory("Expected an array literal.");
|
|
53
|
-
exports.invalidMultiTypeToEmptyPatternOrArrayLiteral = createErrorDiagnosticFactory("There must be one or more elements specified here.");
|
|
54
52
|
exports.invalidMultiReturnAccess = createErrorDiagnosticFactory("The LuaMultiReturn type can only be accessed via an element access expression of a numeric type.");
|
|
55
53
|
exports.invalidCallExtensionUse = createErrorDiagnosticFactory("This function must be called directly and cannot be referred to.");
|
|
56
|
-
exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' has been removed and will no longer have any effect.` +
|
|
57
|
-
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
58
54
|
exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
|
|
59
55
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
60
56
|
exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Only false and nil evaluate to 'false' in Lua, everything else is considered 'true'. Explicitly compare the value with ===.");
|
|
@@ -9,12 +9,14 @@ const symbols_1 = require("./symbols");
|
|
|
9
9
|
const typescript_1 = require("./typescript");
|
|
10
10
|
function hasDefaultExportModifier(node) {
|
|
11
11
|
var _a;
|
|
12
|
-
return ((
|
|
12
|
+
return (ts.canHaveModifiers(node) &&
|
|
13
|
+
((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) === true);
|
|
13
14
|
}
|
|
14
15
|
exports.hasDefaultExportModifier = hasDefaultExportModifier;
|
|
15
16
|
function hasExportModifier(node) {
|
|
16
17
|
var _a;
|
|
17
|
-
return ((
|
|
18
|
+
return (ts.canHaveModifiers(node) &&
|
|
19
|
+
((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)) === true);
|
|
18
20
|
}
|
|
19
21
|
exports.hasExportModifier = hasExportModifier;
|
|
20
22
|
const createDefaultExportStringLiteral = (original) => lua.createStringLiteral("default", original);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
|
-
export
|
|
4
|
+
export type OneToManyVisitorResult<T extends lua.Node> = T | T[] | undefined;
|
|
5
5
|
export declare function unwrapVisitorResult<T extends lua.Node>(result: OneToManyVisitorResult<T>): T[];
|
|
6
6
|
export declare function createSelfIdentifier(tsOriginal?: ts.Node): lua.Identifier;
|
|
7
7
|
export declare function createExportsIdentifier(): lua.Identifier;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../../context";
|
|
4
|
-
export
|
|
4
|
+
export type BitOperator = ts.ShiftOperator | ts.BitwiseOperator;
|
|
5
5
|
export declare const isBitOperator: (operator: ts.BinaryOperator) => operator is BitOperator;
|
|
6
6
|
export declare function transformBinaryBitOperation(context: TransformationContext, node: ts.Node, left: lua.Expression, right: lua.Expression, operator: BitOperator): lua.Expression;
|
|
7
7
|
export declare function transformUnaryBitOperation(context: TransformationContext, node: ts.Node, expression: lua.Expression, operator: lua.UnaryBitwiseOperator): lua.Expression;
|
|
@@ -32,6 +32,7 @@ function transformBitOperatorToLuaOperator(context, node, operator) {
|
|
|
32
32
|
return lua.SyntaxKind.BitwiseLeftShiftOperator;
|
|
33
33
|
case ts.SyntaxKind.GreaterThanGreaterThanToken:
|
|
34
34
|
context.diagnostics.push((0, diagnostics_1.unsupportedRightShiftOperator)(node));
|
|
35
|
+
return lua.SyntaxKind.BitwiseRightShiftOperator;
|
|
35
36
|
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
|
|
36
37
|
return lua.SyntaxKind.BitwiseRightShiftOperator;
|
|
37
38
|
}
|
|
@@ -42,6 +43,7 @@ function transformBinaryBitOperation(context, node, left, right, operator) {
|
|
|
42
43
|
case CompilerOptions_1.LuaTarget.Lua50:
|
|
43
44
|
case CompilerOptions_1.LuaTarget.Lua51:
|
|
44
45
|
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
|
|
46
|
+
return transformBinaryBitLibOperation(node, left, right, operator, "bit");
|
|
45
47
|
case CompilerOptions_1.LuaTarget.LuaJIT:
|
|
46
48
|
return transformBinaryBitLibOperation(node, left, right, operator, "bit");
|
|
47
49
|
case CompilerOptions_1.LuaTarget.Lua52:
|
|
@@ -69,6 +71,7 @@ function transformUnaryBitOperation(context, node, expression, operator) {
|
|
|
69
71
|
case CompilerOptions_1.LuaTarget.Lua50:
|
|
70
72
|
case CompilerOptions_1.LuaTarget.Lua51:
|
|
71
73
|
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Bitwise operations", context.luaTarget));
|
|
74
|
+
return transformUnaryBitLibOperation(node, expression, operator, "bit");
|
|
72
75
|
case CompilerOptions_1.LuaTarget.LuaJIT:
|
|
73
76
|
return transformUnaryBitLibOperation(node, expression, operator, "bit");
|
|
74
77
|
case CompilerOptions_1.LuaTarget.Lua52:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../../context";
|
|
4
|
-
|
|
4
|
+
type CompoundAssignmentToken = ts.SyntaxKind.BarToken | ts.SyntaxKind.PlusToken | ts.SyntaxKind.CaretToken | ts.SyntaxKind.MinusToken | ts.SyntaxKind.SlashToken | ts.SyntaxKind.PercentToken | ts.SyntaxKind.AsteriskToken | ts.SyntaxKind.AmpersandToken | ts.SyntaxKind.AsteriskAsteriskToken | ts.SyntaxKind.LessThanLessThanToken | ts.SyntaxKind.GreaterThanGreaterThanToken | ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.QuestionQuestionToken;
|
|
5
5
|
export declare const isCompoundAssignmentToken: (token: ts.BinaryOperator) => token is ts.CompoundAssignmentOperator;
|
|
6
6
|
export declare const unwrapCompoundAssignmentToken: (token: ts.CompoundAssignmentOperator) => CompoundAssignmentToken;
|
|
7
7
|
export declare function transformCompoundAssignment(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): {
|
|
@@ -5,7 +5,7 @@ const ts = require("typescript");
|
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
8
|
-
const
|
|
8
|
+
const index_1 = require("./index");
|
|
9
9
|
const assignments_1 = require("./assignments");
|
|
10
10
|
function isLuaExpressionWithSideEffect(expression) {
|
|
11
11
|
return !(lua.isLiteral(expression) || lua.isIdentifier(expression));
|
|
@@ -52,7 +52,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
52
52
|
// ____obj[____index] = ____tmp ${replacementOperator} ${right};
|
|
53
53
|
// return ____tmp
|
|
54
54
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, accessExpression);
|
|
55
|
-
const [precedingStatements, operatorExpression] = (0,
|
|
55
|
+
const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, tmp, right, rightPrecedingStatements, operator, expression);
|
|
56
56
|
const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
|
|
57
57
|
return {
|
|
58
58
|
statements: [objAndIndexDeclaration, ...precedingStatements, tmpDeclaration, assignStatement],
|
|
@@ -72,7 +72,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
72
72
|
// local ____tmp = ____obj[____index] ${replacementOperator} ${right};
|
|
73
73
|
// ____obj[____index] = ____tmp;
|
|
74
74
|
// return ____tmp
|
|
75
|
-
const [precedingStatements, operatorExpression] = (0,
|
|
75
|
+
const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, expression);
|
|
76
76
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, operatorExpression);
|
|
77
77
|
const assignStatement = lua.createAssignmentStatement(accessExpression, tmp);
|
|
78
78
|
return {
|
|
@@ -88,7 +88,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
88
88
|
// return ____tmp
|
|
89
89
|
const tmpIdentifier = context.createTempNameForLuaExpression(left);
|
|
90
90
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmpIdentifier, left);
|
|
91
|
-
const [precedingStatements, operatorExpression] = (0,
|
|
91
|
+
const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, tmpIdentifier, right, rightPrecedingStatements, operator, expression);
|
|
92
92
|
const assignStatements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
|
|
93
93
|
return { statements: [tmpDeclaration, ...precedingStatements, ...assignStatements], result: tmpIdentifier };
|
|
94
94
|
}
|
|
@@ -101,7 +101,7 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
101
101
|
}
|
|
102
102
|
// Simple expressions
|
|
103
103
|
// ${left} = ${left} ${operator} ${right}
|
|
104
|
-
const [precedingStatements, operatorExpression] = (0,
|
|
104
|
+
const [precedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, expression);
|
|
105
105
|
const statements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, precedingStatements);
|
|
106
106
|
return { statements, result: left };
|
|
107
107
|
}
|
|
@@ -133,7 +133,7 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
|
|
|
133
133
|
];
|
|
134
134
|
}
|
|
135
135
|
let operatorExpression;
|
|
136
|
-
[rightPrecedingStatements, operatorExpression] = (0,
|
|
136
|
+
[rightPrecedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, node);
|
|
137
137
|
const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
|
|
138
138
|
return [objAndIndexDeclaration, ...rightPrecedingStatements, assignStatement];
|
|
139
139
|
}
|
|
@@ -144,7 +144,7 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
|
|
|
144
144
|
// Simple statements
|
|
145
145
|
// ${left} = ${left} ${replacementOperator} ${right}
|
|
146
146
|
let operatorExpression;
|
|
147
|
-
[rightPrecedingStatements, operatorExpression] = (0,
|
|
147
|
+
[rightPrecedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, node);
|
|
148
148
|
return (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -2,8 +2,8 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../../context";
|
|
4
4
|
import { BitOperator } from "./bit";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type ShortCircuitOperator = ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.QuestionQuestionToken;
|
|
6
|
+
type SimpleOperator = ts.AdditiveOperatorOrHigher | Exclude<ts.RelationalOperator, ts.SyntaxKind.InstanceOfKeyword | ts.SyntaxKind.InKeyword> | ts.EqualityOperator | ts.LogicalOperator;
|
|
7
7
|
export declare function createShortCircuitBinaryExpressionPrecedingStatements(context: TransformationContext, lhs: lua.Expression, rhs: lua.Expression, rightPrecedingStatements: lua.Statement[], operator: ShortCircuitOperator, node?: ts.BinaryExpression): [lua.Statement[], lua.Expression];
|
|
8
8
|
export declare function transformBinaryOperation(context: TransformationContext, left: lua.Expression, right: lua.Expression, rightPrecedingStatements: lua.Statement[], operator: BitOperator | SimpleOperator | ts.SyntaxKind.QuestionQuestionToken, node: ts.Node): [lua.Statement[], lua.Expression];
|
|
9
9
|
export declare const transformBinaryExpression: FunctionVisitor<ts.BinaryExpression>;
|
|
@@ -44,7 +44,8 @@ function transformBinaryOperationWithNoPrecedingStatements(context, left, right,
|
|
|
44
44
|
return transformNullishCoalescingOperationNoPrecedingStatements(context, node, left, right);
|
|
45
45
|
}
|
|
46
46
|
if (operator === ts.SyntaxKind.PercentToken && context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
47
|
-
|
|
47
|
+
const mathMod = lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("mod"));
|
|
48
|
+
return lua.createCallExpression(mathMod, [left, right], node);
|
|
48
49
|
}
|
|
49
50
|
let luaOperator = simpleOperatorsToLua[operator];
|
|
50
51
|
// Check if we need to use string concat operator
|
|
@@ -15,12 +15,16 @@ const method_1 = require("./members/method");
|
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
16
|
const setup_1 = require("./setup");
|
|
17
17
|
const CompilerOptions_1 = require("../../../CompilerOptions");
|
|
18
|
+
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
18
19
|
const transformClassDeclaration = (declaration, context) => {
|
|
19
20
|
// If declaration is a default export, transform to export variable assignment instead
|
|
20
21
|
if ((0, export_1.hasDefaultExportModifier)(declaration)) {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
// Class declaration including assignment to ____exports.default are in preceding statements
|
|
23
|
+
const [precedingStatements] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => {
|
|
24
|
+
transformClassAsExpression(declaration, context);
|
|
25
|
+
return [];
|
|
26
|
+
});
|
|
27
|
+
return precedingStatements;
|
|
24
28
|
}
|
|
25
29
|
const { statements } = transformClassLikeDeclaration(declaration, context);
|
|
26
30
|
return statements;
|
|
@@ -74,7 +78,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
74
78
|
}
|
|
75
79
|
else if (!extendedType) {
|
|
76
80
|
// Generate a constructor if none was defined in a base class
|
|
77
|
-
const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, ts.factory.createConstructorDeclaration([], [],
|
|
81
|
+
const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, ts.factory.createConstructorDeclaration([], [], ts.factory.createBlock([], true)), localClassName, instanceFields, classDeclaration);
|
|
78
82
|
if (constructorResult)
|
|
79
83
|
result.push(constructorResult);
|
|
80
84
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import { TransformationContext } from "../../context";
|
|
3
|
-
export declare function isStaticNode(node: ts.
|
|
3
|
+
export declare function isStaticNode(node: ts.HasModifiers): boolean;
|
|
4
4
|
export declare function getExtendsClause(node: ts.ClassLikeDeclarationBase): ts.HeritageClause | undefined;
|
|
5
5
|
export declare function getExtendedNode(node: ts.ClassLikeDeclarationBase): ts.ExpressionWithTypeArguments | undefined;
|
|
6
6
|
export declare function getExtendedType(context: TransformationContext, node: ts.ClassLikeDeclarationBase): ts.Type | undefined;
|
|
@@ -4,12 +4,12 @@ exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = e
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
function isStaticNode(node) {
|
|
6
6
|
var _a;
|
|
7
|
-
return ((_a = node.modifiers)
|
|
7
|
+
return ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.StaticKeyword)) === true;
|
|
8
8
|
}
|
|
9
9
|
exports.isStaticNode = isStaticNode;
|
|
10
10
|
function getExtendsClause(node) {
|
|
11
11
|
var _a;
|
|
12
|
-
return (
|
|
12
|
+
return (_a = node.heritageClauses) === null || _a === void 0 ? void 0 : _a.find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
|
|
13
13
|
}
|
|
14
14
|
exports.getExtendsClause = getExtendsClause;
|
|
15
15
|
function getExtendedNode(node) {
|
|
@@ -3,8 +3,8 @@ import * as ts from "typescript";
|
|
|
3
3
|
import { ExtensionKind } from "../../utils/language-extensions";
|
|
4
4
|
import * as lua from "../../../LuaAST";
|
|
5
5
|
export declare const callExtensions: Set<ExtensionKind>;
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export type LanguageExtensionCallTransformer = (context: TransformationContext, node: ts.CallExpression, extensionKind: ExtensionKind) => lua.Expression;
|
|
7
|
+
export type LanguageExtensionCallTransformerMap = {
|
|
8
8
|
[P in ExtensionKind]?: LanguageExtensionCallTransformer;
|
|
9
9
|
};
|
|
10
10
|
export declare function transformLanguageExtensionCallExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression | undefined;
|
|
@@ -5,7 +5,7 @@ const ts = require("typescript");
|
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const function_context_1 = require("../utils/function-context");
|
|
7
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
8
|
-
const
|
|
8
|
+
const typescript_1 = require("../utils/typescript");
|
|
9
9
|
const call_1 = require("./call");
|
|
10
10
|
const expression_list_1 = require("./expression-list");
|
|
11
11
|
// TODO: Source positions
|
|
@@ -27,7 +27,7 @@ const transformTemplateExpression = (node, context) => {
|
|
|
27
27
|
const span = node.templateSpans[i];
|
|
28
28
|
const expression = transformedExpressions[i];
|
|
29
29
|
const spanType = context.checker.getTypeAtLocation(span.expression);
|
|
30
|
-
if ((0,
|
|
30
|
+
if ((0, typescript_1.isStringType)(context, spanType)) {
|
|
31
31
|
parts.push(expression);
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
@@ -14,6 +14,7 @@ exports.typescriptVisitors = {
|
|
|
14
14
|
[ts.SyntaxKind.InterfaceDeclaration]: () => undefined,
|
|
15
15
|
[ts.SyntaxKind.NonNullExpression]: (node, context) => context.transformExpression(node.expression),
|
|
16
16
|
[ts.SyntaxKind.ExpressionWithTypeArguments]: (node, context) => context.transformExpression(node.expression),
|
|
17
|
+
[ts.SyntaxKind.SatisfiesExpression]: (node, context) => context.transformExpression(node.expression),
|
|
17
18
|
[ts.SyntaxKind.AsExpression]: transformAssertionExpression,
|
|
18
19
|
[ts.SyntaxKind.TypeAssertionExpression]: transformAssertionExpression,
|
|
19
20
|
[ts.SyntaxKind.NotEmittedStatement]: () => undefined,
|
|
@@ -22,7 +22,7 @@ export interface EmitFile extends BaseFile {
|
|
|
22
22
|
outputPath: string;
|
|
23
23
|
}
|
|
24
24
|
export declare const getConfigDirectory: (options: ts.CompilerOptions) => string;
|
|
25
|
-
export declare function resolvePlugin(kind: string, optionName: string, basedir: string, query:
|
|
25
|
+
export declare function resolvePlugin(kind: string, optionName: string, basedir: string, query: unknown, importName?: string): {
|
|
26
26
|
error?: ts.Diagnostic;
|
|
27
27
|
result?: unknown;
|
|
28
28
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function castArray<T>(value: T | readonly T[]): readonly T[];
|
|
|
4
4
|
export declare const intersperse: <T>(values: readonly T[], separator: T) => T[];
|
|
5
5
|
export declare const union: <T>(...values: Iterable<T>[]) => T[];
|
|
6
6
|
export declare const intersection: <T>(first: readonly T[], ...rest: (readonly T[])[]) => T[];
|
|
7
|
-
|
|
7
|
+
type DiagnosticFactory = (...args: any) => Partial<ts.Diagnostic> & Pick<ts.Diagnostic, "messageText">;
|
|
8
8
|
export declare const createDiagnosticFactoryWithCode: <T extends DiagnosticFactory>(code: number, create: T) => ((...args: Parameters<T>) => ts.Diagnostic) & {
|
|
9
9
|
code: number;
|
|
10
10
|
};
|
|
@@ -14,7 +14,7 @@ export declare const createSerialDiagnosticFactory: <T extends DiagnosticFactory
|
|
|
14
14
|
export declare const normalizeSlashes: (filePath: string) => string;
|
|
15
15
|
export declare const trimExtension: (filePath: string) => string;
|
|
16
16
|
export declare function formatPathToLuaPath(filePath: string): string;
|
|
17
|
-
|
|
17
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
18
18
|
export declare function getOrUpdate<K, V>(map: Map<K, V> | (K extends object ? WeakMap<K, V> : never), key: K, getDefaultValue: () => NoInfer<V>): V;
|
|
19
19
|
export declare function isNonNull<T>(value: T | null | undefined): value is T;
|
|
20
20
|
export declare function cast<TOriginal, TCast extends TOriginal>(item: TOriginal, cast: (item: TOriginal) => item is TCast): TCast;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"node": ">=16.10.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"typescript": "~4.
|
|
45
|
+
"typescript": "~4.9.3"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@typescript-to-lua/language-extensions": "1.0.0",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
"prettier": "^2.3.2",
|
|
71
71
|
"ts-jest": "^28.0.8",
|
|
72
72
|
"ts-node": "^10.9.1",
|
|
73
|
-
"typescript": "~4.
|
|
73
|
+
"typescript": "~4.9.3"
|
|
74
74
|
}
|
|
75
75
|
}
|