typescript-to-lua 1.0.0 → 1.2.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/CHANGELOG.md +34 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.d.ts +1 -0
- package/dist/LuaAST.js +14 -6
- package/dist/LuaLib.d.ts +4 -3
- package/dist/LuaLib.js +5 -4
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +79 -27
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +7 -1
- package/dist/lualib/ArrayReduceRight.lua +7 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArraySplice.lua +5 -5
- package/dist/lualib/Await.lua +39 -19
- package/dist/lualib/CloneDescriptor.lua +8 -8
- package/dist/lualib/Decorate.lua +1 -1
- package/dist/lualib/DelegatedYield.lua +1 -3
- package/dist/lualib/Delete.lua +6 -6
- package/dist/lualib/Error.lua +47 -44
- package/dist/lualib/Generator.lua +1 -5
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Map.lua +130 -134
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberToString.lua +3 -5
- package/dist/lualib/ObjectDefineProperty.lua +40 -8
- package/dist/lualib/ParseFloat.lua +9 -5
- package/dist/lualib/ParseInt.lua +15 -3
- package/dist/lualib/Promise.lua +36 -26
- package/dist/lualib/Set.lua +119 -123
- package/dist/lualib/SetDescriptor.lua +7 -1
- package/dist/lualib/SourceMapTraceBack.lua +19 -9
- package/dist/lualib/SparseArrayNew.lua +5 -0
- package/dist/lualib/SparseArrayPush.lua +9 -0
- package/dist/lualib/SparseArraySpread.lua +4 -0
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +2 -2
- package/dist/lualib/StringPadEnd.lua +2 -2
- package/dist/lualib/StringPadStart.lua +2 -2
- package/dist/lualib/StringReplace.lua +12 -11
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSlice.lua +2 -2
- package/dist/lualib/StringSplit.lua +3 -3
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +2 -2
- package/dist/lualib/Symbol.lua +3 -5
- package/dist/lualib/WeakMap.lua +40 -42
- package/dist/lualib/WeakSet.lua +36 -38
- package/dist/lualib/lualib_bundle.lua +705 -586
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -10
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.d.ts +1 -1
- package/dist/transformation/builtins/index.js +69 -36
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.d.ts +2 -1
- package/dist/transformation/builtins/object.js +12 -13
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -31
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.d.ts +12 -0
- package/dist/transformation/context/context.js +105 -6
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -3
- package/dist/transformation/utils/annotations.js +0 -2
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +6 -0
- package/dist/transformation/utils/diagnostics.js +7 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/lua-ast.d.ts +0 -1
- package/dist/transformation/utils/lua-ast.js +25 -35
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/preceding-statements.d.ts +3 -0
- package/dist/transformation/utils/preceding-statements.js +11 -0
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +7 -0
- package/dist/transformation/utils/scope.js +77 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +16 -1
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.d.ts +3 -0
- package/dist/transformation/visitors/access.js +74 -47
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
- package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
- package/dist/transformation/visitors/binary-expression/compound.js +69 -71
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
- package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
- package/dist/transformation/visitors/binary-expression/index.js +84 -40
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.d.ts +3 -2
- package/dist/transformation/visitors/call.js +130 -143
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +43 -39
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +14 -16
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +34 -20
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -30
- package/dist/transformation/visitors/expression-list.d.ts +7 -0
- package/dist/transformation/visitors/expression-list.js +120 -0
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +30 -32
- package/dist/transformation/visitors/identifier.js +26 -22
- package/dist/transformation/visitors/index.js +2 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -3
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +87 -57
- package/dist/transformation/visitors/loops/do-while.js +35 -9
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +28 -8
- package/dist/transformation/visitors/loops/utils.d.ts +1 -0
- package/dist/transformation/visitors/loops/utils.js +21 -10
- package/dist/transformation/visitors/modules/export.js +14 -15
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
- package/dist/transformation/visitors/optional-chaining.js +172 -0
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +12 -9
- package/dist/transformation/visitors/spread.js +11 -11
- package/dist/transformation/visitors/switch.js +152 -30
- package/dist/transformation/visitors/template.js +10 -7
- package/dist/transformation/visitors/typeof.js +4 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +46 -32
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +20 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +26 -14
- package/dist/transpilation/transformers.js +45 -25
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +5 -3
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/lualib/OptionalChainAccess.lua +0 -6
- package/dist/lualib/OptionalFunctionCall.lua +0 -6
- package/dist/lualib/OptionalMethodCall.lua +0 -11
- package/dist/transformation/utils/transform.d.ts +0 -8
- package/dist/transformation/utils/transform.js +0 -14
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformOrderedExpressions = exports.transformExpressionList = exports.moveToPrecedingTemp = exports.shouldMoveToTemp = void 0;
|
|
4
|
+
const assert = require("assert");
|
|
5
|
+
const ts = require("typescript");
|
|
6
|
+
const lua = require("../../LuaAST");
|
|
7
|
+
const context_1 = require("../context");
|
|
8
|
+
const lualib_1 = require("../utils/lualib");
|
|
9
|
+
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
10
|
+
const typescript_1 = require("../utils/typescript");
|
|
11
|
+
const optional_chaining_1 = require("./optional-chaining");
|
|
12
|
+
function shouldMoveToTemp(context, expression, tsOriginal) {
|
|
13
|
+
return (!lua.isLiteral(expression) &&
|
|
14
|
+
!(lua.isIdentifier(expression) && expression.symbolId === context_1.tempSymbolId) && // Treat generated temps as consts
|
|
15
|
+
!(tsOriginal && ((0, typescript_1.isConstIdentifier)(context, tsOriginal) || (0, optional_chaining_1.isOptionalContinuation)(tsOriginal))));
|
|
16
|
+
}
|
|
17
|
+
exports.shouldMoveToTemp = shouldMoveToTemp;
|
|
18
|
+
// Cache an expression in a preceding statement and return the temp identifier
|
|
19
|
+
function moveToPrecedingTemp(context, expression, tsOriginal) {
|
|
20
|
+
if (!shouldMoveToTemp(context, expression, tsOriginal)) {
|
|
21
|
+
return expression;
|
|
22
|
+
}
|
|
23
|
+
const tempIdentifier = context.createTempNameForLuaExpression(expression);
|
|
24
|
+
const tempDeclaration = lua.createVariableDeclarationStatement(tempIdentifier, expression, tsOriginal);
|
|
25
|
+
context.addPrecedingStatements(tempDeclaration);
|
|
26
|
+
return lua.cloneIdentifier(tempIdentifier, tsOriginal);
|
|
27
|
+
}
|
|
28
|
+
exports.moveToPrecedingTemp = moveToPrecedingTemp;
|
|
29
|
+
function transformExpressions(context, expressions) {
|
|
30
|
+
const precedingStatements = [];
|
|
31
|
+
const transformedExpressions = [];
|
|
32
|
+
let lastPrecedingStatementsIndex = -1;
|
|
33
|
+
for (let i = 0; i < expressions.length; ++i) {
|
|
34
|
+
const [expressionPrecedingStatements, expression] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expressions[i]));
|
|
35
|
+
transformedExpressions.push(expression);
|
|
36
|
+
if (expressionPrecedingStatements.length > 0) {
|
|
37
|
+
lastPrecedingStatementsIndex = i;
|
|
38
|
+
}
|
|
39
|
+
precedingStatements.push(expressionPrecedingStatements);
|
|
40
|
+
}
|
|
41
|
+
return { transformedExpressions, precedingStatements, lastPrecedingStatementsIndex };
|
|
42
|
+
}
|
|
43
|
+
function transformExpressionsUsingTemps(context, expressions, transformedExpressions, precedingStatements, lastPrecedingStatementsIndex) {
|
|
44
|
+
for (let i = 0; i < transformedExpressions.length; ++i) {
|
|
45
|
+
context.addPrecedingStatements(precedingStatements[i]);
|
|
46
|
+
if (i < lastPrecedingStatementsIndex) {
|
|
47
|
+
transformedExpressions[i] = moveToPrecedingTemp(context, transformedExpressions[i], expressions[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return transformedExpressions;
|
|
51
|
+
}
|
|
52
|
+
function pushToSparseArray(context, arrayIdentifier, expressions) {
|
|
53
|
+
if (!arrayIdentifier) {
|
|
54
|
+
arrayIdentifier = lua.createIdentifier(context.createTempName("array"));
|
|
55
|
+
const libCall = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.SparseArrayNew, undefined, ...expressions);
|
|
56
|
+
const declaration = lua.createVariableDeclarationStatement(arrayIdentifier, libCall);
|
|
57
|
+
context.addPrecedingStatements(declaration);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const libCall = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.SparseArrayPush, undefined, arrayIdentifier, ...expressions);
|
|
61
|
+
context.addPrecedingStatements(lua.createExpressionStatement(libCall));
|
|
62
|
+
}
|
|
63
|
+
return arrayIdentifier;
|
|
64
|
+
}
|
|
65
|
+
function transformExpressionsUsingSparseArray(context, expressions, transformedExpressions, precedingStatements) {
|
|
66
|
+
let arrayIdentifier;
|
|
67
|
+
let expressionBatch = [];
|
|
68
|
+
for (let i = 0; i < expressions.length; ++i) {
|
|
69
|
+
// Expressions with preceding statements should always be at the start of a batch
|
|
70
|
+
if (precedingStatements[i].length > 0 && expressionBatch.length > 0) {
|
|
71
|
+
arrayIdentifier = pushToSparseArray(context, arrayIdentifier, expressionBatch);
|
|
72
|
+
expressionBatch = [];
|
|
73
|
+
}
|
|
74
|
+
context.addPrecedingStatements(precedingStatements[i]);
|
|
75
|
+
expressionBatch.push(transformedExpressions[i]);
|
|
76
|
+
// Spread expressions should always be at the end of a batch
|
|
77
|
+
if (ts.isSpreadElement(expressions[i])) {
|
|
78
|
+
arrayIdentifier = pushToSparseArray(context, arrayIdentifier, expressionBatch);
|
|
79
|
+
expressionBatch = [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (expressionBatch.length > 0) {
|
|
83
|
+
arrayIdentifier = pushToSparseArray(context, arrayIdentifier, expressionBatch);
|
|
84
|
+
}
|
|
85
|
+
assert(arrayIdentifier);
|
|
86
|
+
return [(0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.SparseArraySpread, undefined, arrayIdentifier)];
|
|
87
|
+
}
|
|
88
|
+
function countNeededTemps(context, expressions, transformedExpressions, lastPrecedingStatementsIndex) {
|
|
89
|
+
if (lastPrecedingStatementsIndex < 0) {
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
return transformedExpressions
|
|
93
|
+
.slice(0, lastPrecedingStatementsIndex)
|
|
94
|
+
.filter((e, i) => shouldMoveToTemp(context, e, expressions[i])).length;
|
|
95
|
+
}
|
|
96
|
+
// Transforms a list of expressions while flattening spreads and maintaining execution order
|
|
97
|
+
function transformExpressionList(context, expressions) {
|
|
98
|
+
const { transformedExpressions, precedingStatements, lastPrecedingStatementsIndex } = transformExpressions(context, expressions);
|
|
99
|
+
// If more than this number of temps are required to preserve execution order, we'll fall back to using the
|
|
100
|
+
// sparse array lib functions instead to prevent excessive locals.
|
|
101
|
+
const maxTemps = 2;
|
|
102
|
+
// Use sparse array lib if there are spreads before the last expression
|
|
103
|
+
// or if too many temps are needed to preserve order
|
|
104
|
+
const lastSpread = expressions.findIndex(e => ts.isSpreadElement(e));
|
|
105
|
+
if ((lastSpread >= 0 && lastSpread < expressions.length - 1) ||
|
|
106
|
+
countNeededTemps(context, expressions, transformedExpressions, lastPrecedingStatementsIndex) > maxTemps) {
|
|
107
|
+
return transformExpressionsUsingSparseArray(context, expressions, transformedExpressions, precedingStatements);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return transformExpressionsUsingTemps(context, expressions, transformedExpressions, precedingStatements, lastPrecedingStatementsIndex);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.transformExpressionList = transformExpressionList;
|
|
114
|
+
// Transforms a series of expressions while maintaining execution order
|
|
115
|
+
function transformOrderedExpressions(context, expressions) {
|
|
116
|
+
const { transformedExpressions, precedingStatements, lastPrecedingStatementsIndex } = transformExpressions(context, expressions);
|
|
117
|
+
return transformExpressionsUsingTemps(context, expressions, transformedExpressions, precedingStatements, lastPrecedingStatementsIndex);
|
|
118
|
+
}
|
|
119
|
+
exports.transformOrderedExpressions = transformOrderedExpressions;
|
|
120
|
+
//# sourceMappingURL=expression-list.js.map
|
|
@@ -6,19 +6,23 @@ const lua = require("../../LuaAST");
|
|
|
6
6
|
const binary_expression_1 = require("./binary-expression");
|
|
7
7
|
const table_1 = require("./language-extensions/table");
|
|
8
8
|
const unary_expression_1 = require("./unary-expression");
|
|
9
|
+
const void_1 = require("./void");
|
|
9
10
|
const transformExpressionStatement = (node, context) => {
|
|
10
11
|
const expression = node.expression;
|
|
11
|
-
if (ts.isCallExpression(expression) && table_1.isTableDeleteCall(context, expression)) {
|
|
12
|
-
return table_1.transformTableDeleteExpression(context, expression);
|
|
12
|
+
if (ts.isCallExpression(expression) && (0, table_1.isTableDeleteCall)(context, expression)) {
|
|
13
|
+
return (0, table_1.transformTableDeleteExpression)(context, expression);
|
|
13
14
|
}
|
|
14
|
-
if (ts.isCallExpression(expression) && table_1.isTableSetCall(context, expression)) {
|
|
15
|
-
return table_1.transformTableSetExpression(context, expression);
|
|
15
|
+
if (ts.isCallExpression(expression) && (0, table_1.isTableSetCall)(context, expression)) {
|
|
16
|
+
return (0, table_1.transformTableSetExpression)(context, expression);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
if (ts.isVoidExpression(expression)) {
|
|
19
|
+
return (0, void_1.transformVoidExpressionStatement)(expression, context);
|
|
20
|
+
}
|
|
21
|
+
const unaryExpressionResult = (0, unary_expression_1.transformUnaryExpressionStatement)(context, node);
|
|
18
22
|
if (unaryExpressionResult) {
|
|
19
23
|
return unaryExpressionResult;
|
|
20
24
|
}
|
|
21
|
-
const binaryExpressionResult = binary_expression_1.transformBinaryExpressionStatement(context, node);
|
|
25
|
+
const binaryExpressionResult = (0, binary_expression_1.transformBinaryExpressionStatement)(context, node);
|
|
22
26
|
if (binaryExpressionResult) {
|
|
23
27
|
return binaryExpressionResult;
|
|
24
28
|
}
|
|
@@ -10,6 +10,7 @@ const export_1 = require("../utils/export");
|
|
|
10
10
|
const function_context_1 = require("../utils/function-context");
|
|
11
11
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
12
12
|
const lualib_1 = require("../utils/lualib");
|
|
13
|
+
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
13
14
|
const scope_1 = require("../utils/scope");
|
|
14
15
|
const async_await_1 = require("./async-await");
|
|
15
16
|
const identifier_1 = require("./identifier");
|
|
@@ -34,10 +35,10 @@ function isRestParameterReferenced(identifier, scope) {
|
|
|
34
35
|
}
|
|
35
36
|
function transformFunctionBodyContent(context, body) {
|
|
36
37
|
if (!ts.isBlock(body)) {
|
|
37
|
-
const returnStatement = return_1.transformExpressionBodyToReturnStatement(context, body);
|
|
38
|
-
return [returnStatement];
|
|
38
|
+
const [precedingStatements, returnStatement] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, return_1.transformExpressionBodyToReturnStatement)(context, body));
|
|
39
|
+
return [...precedingStatements, returnStatement];
|
|
39
40
|
}
|
|
40
|
-
const bodyStatements = scope_1.performHoisting(context, context.transformStatements(body.statements));
|
|
41
|
+
const bodyStatements = (0, scope_1.performHoisting)(context, context.transformStatements(body.statements));
|
|
41
42
|
return bodyStatements;
|
|
42
43
|
}
|
|
43
44
|
exports.transformFunctionBodyContent = transformFunctionBodyContent;
|
|
@@ -54,16 +55,16 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
54
55
|
headerStatements.push(transformParameterDefaultValueDeclaration(context, identifier, declaration.initializer));
|
|
55
56
|
}
|
|
56
57
|
// Binding pattern
|
|
57
|
-
bindingPatternDeclarations.push(...variable_declaration_1.transformBindingPattern(context, declaration.name, identifier));
|
|
58
|
+
bindingPatternDeclarations.push(...(0, variable_declaration_1.transformBindingPattern)(context, declaration.name, identifier));
|
|
58
59
|
}
|
|
59
60
|
else if (declaration.initializer !== undefined) {
|
|
60
61
|
// Default parameter
|
|
61
|
-
headerStatements.push(transformParameterDefaultValueDeclaration(context, identifier_1.transformIdentifier(context, declaration.name), declaration.initializer));
|
|
62
|
+
headerStatements.push(transformParameterDefaultValueDeclaration(context, (0, identifier_1.transformIdentifier)(context, declaration.name), declaration.initializer));
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
// Push spread operator here
|
|
65
66
|
if (spreadIdentifier && isRestParameterReferenced(spreadIdentifier, bodyScope)) {
|
|
66
|
-
const spreadTable = lua_ast_1.wrapInTable(lua.createDotsLiteral());
|
|
67
|
+
const spreadTable = (0, lua_ast_1.wrapInTable)(lua.createDotsLiteral());
|
|
67
68
|
headerStatements.push(lua.createVariableDeclarationStatement(spreadIdentifier, spreadTable));
|
|
68
69
|
}
|
|
69
70
|
// Binding pattern statements need to be after spread table is declared
|
|
@@ -72,14 +73,14 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
72
73
|
}
|
|
73
74
|
exports.transformFunctionBodyHeader = transformFunctionBodyHeader;
|
|
74
75
|
function transformFunctionBody(context, parameters, body, spreadIdentifier, node) {
|
|
75
|
-
const scope = scope_1.pushScope(context, scope_1.ScopeType.Function);
|
|
76
|
+
const scope = (0, scope_1.pushScope)(context, scope_1.ScopeType.Function);
|
|
76
77
|
scope.node = node;
|
|
77
78
|
let bodyStatements = transformFunctionBodyContent(context, body);
|
|
78
|
-
if (node && async_await_1.isAsyncFunction(node)) {
|
|
79
|
-
bodyStatements = async_await_1.wrapInAsyncAwaiter(context, bodyStatements);
|
|
79
|
+
if (node && (0, async_await_1.isAsyncFunction)(node)) {
|
|
80
|
+
bodyStatements = (0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements);
|
|
80
81
|
}
|
|
81
82
|
const headerStatements = transformFunctionBodyHeader(context, scope, parameters, spreadIdentifier);
|
|
82
|
-
scope_1.popScope(context);
|
|
83
|
+
(0, scope_1.popScope)(context);
|
|
83
84
|
return [[...headerStatements, ...bodyStatements], scope];
|
|
84
85
|
}
|
|
85
86
|
exports.transformFunctionBody = transformFunctionBody;
|
|
@@ -101,7 +102,7 @@ function transformParameters(context, parameters, functionContext) {
|
|
|
101
102
|
// See transformFunctionBody for how these values are destructured
|
|
102
103
|
const paramName = ts.isObjectBindingPattern(param.name) || ts.isArrayBindingPattern(param.name)
|
|
103
104
|
? lua.createIdentifier(`____bindingPattern${identifierIndex++}`)
|
|
104
|
-
: identifier_1.transformIdentifier(context, param.name);
|
|
105
|
+
: (0, identifier_1.transformIdentifier)(context, param.name);
|
|
105
106
|
// This parameter is a spread parameter (...param)
|
|
106
107
|
if (!param.dotDotDotToken) {
|
|
107
108
|
paramNames.push(paramName);
|
|
@@ -116,10 +117,10 @@ function transformParameters(context, parameters, functionContext) {
|
|
|
116
117
|
}
|
|
117
118
|
exports.transformParameters = transformParameters;
|
|
118
119
|
function transformFunctionToExpression(context, node) {
|
|
119
|
-
utils_1.assert(node.body);
|
|
120
|
+
(0, utils_1.assert)(node.body);
|
|
120
121
|
const type = context.checker.getTypeAtLocation(node);
|
|
121
122
|
let functionContext;
|
|
122
|
-
if (function_context_1.getFunctionContextType(context, type) !== function_context_1.ContextType.Void) {
|
|
123
|
+
if ((0, function_context_1.getFunctionContextType)(context, type) !== function_context_1.ContextType.Void) {
|
|
123
124
|
if (ts.isArrowFunction(node)) {
|
|
124
125
|
// dummy context for arrow functions with parameters
|
|
125
126
|
if (node.parameters.length > 0) {
|
|
@@ -128,7 +129,7 @@ function transformFunctionToExpression(context, node) {
|
|
|
128
129
|
}
|
|
129
130
|
else {
|
|
130
131
|
// self context
|
|
131
|
-
functionContext = lua_ast_1.createSelfIdentifier();
|
|
132
|
+
functionContext = (0, lua_ast_1.createSelfIdentifier)();
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
let flags = lua.FunctionExpressionFlags.None;
|
|
@@ -142,7 +143,7 @@ function transformFunctionToExpression(context, node) {
|
|
|
142
143
|
const functionExpression = lua.createFunctionExpression(lua.createBlock(transformedBody), paramNames, dotsLiteral, flags, node);
|
|
143
144
|
return [
|
|
144
145
|
node.asteriskToken
|
|
145
|
-
? lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.Generator, undefined, functionExpression)
|
|
146
|
+
? (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Generator, undefined, functionExpression)
|
|
146
147
|
: functionExpression,
|
|
147
148
|
functionScope,
|
|
148
149
|
];
|
|
@@ -153,8 +154,8 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
153
154
|
// This code can be reached only from object methods, which is TypeScript error
|
|
154
155
|
return lua.createNilLiteral();
|
|
155
156
|
}
|
|
156
|
-
if (annotations_1.getNodeAnnotations(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
157
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.TupleReturn));
|
|
157
|
+
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
158
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
158
159
|
}
|
|
159
160
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
160
161
|
// Handle named function expressions which reference themselves
|
|
@@ -163,14 +164,11 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
163
164
|
if (symbol) {
|
|
164
165
|
// TODO: Not using symbol ids because of https://github.com/microsoft/TypeScript/issues/37131
|
|
165
166
|
const isReferenced = [...functionScope.referencedSymbols].some(([, nodes]) => nodes.some(n => { var _a; return ((_a = context.checker.getSymbolAtLocation(n)) === null || _a === void 0 ? void 0 : _a.valueDeclaration) === symbol.valueDeclaration; }));
|
|
166
|
-
// Only
|
|
167
|
+
// Only handle if the name is actually referenced inside the function
|
|
167
168
|
if (isReferenced) {
|
|
168
|
-
const nameIdentifier = identifier_1.transformIdentifier(context, node.name);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// with var-arg optimization because the IIFE is just wrapping another function which will already push
|
|
172
|
-
// another scope.
|
|
173
|
-
return lua_ast_1.createImmediatelyInvokedFunctionExpression([lua.createVariableDeclarationStatement(nameIdentifier, functionExpression)], lua.cloneIdentifier(nameIdentifier));
|
|
169
|
+
const nameIdentifier = (0, identifier_1.transformIdentifier)(context, node.name);
|
|
170
|
+
context.addPrecedingStatements(lua.createVariableDeclarationStatement(nameIdentifier, functionExpression));
|
|
171
|
+
return lua.cloneIdentifier(nameIdentifier);
|
|
174
172
|
}
|
|
175
173
|
}
|
|
176
174
|
}
|
|
@@ -179,35 +177,35 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
179
177
|
exports.transformFunctionLikeDeclaration = transformFunctionLikeDeclaration;
|
|
180
178
|
const transformFunctionDeclaration = (node, context) => {
|
|
181
179
|
var _a;
|
|
182
|
-
if (annotations_1.getNodeAnnotations(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
183
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.TupleReturn));
|
|
180
|
+
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
181
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
184
182
|
}
|
|
185
183
|
// Don't transform functions without body (overload declarations)
|
|
186
184
|
if (node.body === undefined) {
|
|
187
185
|
return undefined;
|
|
188
186
|
}
|
|
189
|
-
if (export_1.hasDefaultExportModifier(node)) {
|
|
190
|
-
return lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createExportsIdentifier(), export_1.createDefaultExportStringLiteral(node)), transformFunctionLikeDeclaration(node, context));
|
|
187
|
+
if ((0, export_1.hasDefaultExportModifier)(node)) {
|
|
188
|
+
return lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, export_1.createDefaultExportStringLiteral)(node)), transformFunctionLikeDeclaration(node, context));
|
|
191
189
|
}
|
|
192
190
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
193
191
|
// Name being undefined without default export is a TypeScript error
|
|
194
|
-
const name = node.name ? identifier_1.transformIdentifier(context, node.name) : lua.createAnonymousIdentifier();
|
|
192
|
+
const name = node.name ? (0, identifier_1.transformIdentifier)(context, node.name) : lua.createAnonymousIdentifier();
|
|
195
193
|
// Remember symbols referenced in this function for hoisting later
|
|
196
194
|
if (name.symbolId !== undefined) {
|
|
197
|
-
const scope = scope_1.peekScope(context);
|
|
195
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
198
196
|
if (!scope.functionDefinitions) {
|
|
199
197
|
scope.functionDefinitions = new Map();
|
|
200
198
|
}
|
|
201
199
|
const functionInfo = { referencedSymbols: (_a = functionScope.referencedSymbols) !== null && _a !== void 0 ? _a : new Map() };
|
|
202
200
|
scope.functionDefinitions.set(name.symbolId, functionInfo);
|
|
203
201
|
}
|
|
204
|
-
return lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, name, functionExpression, node);
|
|
202
|
+
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, name, functionExpression, node);
|
|
205
203
|
};
|
|
206
204
|
exports.transformFunctionDeclaration = transformFunctionDeclaration;
|
|
207
205
|
const transformYieldExpression = (expression, context) => {
|
|
208
206
|
const parameters = expression.expression ? [context.transformExpression(expression.expression)] : [];
|
|
209
207
|
return expression.asteriskToken
|
|
210
|
-
? lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.DelegatedYield, expression, ...parameters)
|
|
208
|
+
? (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DelegatedYield, expression, ...parameters)
|
|
211
209
|
: lua.createCallExpression(lua.createTableIndexExpression(lua.createIdentifier("coroutine"), lua.createStringLiteral("yield")), parameters, expression);
|
|
212
210
|
};
|
|
213
211
|
exports.transformYieldExpression = transformYieldExpression;
|
|
@@ -16,53 +16,57 @@ const operators_1 = require("./language-extensions/operators");
|
|
|
16
16
|
const range_1 = require("./language-extensions/range");
|
|
17
17
|
const table_1 = require("./language-extensions/table");
|
|
18
18
|
const vararg_1 = require("./language-extensions/vararg");
|
|
19
|
+
const optional_chaining_1 = require("./optional-chaining");
|
|
19
20
|
function transformIdentifier(context, identifier) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
21
|
+
if ((0, optional_chaining_1.isOptionalContinuation)(identifier)) {
|
|
22
|
+
return lua.createIdentifier(identifier.text);
|
|
23
|
+
}
|
|
24
|
+
if ((0, multi_1.isMultiFunctionNode)(context, identifier)) {
|
|
25
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(identifier));
|
|
22
26
|
return lua.createAnonymousIdentifier(identifier);
|
|
23
27
|
}
|
|
24
|
-
if (operators_1.isOperatorMapping(context, identifier)) {
|
|
25
|
-
context.diagnostics.push(diagnostics_1.invalidOperatorMappingUse(identifier));
|
|
28
|
+
if ((0, operators_1.isOperatorMapping)(context, identifier)) {
|
|
29
|
+
context.diagnostics.push((0, diagnostics_1.invalidOperatorMappingUse)(identifier));
|
|
26
30
|
}
|
|
27
|
-
if (table_1.isTableExtensionIdentifier(context, identifier)) {
|
|
28
|
-
context.diagnostics.push(diagnostics_1.invalidTableExtensionUse(identifier));
|
|
31
|
+
if ((0, table_1.isTableExtensionIdentifier)(context, identifier)) {
|
|
32
|
+
context.diagnostics.push((0, diagnostics_1.invalidTableExtensionUse)(identifier));
|
|
29
33
|
}
|
|
30
|
-
if (range_1.isRangeFunctionNode(context, identifier)) {
|
|
31
|
-
context.diagnostics.push(diagnostics_1.invalidRangeUse(identifier));
|
|
34
|
+
if ((0, range_1.isRangeFunctionNode)(context, identifier)) {
|
|
35
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeUse)(identifier));
|
|
32
36
|
return lua.createAnonymousIdentifier(identifier);
|
|
33
37
|
}
|
|
34
|
-
if (vararg_1.isVarargConstantNode(context, identifier)) {
|
|
35
|
-
context.diagnostics.push(diagnostics_1.invalidVarargUse(identifier));
|
|
38
|
+
if ((0, vararg_1.isVarargConstantNode)(context, identifier)) {
|
|
39
|
+
context.diagnostics.push((0, diagnostics_1.invalidVarargUse)(identifier));
|
|
36
40
|
return lua.createAnonymousIdentifier(identifier);
|
|
37
41
|
}
|
|
38
|
-
if (annotations_1.isForRangeType(context, identifier)) {
|
|
39
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(identifier, annotations_1.AnnotationKind.ForRange));
|
|
42
|
+
if ((0, annotations_1.isForRangeType)(context, identifier)) {
|
|
43
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(identifier, annotations_1.AnnotationKind.ForRange));
|
|
40
44
|
}
|
|
41
|
-
if (promise_1.isPromiseClass(context, identifier)) {
|
|
42
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Promise);
|
|
43
|
-
return promise_1.createPromiseIdentifier(identifier);
|
|
45
|
+
if ((0, promise_1.isPromiseClass)(context, identifier)) {
|
|
46
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
47
|
+
return (0, promise_1.createPromiseIdentifier)(identifier);
|
|
44
48
|
}
|
|
45
|
-
const text = safe_names_1.hasUnsafeIdentifierName(context, identifier) ? safe_names_1.createSafeName(identifier.text) : identifier.text;
|
|
46
|
-
const symbolId = symbols_1.getIdentifierSymbolId(context, identifier);
|
|
49
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier) ? (0, safe_names_1.createSafeName)(identifier.text) : identifier.text;
|
|
50
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, identifier);
|
|
47
51
|
return lua.createIdentifier(text, identifier, symbolId, identifier.text);
|
|
48
52
|
}
|
|
49
53
|
exports.transformIdentifier = transformIdentifier;
|
|
50
54
|
const transformIdentifierExpression = (node, context) => {
|
|
51
55
|
const symbol = context.checker.getSymbolAtLocation(node);
|
|
52
56
|
if (symbol) {
|
|
53
|
-
const exportScope = export_1.getSymbolExportScope(context, symbol);
|
|
57
|
+
const exportScope = (0, export_1.getSymbolExportScope)(context, symbol);
|
|
54
58
|
if (exportScope) {
|
|
55
59
|
const name = symbol.name;
|
|
56
|
-
const text = safe_names_1.hasUnsafeIdentifierName(context, node) ? safe_names_1.createSafeName(name) : name;
|
|
57
|
-
const symbolId = symbols_1.getIdentifierSymbolId(context, node);
|
|
60
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, node) ? (0, safe_names_1.createSafeName)(name) : name;
|
|
61
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, node);
|
|
58
62
|
const identifier = lua.createIdentifier(text, node, symbolId, name);
|
|
59
|
-
return export_1.createExportedIdentifier(context, identifier, exportScope);
|
|
63
|
+
return (0, export_1.createExportedIdentifier)(context, identifier, exportScope);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
|
|
63
67
|
return lua.createNilLiteral();
|
|
64
68
|
}
|
|
65
|
-
const builtinResult = builtins_1.transformBuiltinIdentifierExpression(context, node);
|
|
69
|
+
const builtinResult = (0, builtins_1.transformBuiltinIdentifierExpression)(context, node);
|
|
66
70
|
if (builtinResult) {
|
|
67
71
|
return builtinResult;
|
|
68
72
|
}
|
|
@@ -33,14 +33,13 @@ const typeof_1 = require("./typeof");
|
|
|
33
33
|
const typescript_1 = require("./typescript");
|
|
34
34
|
const unary_expression_1 = require("./unary-expression");
|
|
35
35
|
const variable_declaration_1 = require("./variable-declaration");
|
|
36
|
-
const jsx_1 = require("./jsx/jsx");
|
|
37
36
|
const async_await_1 = require("./async-await");
|
|
37
|
+
const void_1 = require("./void");
|
|
38
38
|
const transformEmptyStatement = () => undefined;
|
|
39
39
|
const transformParenthesizedExpression = (node, context) => context.transformExpression(node.expression);
|
|
40
40
|
exports.standardVisitors = {
|
|
41
41
|
...literal_1.literalVisitors,
|
|
42
42
|
...typescript_1.typescriptVisitors,
|
|
43
|
-
...jsx_1.jsxVisitors,
|
|
44
43
|
[ts.SyntaxKind.ArrowFunction]: function_1.transformFunctionLikeDeclaration,
|
|
45
44
|
[ts.SyntaxKind.AwaitExpression]: async_await_1.transformAwaitExpression,
|
|
46
45
|
[ts.SyntaxKind.BinaryExpression]: binary_expression_1.transformBinaryExpression,
|
|
@@ -90,5 +89,6 @@ exports.standardVisitors = {
|
|
|
90
89
|
[ts.SyntaxKind.VariableStatement]: variable_declaration_1.transformVariableStatement,
|
|
91
90
|
[ts.SyntaxKind.WhileStatement]: do_while_1.transformWhileStatement,
|
|
92
91
|
[ts.SyntaxKind.YieldExpression]: function_1.transformYieldExpression,
|
|
92
|
+
[ts.SyntaxKind.VoidExpression]: void_1.transformVoidExpression,
|
|
93
93
|
};
|
|
94
94
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,12 +30,12 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
30
30
|
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
31
31
|
// Variables declared in for loop
|
|
32
32
|
// for ${initializer} in ${iterable} do
|
|
33
|
-
const binding = utils_1.getVariableDeclarationBinding(context, statement.initializer);
|
|
33
|
+
const binding = (0, utils_1.getVariableDeclarationBinding)(context, statement.initializer);
|
|
34
34
|
if (ts.isArrayBindingPattern(binding)) {
|
|
35
|
-
identifiers = binding.elements.map(e => variable_declaration_1.transformArrayBindingElement(context, e));
|
|
35
|
+
identifiers = binding.elements.map(e => (0, variable_declaration_1.transformArrayBindingElement)(context, e));
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
context.diagnostics.push(diagnostics_1.invalidMultiIterableWithoutDestructuring(binding));
|
|
38
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiIterableWithoutDestructuring)(binding));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
else if (ts.isArrayLiteralExpression(statement.initializer)) {
|
|
@@ -44,11 +44,11 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
44
44
|
// ${initializer} = ____value0
|
|
45
45
|
identifiers = statement.initializer.elements.map((_, i) => lua.createIdentifier(`____value${i}`));
|
|
46
46
|
if (identifiers.length > 0) {
|
|
47
|
-
block.statements.unshift(lua.createAssignmentStatement(statement.initializer.elements.map(e => utils_2.cast(context.transformExpression(e), lua.isAssignmentLeftHandSideExpression)), identifiers));
|
|
47
|
+
block.statements.unshift(lua.createAssignmentStatement(statement.initializer.elements.map(e => (0, utils_2.cast)(context.transformExpression(e), lua.isAssignmentLeftHandSideExpression)), identifiers));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
context.diagnostics.push(diagnostics_1.invalidMultiIterableWithoutDestructuring(statement.initializer));
|
|
51
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiIterableWithoutDestructuring)(statement.initializer));
|
|
52
52
|
}
|
|
53
53
|
if (identifiers.length === 0) {
|
|
54
54
|
identifiers.push(lua.createAnonymousIdentifier());
|
|
@@ -58,11 +58,11 @@ function transformForOfMultiIterableStatement(context, statement, block) {
|
|
|
58
58
|
function transformForOfIterableStatement(context, statement, block) {
|
|
59
59
|
var _a;
|
|
60
60
|
const type = context.checker.getTypeAtLocation(statement.expression);
|
|
61
|
-
if (((_a = type.aliasTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 2 && multi_1.isMultiReturnType(type.aliasTypeArguments[0])) {
|
|
61
|
+
if (((_a = type.aliasTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 2 && (0, multi_1.isMultiReturnType)(type.aliasTypeArguments[0])) {
|
|
62
62
|
return transformForOfMultiIterableStatement(context, statement, block);
|
|
63
63
|
}
|
|
64
64
|
const luaIterator = context.transformExpression(statement.expression);
|
|
65
|
-
const identifier = utils_1.transformForInitializer(context, statement.initializer, block);
|
|
65
|
+
const identifier = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
66
66
|
return lua.createForInStatement(block, [identifier], [luaIterator], statement);
|
|
67
67
|
}
|
|
68
68
|
exports.transformForOfIterableStatement = transformForOfIterableStatement;
|
|
@@ -8,4 +8,4 @@ export declare function isMultiReturnCall(context: TransformationContext, expres
|
|
|
8
8
|
export declare function isMultiFunctionNode(context: TransformationContext, node: ts.Node): boolean;
|
|
9
9
|
export declare function isInMultiReturnFunction(context: TransformationContext, node: ts.Node): boolean;
|
|
10
10
|
export declare function shouldMultiReturnCallBeWrapped(context: TransformationContext, node: ts.CallExpression): boolean;
|
|
11
|
-
export declare function findMultiAssignmentViolations(context: TransformationContext, node: ts.
|
|
11
|
+
export declare function findMultiAssignmentViolations(context: TransformationContext, node: ts.ObjectLiteralExpression): ts.Node[];
|
|
@@ -34,7 +34,7 @@ function isMultiFunctionNode(context, node) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.isMultiFunctionNode = isMultiFunctionNode;
|
|
36
36
|
function isInMultiReturnFunction(context, node) {
|
|
37
|
-
const declaration = typescript_1.findFirstNodeAbove(node, ts.isFunctionLike);
|
|
37
|
+
const declaration = (0, typescript_1.findFirstNodeAbove)(node, ts.isFunctionLike);
|
|
38
38
|
if (!declaration) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
@@ -75,7 +75,7 @@ function shouldMultiReturnCallBeWrapped(context, node) {
|
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
// LuaIterable in for...of
|
|
78
|
-
if (ts.isForOfStatement(node.parent) && iterable_1.isIterableExpression(context, node)) {
|
|
78
|
+
if (ts.isForOfStatement(node.parent) && (0, iterable_1.isIterableExpression)(context, node)) {
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
return true;
|
|
@@ -89,7 +89,7 @@ function findMultiAssignmentViolations(context, node) {
|
|
|
89
89
|
const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(element);
|
|
90
90
|
if (valueSymbol) {
|
|
91
91
|
if (extensions.isExtensionValue(context, valueSymbol, extensions.ExtensionKind.MultiFunction)) {
|
|
92
|
-
context.diagnostics.push(diagnostics_1.invalidMultiFunctionUse(element));
|
|
92
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(element));
|
|
93
93
|
result.push(element);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -64,7 +64,7 @@ const bitwiseOperatorMapExtensions = new Set([
|
|
|
64
64
|
extensions.ExtensionKind.BitwiseNotOperatorMethodType,
|
|
65
65
|
]);
|
|
66
66
|
function getOperatorMapExtensionKindForCall(context, node) {
|
|
67
|
-
const type = typescript_1.getFunctionTypeForCall(context, node);
|
|
67
|
+
const type = (0, typescript_1.getFunctionTypeForCall)(context, node);
|
|
68
68
|
return type && operatorMapExtensions.find(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
69
69
|
}
|
|
70
70
|
function isOperatorMapping(context, node) {
|
|
@@ -79,7 +79,7 @@ function isOperatorMapping(context, node) {
|
|
|
79
79
|
exports.isOperatorMapping = isOperatorMapping;
|
|
80
80
|
function transformOperatorMappingExpression(context, node) {
|
|
81
81
|
const extensionKind = getOperatorMapExtensionKindForCall(context, node);
|
|
82
|
-
utils_1.assert(extensionKind);
|
|
82
|
+
(0, utils_1.assert)(extensionKind);
|
|
83
83
|
const isBefore53 = context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 ||
|
|
84
84
|
context.luaTarget === CompilerOptions_1.LuaTarget.Lua52 ||
|
|
85
85
|
context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT ||
|
|
@@ -87,11 +87,11 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
87
87
|
if (isBefore53) {
|
|
88
88
|
const luaTarget = context.luaTarget === CompilerOptions_1.LuaTarget.Universal ? CompilerOptions_1.LuaTarget.Lua51 : context.luaTarget;
|
|
89
89
|
if (bitwiseOperatorMapExtensions.has(extensionKind)) {
|
|
90
|
-
context.diagnostics.push(diagnostics_1.unsupportedForTarget(node, "Native bitwise operations", luaTarget));
|
|
90
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Native bitwise operations", luaTarget));
|
|
91
91
|
}
|
|
92
92
|
else if (extensionKind === extensions.ExtensionKind.FloorDivisionOperatorType ||
|
|
93
93
|
extensionKind === extensions.ExtensionKind.FloorDivisionOperatorMethodType) {
|
|
94
|
-
context.diagnostics.push(diagnostics_1.unsupportedForTarget(node, "Floor division operator", luaTarget));
|
|
94
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(node, "Floor division operator", luaTarget));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
const args = node.arguments.slice();
|
|
@@ -101,7 +101,7 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
101
101
|
args.unshift(node.expression.expression);
|
|
102
102
|
}
|
|
103
103
|
const luaOperator = binaryOperatorMappings.get(extensionKind);
|
|
104
|
-
utils_1.assert(luaOperator);
|
|
104
|
+
(0, utils_1.assert)(luaOperator);
|
|
105
105
|
return lua.createBinaryExpression(context.transformExpression(args[0]), context.transformExpression(args[1]), luaOperator);
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
@@ -114,7 +114,7 @@ function transformOperatorMappingExpression(context, node) {
|
|
|
114
114
|
arg = args[0];
|
|
115
115
|
}
|
|
116
116
|
const luaOperator = unaryOperatorMappings.get(extensionKind);
|
|
117
|
-
utils_1.assert(luaOperator);
|
|
117
|
+
(0, utils_1.assert)(luaOperator);
|
|
118
118
|
return lua.createUnaryExpression(context.transformExpression(arg), luaOperator);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -20,21 +20,21 @@ function isRangeFunctionNode(context, node) {
|
|
|
20
20
|
exports.isRangeFunctionNode = isRangeFunctionNode;
|
|
21
21
|
function getControlVariable(context, statement) {
|
|
22
22
|
if (!ts.isVariableDeclarationList(statement.initializer)) {
|
|
23
|
-
context.diagnostics.push(diagnostics_1.invalidRangeControlVariable(statement.initializer));
|
|
23
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeControlVariable)(statement.initializer));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const binding = utils_1.getVariableDeclarationBinding(context, statement.initializer);
|
|
26
|
+
const binding = (0, utils_1.getVariableDeclarationBinding)(context, statement.initializer);
|
|
27
27
|
if (!ts.isIdentifier(binding)) {
|
|
28
|
-
context.diagnostics.push(diagnostics_1.invalidRangeControlVariable(statement.initializer));
|
|
28
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeControlVariable)(statement.initializer));
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
return identifier_1.transformIdentifier(context, binding);
|
|
31
|
+
return (0, identifier_1.transformIdentifier)(context, binding);
|
|
32
32
|
}
|
|
33
33
|
function transformRangeStatement(context, statement, block) {
|
|
34
34
|
var _a;
|
|
35
|
-
utils_2.assert(ts.isCallExpression(statement.expression));
|
|
35
|
+
(0, utils_2.assert)(ts.isCallExpression(statement.expression));
|
|
36
36
|
const controlVariable = (_a = getControlVariable(context, statement)) !== null && _a !== void 0 ? _a : lua.createAnonymousIdentifier(statement.initializer);
|
|
37
|
-
const [start = lua.createNumericLiteral(0), limit = lua.createNumericLiteral(0), step] = call_1.transformArguments(context, statement.expression.arguments, context.checker.getResolvedSignature(statement.expression));
|
|
37
|
+
const [start = lua.createNumericLiteral(0), limit = lua.createNumericLiteral(0), step] = (0, call_1.transformArguments)(context, statement.expression.arguments, context.checker.getResolvedSignature(statement.expression));
|
|
38
38
|
return lua.createForStatement(block, controlVariable, start, limit, step, statement);
|
|
39
39
|
}
|
|
40
40
|
exports.transformRangeStatement = transformRangeStatement;
|
|
@@ -21,7 +21,7 @@ const tableExtensions = [
|
|
|
21
21
|
...tableSetExtensions,
|
|
22
22
|
];
|
|
23
23
|
function getTableExtensionKindForCall(context, node, validExtensions) {
|
|
24
|
-
const type = typescript_1.getFunctionTypeForCall(context, node);
|
|
24
|
+
const type = (0, typescript_1.getFunctionTypeForCall)(context, node);
|
|
25
25
|
return type && validExtensions.find(extensionKind => extensions.isExtensionType(type, extensionKind));
|
|
26
26
|
}
|
|
27
27
|
function isTableExtensionIdentifier(context, node) {
|
|
@@ -52,7 +52,7 @@ function isTableNewCall(context, node) {
|
|
|
52
52
|
exports.isTableNewCall = isTableNewCall;
|
|
53
53
|
function transformTableDeleteExpression(context, node) {
|
|
54
54
|
const extensionKind = getTableExtensionKindForCall(context, node, tableDeleteExtensions);
|
|
55
|
-
utils_1.assert(extensionKind);
|
|
55
|
+
(0, utils_1.assert)(extensionKind);
|
|
56
56
|
const args = node.arguments.slice();
|
|
57
57
|
if (args.length === 1 &&
|
|
58
58
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -65,7 +65,7 @@ function transformTableDeleteExpression(context, node) {
|
|
|
65
65
|
exports.transformTableDeleteExpression = transformTableDeleteExpression;
|
|
66
66
|
function transformTableGetExpression(context, node) {
|
|
67
67
|
const extensionKind = getTableExtensionKindForCall(context, node, tableGetExtensions);
|
|
68
|
-
utils_1.assert(extensionKind);
|
|
68
|
+
(0, utils_1.assert)(extensionKind);
|
|
69
69
|
const args = node.arguments.slice();
|
|
70
70
|
if (args.length === 1 &&
|
|
71
71
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -78,7 +78,7 @@ function transformTableGetExpression(context, node) {
|
|
|
78
78
|
exports.transformTableGetExpression = transformTableGetExpression;
|
|
79
79
|
function transformTableHasExpression(context, node) {
|
|
80
80
|
const extensionKind = getTableExtensionKindForCall(context, node, tableHasExtensions);
|
|
81
|
-
utils_1.assert(extensionKind);
|
|
81
|
+
(0, utils_1.assert)(extensionKind);
|
|
82
82
|
const args = node.arguments.slice();
|
|
83
83
|
if (args.length === 1 &&
|
|
84
84
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
@@ -93,7 +93,7 @@ function transformTableHasExpression(context, node) {
|
|
|
93
93
|
exports.transformTableHasExpression = transformTableHasExpression;
|
|
94
94
|
function transformTableSetExpression(context, node) {
|
|
95
95
|
const extensionKind = getTableExtensionKindForCall(context, node, tableSetExtensions);
|
|
96
|
-
utils_1.assert(extensionKind);
|
|
96
|
+
(0, utils_1.assert)(extensionKind);
|
|
97
97
|
const args = node.arguments.slice();
|
|
98
98
|
if (args.length === 2 &&
|
|
99
99
|
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|