typescript-to-lua 1.14.0 → 1.15.0
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/LuaAST.d.ts +31 -25
- package/dist/LuaAST.js +37 -26
- package/dist/LuaPrinter.d.ts +1 -0
- package/dist/LuaPrinter.js +5 -0
- package/dist/cli/tsconfig.js +36 -1
- package/dist/lualib/5.0/ParseFloat.lua +1 -1
- package/dist/lualib/5.0/ParseInt.lua +2 -5
- package/dist/lualib/5.0/SourceMapTraceBack.lua +1 -1
- package/dist/lualib/5.0/lualib_bundle.lua +4 -7
- package/dist/lualib/universal/ParseFloat.lua +1 -1
- package/dist/lualib/universal/ParseInt.lua +2 -5
- package/dist/lualib/universal/SourceMapTraceBack.lua +1 -1
- package/dist/lualib/universal/lualib_bundle.lua +4 -7
- package/dist/transformation/utils/export.js +1 -1
- package/dist/transformation/visitors/access.js +7 -7
- package/dist/transformation/visitors/function.js +13 -5
- package/dist/transformation/visitors/namespace.d.ts +1 -0
- package/dist/transformation/visitors/namespace.js +10 -2
- package/package.json +3 -3
package/dist/LuaAST.d.ts
CHANGED
|
@@ -32,31 +32,32 @@ export declare enum SyntaxKind {
|
|
|
32
32
|
MethodCallExpression = 28,
|
|
33
33
|
Identifier = 29,
|
|
34
34
|
TableIndexExpression = 30,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
ParenthesizedExpression = 31,
|
|
36
|
+
AdditionOperator = 32,
|
|
37
|
+
SubtractionOperator = 33,
|
|
38
|
+
MultiplicationOperator = 34,
|
|
39
|
+
DivisionOperator = 35,
|
|
40
|
+
FloorDivisionOperator = 36,
|
|
41
|
+
ModuloOperator = 37,
|
|
42
|
+
PowerOperator = 38,
|
|
43
|
+
NegationOperator = 39,
|
|
44
|
+
ConcatOperator = 40,
|
|
45
|
+
LengthOperator = 41,
|
|
46
|
+
EqualityOperator = 42,
|
|
47
|
+
InequalityOperator = 43,
|
|
48
|
+
LessThanOperator = 44,
|
|
49
|
+
LessEqualOperator = 45,
|
|
50
|
+
GreaterThanOperator = 46,
|
|
51
|
+
GreaterEqualOperator = 47,
|
|
52
|
+
AndOperator = 48,
|
|
53
|
+
OrOperator = 49,
|
|
54
|
+
NotOperator = 50,
|
|
55
|
+
BitwiseAndOperator = 51,
|
|
56
|
+
BitwiseOrOperator = 52,
|
|
57
|
+
BitwiseExclusiveOrOperator = 53,
|
|
58
|
+
BitwiseRightShiftOperator = 54,
|
|
59
|
+
BitwiseLeftShiftOperator = 55,
|
|
60
|
+
BitwiseNotOperator = 56
|
|
60
61
|
}
|
|
61
62
|
export type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;
|
|
62
63
|
export type UnaryOperator = SyntaxKind.NegationOperator | SyntaxKind.LengthOperator | SyntaxKind.NotOperator | UnaryBitwiseOperator;
|
|
@@ -314,3 +315,8 @@ export type InlineFunctionExpression = FunctionExpression & {
|
|
|
314
315
|
};
|
|
315
316
|
};
|
|
316
317
|
export declare function isInlineFunctionExpression(expression: FunctionExpression): expression is InlineFunctionExpression;
|
|
318
|
+
export type ParenthesizedExpression = Expression & {
|
|
319
|
+
expression: Expression;
|
|
320
|
+
};
|
|
321
|
+
export declare function isParenthesizedExpression(node: Node): node is ParenthesizedExpression;
|
|
322
|
+
export declare function createParenthesizedExpression(expression: Expression, tsOriginal?: ts.Node): ParenthesizedExpression;
|
package/dist/LuaAST.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// https://www.lua.org/manual/5.3/manual.html#9 and the TS AST implementation
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.isStringLiteral = exports.createNumericLiteral = exports.isNumericLiteral = exports.createArgLiteral = exports.isArgLiteral = exports.createDotsLiteral = exports.isDotsLiteral = exports.createBooleanLiteral = exports.isBooleanLiteral = exports.createNilLiteral = exports.isNilLiteral = exports.createExpressionStatement = exports.isExpressionStatement = exports.createBreakStatement = exports.isBreakStatement = exports.createReturnStatement = exports.isReturnStatement = exports.createLabelStatement = exports.isLabelStatement = exports.createGotoStatement = exports.isGotoStatement = exports.createForInStatement = exports.isForInStatement = exports.createForStatement = exports.isForStatement = exports.createRepeatStatement = exports.isRepeatStatement = exports.createWhileStatement = exports.isWhileStatement = exports.isIterationStatement = exports.createIfStatement = exports.isIfStatement = exports.createAssignmentStatement = exports.isAssignmentStatement = exports.createVariableDeclarationStatement = exports.isVariableDeclarationStatement = exports.createDoStatement = exports.isDoStatement = exports.createBlock = exports.isBlock = exports.createFile = exports.isFile = exports.setNodeFlags = exports.getOriginalPos = exports.setNodeOriginal = exports.setNodePosition = exports.cloneNode = exports.createNode = exports.NodeFlags = exports.SyntaxKind = void 0;
|
|
6
|
-
exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = exports.isFunctionExpression = exports.isLiteral = exports.createStringLiteral = void 0;
|
|
6
|
+
exports.createParenthesizedExpression = exports.isParenthesizedExpression = exports.isInlineFunctionExpression = exports.isFunctionDefinition = exports.isAssignmentLeftHandSideExpression = exports.createTableIndexExpression = exports.isTableIndexExpression = exports.createAnonymousIdentifier = exports.cloneIdentifier = exports.createIdentifier = exports.isIdentifier = exports.createMethodCallExpression = exports.isMethodCallExpression = exports.createCallExpression = exports.isCallExpression = exports.createBinaryExpression = exports.isBinaryExpression = exports.createUnaryExpression = exports.isUnaryExpression = exports.createTableExpression = exports.isTableExpression = exports.createTableFieldExpression = exports.isTableFieldExpression = exports.createFunctionExpression = exports.isFunctionExpression = exports.isLiteral = exports.createStringLiteral = void 0;
|
|
7
7
|
// We can elide a lot of nodes especially tokens and keywords
|
|
8
8
|
// because we don't create the AST from text
|
|
9
9
|
const ts = require("typescript");
|
|
@@ -43,40 +43,41 @@ var SyntaxKind;
|
|
|
43
43
|
SyntaxKind[SyntaxKind["MethodCallExpression"] = 28] = "MethodCallExpression";
|
|
44
44
|
SyntaxKind[SyntaxKind["Identifier"] = 29] = "Identifier";
|
|
45
45
|
SyntaxKind[SyntaxKind["TableIndexExpression"] = 30] = "TableIndexExpression";
|
|
46
|
+
SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 31] = "ParenthesizedExpression";
|
|
46
47
|
// Operators
|
|
47
48
|
// Arithmetic
|
|
48
|
-
SyntaxKind[SyntaxKind["AdditionOperator"] =
|
|
49
|
-
SyntaxKind[SyntaxKind["SubtractionOperator"] =
|
|
50
|
-
SyntaxKind[SyntaxKind["MultiplicationOperator"] =
|
|
51
|
-
SyntaxKind[SyntaxKind["DivisionOperator"] =
|
|
52
|
-
SyntaxKind[SyntaxKind["FloorDivisionOperator"] =
|
|
53
|
-
SyntaxKind[SyntaxKind["ModuloOperator"] =
|
|
54
|
-
SyntaxKind[SyntaxKind["PowerOperator"] =
|
|
55
|
-
SyntaxKind[SyntaxKind["NegationOperator"] =
|
|
49
|
+
SyntaxKind[SyntaxKind["AdditionOperator"] = 32] = "AdditionOperator";
|
|
50
|
+
SyntaxKind[SyntaxKind["SubtractionOperator"] = 33] = "SubtractionOperator";
|
|
51
|
+
SyntaxKind[SyntaxKind["MultiplicationOperator"] = 34] = "MultiplicationOperator";
|
|
52
|
+
SyntaxKind[SyntaxKind["DivisionOperator"] = 35] = "DivisionOperator";
|
|
53
|
+
SyntaxKind[SyntaxKind["FloorDivisionOperator"] = 36] = "FloorDivisionOperator";
|
|
54
|
+
SyntaxKind[SyntaxKind["ModuloOperator"] = 37] = "ModuloOperator";
|
|
55
|
+
SyntaxKind[SyntaxKind["PowerOperator"] = 38] = "PowerOperator";
|
|
56
|
+
SyntaxKind[SyntaxKind["NegationOperator"] = 39] = "NegationOperator";
|
|
56
57
|
// Concat
|
|
57
|
-
SyntaxKind[SyntaxKind["ConcatOperator"] =
|
|
58
|
+
SyntaxKind[SyntaxKind["ConcatOperator"] = 40] = "ConcatOperator";
|
|
58
59
|
// Length
|
|
59
|
-
SyntaxKind[SyntaxKind["LengthOperator"] =
|
|
60
|
+
SyntaxKind[SyntaxKind["LengthOperator"] = 41] = "LengthOperator";
|
|
60
61
|
// Relational Ops
|
|
61
|
-
SyntaxKind[SyntaxKind["EqualityOperator"] =
|
|
62
|
-
SyntaxKind[SyntaxKind["InequalityOperator"] =
|
|
63
|
-
SyntaxKind[SyntaxKind["LessThanOperator"] =
|
|
64
|
-
SyntaxKind[SyntaxKind["LessEqualOperator"] =
|
|
62
|
+
SyntaxKind[SyntaxKind["EqualityOperator"] = 42] = "EqualityOperator";
|
|
63
|
+
SyntaxKind[SyntaxKind["InequalityOperator"] = 43] = "InequalityOperator";
|
|
64
|
+
SyntaxKind[SyntaxKind["LessThanOperator"] = 44] = "LessThanOperator";
|
|
65
|
+
SyntaxKind[SyntaxKind["LessEqualOperator"] = 45] = "LessEqualOperator";
|
|
65
66
|
// Syntax Sugar `x > y` <=> `not (y <= x)`
|
|
66
67
|
// but we should probably use them to make the output code more readable
|
|
67
|
-
SyntaxKind[SyntaxKind["GreaterThanOperator"] =
|
|
68
|
-
SyntaxKind[SyntaxKind["GreaterEqualOperator"] =
|
|
68
|
+
SyntaxKind[SyntaxKind["GreaterThanOperator"] = 46] = "GreaterThanOperator";
|
|
69
|
+
SyntaxKind[SyntaxKind["GreaterEqualOperator"] = 47] = "GreaterEqualOperator";
|
|
69
70
|
// Logical
|
|
70
|
-
SyntaxKind[SyntaxKind["AndOperator"] =
|
|
71
|
-
SyntaxKind[SyntaxKind["OrOperator"] =
|
|
72
|
-
SyntaxKind[SyntaxKind["NotOperator"] =
|
|
71
|
+
SyntaxKind[SyntaxKind["AndOperator"] = 48] = "AndOperator";
|
|
72
|
+
SyntaxKind[SyntaxKind["OrOperator"] = 49] = "OrOperator";
|
|
73
|
+
SyntaxKind[SyntaxKind["NotOperator"] = 50] = "NotOperator";
|
|
73
74
|
// Bitwise
|
|
74
|
-
SyntaxKind[SyntaxKind["BitwiseAndOperator"] =
|
|
75
|
-
SyntaxKind[SyntaxKind["BitwiseOrOperator"] =
|
|
76
|
-
SyntaxKind[SyntaxKind["BitwiseExclusiveOrOperator"] =
|
|
77
|
-
SyntaxKind[SyntaxKind["BitwiseRightShiftOperator"] =
|
|
78
|
-
SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] =
|
|
79
|
-
SyntaxKind[SyntaxKind["BitwiseNotOperator"] =
|
|
75
|
+
SyntaxKind[SyntaxKind["BitwiseAndOperator"] = 51] = "BitwiseAndOperator";
|
|
76
|
+
SyntaxKind[SyntaxKind["BitwiseOrOperator"] = 52] = "BitwiseOrOperator";
|
|
77
|
+
SyntaxKind[SyntaxKind["BitwiseExclusiveOrOperator"] = 53] = "BitwiseExclusiveOrOperator";
|
|
78
|
+
SyntaxKind[SyntaxKind["BitwiseRightShiftOperator"] = 54] = "BitwiseRightShiftOperator";
|
|
79
|
+
SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] = 55] = "BitwiseLeftShiftOperator";
|
|
80
|
+
SyntaxKind[SyntaxKind["BitwiseNotOperator"] = 56] = "BitwiseNotOperator";
|
|
80
81
|
})(SyntaxKind = exports.SyntaxKind || (exports.SyntaxKind = {}));
|
|
81
82
|
var NodeFlags;
|
|
82
83
|
(function (NodeFlags) {
|
|
@@ -500,4 +501,14 @@ function isInlineFunctionExpression(expression) {
|
|
|
500
501
|
(expression.flags & NodeFlags.Inline) !== 0);
|
|
501
502
|
}
|
|
502
503
|
exports.isInlineFunctionExpression = isInlineFunctionExpression;
|
|
504
|
+
function isParenthesizedExpression(node) {
|
|
505
|
+
return node.kind === SyntaxKind.ParenthesizedExpression;
|
|
506
|
+
}
|
|
507
|
+
exports.isParenthesizedExpression = isParenthesizedExpression;
|
|
508
|
+
function createParenthesizedExpression(expression, tsOriginal) {
|
|
509
|
+
const parenthesizedExpression = createNode(SyntaxKind.ParenthesizedExpression, tsOriginal);
|
|
510
|
+
parenthesizedExpression.expression = expression;
|
|
511
|
+
return parenthesizedExpression;
|
|
512
|
+
}
|
|
513
|
+
exports.createParenthesizedExpression = createParenthesizedExpression;
|
|
503
514
|
//# sourceMappingURL=LuaAST.js.map
|
package/dist/LuaPrinter.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare class LuaPrinter {
|
|
|
75
75
|
printMethodCallExpression(expression: lua.MethodCallExpression): SourceNode;
|
|
76
76
|
printIdentifier(expression: lua.Identifier): SourceNode;
|
|
77
77
|
printTableIndexExpression(expression: lua.TableIndexExpression): SourceNode;
|
|
78
|
+
printParenthesizedExpression(expression: lua.ParenthesizedExpression): SourceNode;
|
|
78
79
|
printOperator(kind: lua.Operator): SourceNode;
|
|
79
80
|
protected joinChunksWithComma(chunks: SourceChunk[]): SourceChunk[];
|
|
80
81
|
/**
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -430,6 +430,8 @@ class LuaPrinter {
|
|
|
430
430
|
return this.printIdentifier(expression);
|
|
431
431
|
case lua.SyntaxKind.TableIndexExpression:
|
|
432
432
|
return this.printTableIndexExpression(expression);
|
|
433
|
+
case lua.SyntaxKind.ParenthesizedExpression:
|
|
434
|
+
return this.printParenthesizedExpression(expression);
|
|
433
435
|
default:
|
|
434
436
|
throw new Error(`Tried to print unknown statement kind: ${lua.SyntaxKind[expression.kind]}`);
|
|
435
437
|
}
|
|
@@ -582,6 +584,9 @@ class LuaPrinter {
|
|
|
582
584
|
}
|
|
583
585
|
return this.createSourceNode(expression, chunks);
|
|
584
586
|
}
|
|
587
|
+
printParenthesizedExpression(expression) {
|
|
588
|
+
return this.createSourceNode(expression, ["(", this.printExpression(expression.expression), ")"]);
|
|
589
|
+
}
|
|
585
590
|
printOperator(kind) {
|
|
586
591
|
return new source_map_1.SourceNode(null, null, this.relativeSourcePath, LuaPrinter.operatorMap[kind]);
|
|
587
592
|
}
|
package/dist/cli/tsconfig.js
CHANGED
|
@@ -38,10 +38,45 @@ function locateConfigFile(commandLine) {
|
|
|
38
38
|
}
|
|
39
39
|
exports.locateConfigFile = locateConfigFile;
|
|
40
40
|
function parseConfigFileWithSystem(configFileName, commandLineOptions, system = ts.sys) {
|
|
41
|
-
|
|
41
|
+
var _a;
|
|
42
|
+
const configRootDir = path.dirname(configFileName);
|
|
43
|
+
const parsedConfigFile = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(configFileName, system.readFile), system, configRootDir, commandLineOptions, configFileName);
|
|
44
|
+
const cycleCache = new Set();
|
|
45
|
+
const extendedTstlOptions = getExtendedTstlOptions(configFileName, configRootDir, cycleCache, system);
|
|
46
|
+
parsedConfigFile.raw.tstl = Object.assign(extendedTstlOptions, (_a = parsedConfigFile.raw.tstl) !== null && _a !== void 0 ? _a : {});
|
|
42
47
|
return (0, parse_1.updateParsedConfigFile)(parsedConfigFile);
|
|
43
48
|
}
|
|
44
49
|
exports.parseConfigFileWithSystem = parseConfigFileWithSystem;
|
|
50
|
+
function getExtendedTstlOptions(configFilePath, configRootDir, cycleCache, system) {
|
|
51
|
+
const absolutePath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(configRootDir, configFilePath);
|
|
52
|
+
const newConfigRoot = path.dirname(absolutePath);
|
|
53
|
+
if (cycleCache.has(absolutePath)) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
cycleCache.add(absolutePath);
|
|
57
|
+
const fileContent = system.readFile(absolutePath);
|
|
58
|
+
const options = {};
|
|
59
|
+
if (fileContent) {
|
|
60
|
+
const { config: parsedConfig } = ts.parseConfigFileTextToJson(configFilePath, fileContent);
|
|
61
|
+
if (!parsedConfig) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
if (parsedConfig.extends) {
|
|
65
|
+
if (Array.isArray(parsedConfig.extends)) {
|
|
66
|
+
for (const extendedConfigFile of parsedConfig.extends) {
|
|
67
|
+
Object.assign(options, getExtendedTstlOptions(extendedConfigFile, newConfigRoot, cycleCache, system));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
Object.assign(options, getExtendedTstlOptions(parsedConfig.extends, newConfigRoot, cycleCache, system));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (parsedConfig.tstl) {
|
|
75
|
+
Object.assign(options, parsedConfig.tstl);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return options;
|
|
79
|
+
}
|
|
45
80
|
function createConfigFileUpdater(optionsToExtend) {
|
|
46
81
|
const configFileMap = new WeakMap();
|
|
47
82
|
return options => {
|
|
@@ -3,6 +3,6 @@ local function __TS__ParseFloat(numberString)
|
|
|
3
3
|
if infinityMatch ~= nil then
|
|
4
4
|
return __TS__StringAccess(infinityMatch, 0) == "-" and -(1 / 0) or 1 / 0
|
|
5
5
|
end
|
|
6
|
-
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
6
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
7
7
|
return number or 0 / 0
|
|
8
8
|
end
|
|
@@ -7,7 +7,7 @@ do
|
|
|
7
7
|
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
8
8
|
if hexMatch ~= nil then
|
|
9
9
|
base = 16
|
|
10
|
-
numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(
|
|
10
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(
|
|
11
11
|
numberString,
|
|
12
12
|
string.len(hexMatch)
|
|
13
13
|
) or __TS__StringSubstring(
|
|
@@ -21,10 +21,7 @@ do
|
|
|
21
21
|
end
|
|
22
22
|
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
23
23
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
24
|
-
local number = tonumber(
|
|
25
|
-
__TS__Match(numberString, pattern),
|
|
26
|
-
base
|
|
27
|
-
)
|
|
24
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
28
25
|
if number == nil then
|
|
29
26
|
return 0 / 0
|
|
30
27
|
end
|
|
@@ -35,7 +35,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
35
35
|
local function stringReplacer(____, file, line)
|
|
36
36
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
37
37
|
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
38
|
-
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
38
|
+
local chunkName = (__TS__Match(file, "%[string \"([^\"]+)\"%]"))
|
|
39
39
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
40
40
|
local data = fileSourceMap[line]
|
|
41
41
|
if type(data) == "number" then
|
|
@@ -1632,7 +1632,7 @@ local function __TS__ParseFloat(numberString)
|
|
|
1632
1632
|
if infinityMatch ~= nil then
|
|
1633
1633
|
return __TS__StringAccess(infinityMatch, 0) == "-" and -(1 / 0) or 1 / 0
|
|
1634
1634
|
end
|
|
1635
|
-
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1635
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1636
1636
|
return number or 0 / 0
|
|
1637
1637
|
end
|
|
1638
1638
|
|
|
@@ -1663,7 +1663,7 @@ do
|
|
|
1663
1663
|
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1664
1664
|
if hexMatch ~= nil then
|
|
1665
1665
|
base = 16
|
|
1666
|
-
numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(
|
|
1666
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(
|
|
1667
1667
|
numberString,
|
|
1668
1668
|
string.len(hexMatch)
|
|
1669
1669
|
) or __TS__StringSubstring(
|
|
@@ -1677,10 +1677,7 @@ do
|
|
|
1677
1677
|
end
|
|
1678
1678
|
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1679
1679
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1680
|
-
local number = tonumber(
|
|
1681
|
-
__TS__Match(numberString, pattern),
|
|
1682
|
-
base
|
|
1683
|
-
)
|
|
1680
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1684
1681
|
if number == nil then
|
|
1685
1682
|
return 0 / 0
|
|
1686
1683
|
end
|
|
@@ -2133,7 +2130,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2133
2130
|
local function stringReplacer(____, file, line)
|
|
2134
2131
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2135
2132
|
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
2136
|
-
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
2133
|
+
local chunkName = (__TS__Match(file, "%[string \"([^\"]+)\"%]"))
|
|
2137
2134
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
2138
2135
|
local data = fileSourceMap[line]
|
|
2139
2136
|
if type(data) == "number" then
|
|
@@ -3,6 +3,6 @@ local function __TS__ParseFloat(numberString)
|
|
|
3
3
|
if infinityMatch ~= nil then
|
|
4
4
|
return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
|
|
5
5
|
end
|
|
6
|
-
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
6
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
7
7
|
return number or 0 / 0
|
|
8
8
|
end
|
|
@@ -7,7 +7,7 @@ do
|
|
|
7
7
|
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
8
8
|
if hexMatch ~= nil then
|
|
9
9
|
base = 16
|
|
10
|
-
numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
10
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
if base < 2 or base > 36 then
|
|
@@ -15,10 +15,7 @@ do
|
|
|
15
15
|
end
|
|
16
16
|
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
17
17
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
18
|
-
local number = tonumber(
|
|
19
|
-
__TS__Match(numberString, pattern),
|
|
20
|
-
base
|
|
21
|
-
)
|
|
18
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
22
19
|
if number == nil then
|
|
23
20
|
return 0 / 0
|
|
24
21
|
end
|
|
@@ -35,7 +35,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
35
35
|
local function stringReplacer(____, file, line)
|
|
36
36
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
37
37
|
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
38
|
-
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
38
|
+
local chunkName = (__TS__Match(file, "%[string \"([^\"]+)\"%]"))
|
|
39
39
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
40
40
|
local data = fileSourceMap[line]
|
|
41
41
|
if type(data) == "number" then
|
|
@@ -1574,7 +1574,7 @@ local function __TS__ParseFloat(numberString)
|
|
|
1574
1574
|
if infinityMatch ~= nil then
|
|
1575
1575
|
return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
|
|
1576
1576
|
end
|
|
1577
|
-
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1577
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1578
1578
|
return number or 0 / 0
|
|
1579
1579
|
end
|
|
1580
1580
|
|
|
@@ -1605,7 +1605,7 @@ do
|
|
|
1605
1605
|
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1606
1606
|
if hexMatch ~= nil then
|
|
1607
1607
|
base = 16
|
|
1608
|
-
numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
1608
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
1609
1609
|
end
|
|
1610
1610
|
end
|
|
1611
1611
|
if base < 2 or base > 36 then
|
|
@@ -1613,10 +1613,7 @@ do
|
|
|
1613
1613
|
end
|
|
1614
1614
|
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1615
1615
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1616
|
-
local number = tonumber(
|
|
1617
|
-
__TS__Match(numberString, pattern),
|
|
1618
|
-
base
|
|
1619
|
-
)
|
|
1616
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1620
1617
|
if number == nil then
|
|
1621
1618
|
return 0 / 0
|
|
1622
1619
|
end
|
|
@@ -2070,7 +2067,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2070
2067
|
local function stringReplacer(____, file, line)
|
|
2071
2068
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2072
2069
|
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
2073
|
-
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
2070
|
+
local chunkName = (__TS__Match(file, "%[string \"([^\"]+)\"%]"))
|
|
2074
2071
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
2075
2072
|
local data = fileSourceMap[line]
|
|
2076
2073
|
if type(data) == "number" then
|
|
@@ -103,7 +103,7 @@ function createExportedIdentifier(context, identifier, exportScope) {
|
|
|
103
103
|
return identifier;
|
|
104
104
|
}
|
|
105
105
|
const exportTable = exportScope && ts.isModuleDeclaration(exportScope)
|
|
106
|
-
? (0, namespace_1.
|
|
106
|
+
? (0, namespace_1.createModuleLocalName)(context, exportScope)
|
|
107
107
|
: (0, lua_ast_1.createExportsIdentifier)();
|
|
108
108
|
return lua.createTableIndexExpression(exportTable, lua.createStringLiteral(identifier.text));
|
|
109
109
|
}
|
|
@@ -53,14 +53,14 @@ function transformElementAccessExpressionWithCapture(context, node, thisValueCap
|
|
|
53
53
|
if (!(0, typescript_1.isNumberType)(context, accessType)) {
|
|
54
54
|
context.diagnostics.push((0, diagnostics_1.invalidMultiReturnAccess)(node));
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const selectIdentifier = lua.createIdentifier("select");
|
|
62
|
-
return { expression: lua.createCallExpression(selectIdentifier, [updatedAccessExpression, table]) };
|
|
56
|
+
const canOmitSelect = ts.isNumericLiteral(node.argumentExpression) && node.argumentExpression.text === "0";
|
|
57
|
+
if (canOmitSelect) {
|
|
58
|
+
// wrapping in parenthesis ensures only the first return value is used
|
|
59
|
+
// https://www.lua.org/manual/5.1/manual.html#2.5
|
|
60
|
+
return { expression: lua.createParenthesizedExpression(table) };
|
|
63
61
|
}
|
|
62
|
+
const selectIdentifier = lua.createIdentifier("select");
|
|
63
|
+
return { expression: lua.createCallExpression(selectIdentifier, [updatedAccessExpression, table]) };
|
|
64
64
|
}
|
|
65
65
|
if (thisValueCapture) {
|
|
66
66
|
const thisValue = (0, optional_chaining_1.captureThisValue)(context, table, thisValueCapture, node.expression);
|
|
@@ -18,10 +18,14 @@ const identifier_1 = require("./identifier");
|
|
|
18
18
|
const return_1 = require("./return");
|
|
19
19
|
const variable_declaration_1 = require("./variable-declaration");
|
|
20
20
|
function transformParameterDefaultValueDeclaration(context, parameterName, value, tsOriginal) {
|
|
21
|
-
const parameterValue =
|
|
22
|
-
|
|
21
|
+
const { precedingStatements: statements, result: parameterValue } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(value));
|
|
22
|
+
if (!lua.isNilLiteral(parameterValue)) {
|
|
23
|
+
statements.push(lua.createAssignmentStatement(parameterName, parameterValue));
|
|
24
|
+
}
|
|
25
|
+
if (statements.length === 0)
|
|
26
|
+
return undefined;
|
|
23
27
|
const nilCondition = lua.createBinaryExpression(parameterName, lua.createNilLiteral(), lua.SyntaxKind.EqualityOperator);
|
|
24
|
-
const ifBlock = lua.createBlock(
|
|
28
|
+
const ifBlock = lua.createBlock(statements, tsOriginal);
|
|
25
29
|
return lua.createIfStatement(nilCondition, ifBlock, undefined, tsOriginal);
|
|
26
30
|
}
|
|
27
31
|
function isRestParameterReferenced(identifier, scope) {
|
|
@@ -86,7 +90,9 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
86
90
|
const identifier = lua.createIdentifier(`____bindingPattern${bindPatternIndex++}`);
|
|
87
91
|
if (declaration.initializer !== undefined) {
|
|
88
92
|
// Default binding parameter
|
|
89
|
-
|
|
93
|
+
const initializer = transformParameterDefaultValueDeclaration(context, identifier, declaration.initializer);
|
|
94
|
+
if (initializer)
|
|
95
|
+
headerStatements.push(initializer);
|
|
90
96
|
}
|
|
91
97
|
// Binding pattern
|
|
92
98
|
const name = declaration.name;
|
|
@@ -95,7 +101,9 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
95
101
|
}
|
|
96
102
|
else if (declaration.initializer !== undefined) {
|
|
97
103
|
// Default parameter
|
|
98
|
-
|
|
104
|
+
const initializer = transformParameterDefaultValueDeclaration(context, (0, identifier_1.transformIdentifier)(context, declaration.name), declaration.initializer);
|
|
105
|
+
if (initializer)
|
|
106
|
+
headerStatements.push(initializer);
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
// Push spread operator here
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
|
+
export declare function createModuleLocalName(context: TransformationContext, module: ts.ModuleDeclaration): lua.Expression;
|
|
4
5
|
export declare function createModuleLocalNameIdentifier(context: TransformationContext, declaration: ts.ModuleDeclaration): lua.Identifier;
|
|
5
6
|
export declare const transformModuleDeclaration: FunctionVisitor<ts.ModuleDeclaration>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformModuleDeclaration = exports.createModuleLocalNameIdentifier = void 0;
|
|
3
|
+
exports.transformModuleDeclaration = exports.createModuleLocalNameIdentifier = exports.createModuleLocalName = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const export_1 = require("../utils/export");
|
|
@@ -9,12 +9,20 @@ const safe_names_1 = require("../utils/safe-names");
|
|
|
9
9
|
const scope_1 = require("../utils/scope");
|
|
10
10
|
const symbols_1 = require("../utils/symbols");
|
|
11
11
|
const identifier_1 = require("./identifier");
|
|
12
|
+
function createModuleLocalName(context, module) {
|
|
13
|
+
if (!ts.isSourceFile(module.parent) && ts.isModuleDeclaration(module.parent)) {
|
|
14
|
+
const parentDeclaration = createModuleLocalName(context, module.parent);
|
|
15
|
+
const name = createModuleLocalNameIdentifier(context, module);
|
|
16
|
+
return lua.createTableIndexExpression(parentDeclaration, lua.createStringLiteral(name.text), module.name);
|
|
17
|
+
}
|
|
18
|
+
return createModuleLocalNameIdentifier(context, module);
|
|
19
|
+
}
|
|
20
|
+
exports.createModuleLocalName = createModuleLocalName;
|
|
12
21
|
function createModuleLocalNameIdentifier(context, declaration) {
|
|
13
22
|
const moduleSymbol = context.checker.getSymbolAtLocation(declaration.name);
|
|
14
23
|
if (moduleSymbol !== undefined && (0, safe_names_1.isUnsafeName)(moduleSymbol.name, context.options)) {
|
|
15
24
|
return lua.createIdentifier((0, safe_names_1.createSafeName)(declaration.name.text), declaration.name, moduleSymbol && (0, symbols_1.getSymbolIdOfSymbol)(context, moduleSymbol), declaration.name.text);
|
|
16
25
|
}
|
|
17
|
-
// TODO: Should synthetic name nodes be escaped as well?
|
|
18
26
|
return (0, identifier_1.transformIdentifier)(context, declaration.name);
|
|
19
27
|
}
|
|
20
28
|
exports.createModuleLocalNameIdentifier = createModuleLocalNameIdentifier;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
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/",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"eslint-plugin-jest": "^26.9.0",
|
|
64
64
|
"fs-extra": "^8.1.0",
|
|
65
65
|
"javascript-stringify": "^2.0.1",
|
|
66
|
-
"jest": "^
|
|
66
|
+
"jest": "^29.5.0",
|
|
67
67
|
"jest-circus": "^29.5.0",
|
|
68
68
|
"lua-types": "^2.13.0",
|
|
69
69
|
"lua-wasm-bindings": "^0.3.1",
|
|
70
70
|
"prettier": "^2.8.4",
|
|
71
|
-
"ts-jest": "^
|
|
71
|
+
"ts-jest": "^29.1.0",
|
|
72
72
|
"ts-node": "^10.9.1",
|
|
73
73
|
"typescript": "^5.0.2"
|
|
74
74
|
}
|