typescript-to-lua 1.0.1 → 1.3.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 +46 -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 +6 -5
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +81 -29
- 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 +43 -19
- package/dist/lualib/CloneDescriptor.lua +7 -7
- 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 +44 -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 +876 -745
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +14 -12
- 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 +9 -0
- package/dist/transformation/utils/diagnostics.js +8 -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/language-extensions.d.ts +2 -0
- package/dist/transformation/utils/language-extensions.js +7 -1
- 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.d.ts +4 -2
- package/dist/transformation/utils/safe-names.js +13 -7
- package/dist/transformation/utils/scope.d.ts +9 -1
- package/dist/transformation/utils/scope.js +78 -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/utils/typescript/types.d.ts +3 -1
- package/dist/transformation/utils/typescript/types.js +40 -13
- 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 -42
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +2 -2
- 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 +36 -43
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +35 -33
- 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.d.ts +2 -0
- package/dist/transformation/visitors/function.js +80 -33
- 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/pairsIterable.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
- 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 +17 -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 +26 -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 +23 -16
- package/dist/transformation/visitors/switch.js +63 -20
- 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 +55 -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 +52 -10
- 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 +20 -13
- 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/language-extensions/index.d.ts +11 -1
- 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
|
@@ -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
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import * as lua from "../../../LuaAST";
|
|
3
|
+
import { TransformationContext } from "../../context";
|
|
4
|
+
export declare function isPairsIterableExpression(context: TransformationContext, expression: ts.Expression): boolean;
|
|
5
|
+
export declare function transformForOfPairsIterableStatement(context: TransformationContext, statement: ts.ForOfStatement, block: lua.Block): lua.Statement;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformForOfPairsIterableStatement = exports.isPairsIterableExpression = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const lua = require("../../../LuaAST");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const diagnostics_1 = require("../../utils/diagnostics");
|
|
8
|
+
const extensions = require("../../utils/language-extensions");
|
|
9
|
+
const utils_2 = require("../loops/utils");
|
|
10
|
+
const variable_declaration_1 = require("../variable-declaration");
|
|
11
|
+
function isPairsIterableType(type) {
|
|
12
|
+
return extensions.isExtensionType(type, extensions.ExtensionKind.PairsIterableType);
|
|
13
|
+
}
|
|
14
|
+
function isPairsIterableExpression(context, expression) {
|
|
15
|
+
const type = context.checker.getTypeAtLocation(expression);
|
|
16
|
+
return isPairsIterableType(type);
|
|
17
|
+
}
|
|
18
|
+
exports.isPairsIterableExpression = isPairsIterableExpression;
|
|
19
|
+
function transformForOfPairsIterableStatement(context, statement, block) {
|
|
20
|
+
const pairsCall = lua.createCallExpression(lua.createIdentifier("pairs"), [
|
|
21
|
+
context.transformExpression(statement.expression),
|
|
22
|
+
]);
|
|
23
|
+
let identifiers = [];
|
|
24
|
+
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
25
|
+
// Variables declared in for loop
|
|
26
|
+
// for key, value in iterable do
|
|
27
|
+
const binding = (0, utils_2.getVariableDeclarationBinding)(context, statement.initializer);
|
|
28
|
+
if (ts.isArrayBindingPattern(binding)) {
|
|
29
|
+
identifiers = binding.elements.map(e => (0, variable_declaration_1.transformArrayBindingElement)(context, e));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
context.diagnostics.push((0, diagnostics_1.invalidPairsIterableWithoutDestructuring)(binding));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (ts.isArrayLiteralExpression(statement.initializer)) {
|
|
36
|
+
// Variables NOT declared in for loop - catch iterator values in temps and assign
|
|
37
|
+
// for ____key, ____value in iterable do
|
|
38
|
+
// key, value = ____key, ____value
|
|
39
|
+
identifiers = statement.initializer.elements.map(e => context.createTempNameForNode(e));
|
|
40
|
+
if (identifiers.length > 0) {
|
|
41
|
+
block.statements.unshift(lua.createAssignmentStatement(statement.initializer.elements.map(e => (0, utils_1.cast)(context.transformExpression(e), lua.isAssignmentLeftHandSideExpression)), identifiers));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
context.diagnostics.push((0, diagnostics_1.invalidPairsIterableWithoutDestructuring)(statement.initializer));
|
|
46
|
+
}
|
|
47
|
+
if (identifiers.length === 0) {
|
|
48
|
+
identifiers.push(lua.createAnonymousIdentifier());
|
|
49
|
+
}
|
|
50
|
+
return lua.createForInStatement(block, identifiers, [pairsCall], statement);
|
|
51
|
+
}
|
|
52
|
+
exports.transformForOfPairsIterableStatement = transformForOfPairsIterableStatement;
|
|
53
|
+
//# sourceMappingURL=pairsIterable.js.map
|
|
@@ -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))) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
|
-
import {
|
|
3
|
+
import { TransformationContext, Visitors } from "../context";
|
|
4
4
|
export declare function transformPropertyName(context: TransformationContext, node: ts.PropertyName): lua.Expression;
|
|
5
5
|
export declare function createShorthandIdentifier(context: TransformationContext, valueSymbol: ts.Symbol | undefined, propertyIdentifier: ts.Identifier): lua.Expression;
|
|
6
|
-
export declare const transformJsxAttributes: FunctionVisitor<ts.JsxAttributes>;
|
|
7
6
|
export declare const literalVisitors: Visitors;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.literalVisitors = exports.
|
|
3
|
+
exports.literalVisitors = exports.createShorthandIdentifier = exports.transformPropertyName = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
@@ -11,9 +11,8 @@ const safe_names_1 = require("../utils/safe-names");
|
|
|
11
11
|
const symbols_1 = require("../utils/symbols");
|
|
12
12
|
const typescript_1 = require("../utils/typescript");
|
|
13
13
|
const function_1 = require("./function");
|
|
14
|
-
const
|
|
14
|
+
const expression_list_1 = require("./expression-list");
|
|
15
15
|
const multi_1 = require("./language-extensions/multi");
|
|
16
|
-
const jsx_1 = require("./jsx/jsx");
|
|
17
16
|
// TODO: Move to object-literal.ts?
|
|
18
17
|
function transformPropertyName(context, node) {
|
|
19
18
|
if (ts.isComputedPropertyName(node)) {
|
|
@@ -33,16 +32,16 @@ exports.transformPropertyName = transformPropertyName;
|
|
|
33
32
|
function createShorthandIdentifier(context, valueSymbol, propertyIdentifier) {
|
|
34
33
|
const propertyName = propertyIdentifier.text;
|
|
35
34
|
const isUnsafeName = valueSymbol
|
|
36
|
-
? safe_names_1.hasUnsafeSymbolName(context, valueSymbol, propertyIdentifier)
|
|
37
|
-
: safe_names_1.hasUnsafeIdentifierName(context, propertyIdentifier, false);
|
|
38
|
-
const name = isUnsafeName ? safe_names_1.createSafeName(propertyName) : propertyName;
|
|
35
|
+
? (0, safe_names_1.hasUnsafeSymbolName)(context, valueSymbol, propertyIdentifier)
|
|
36
|
+
: (0, safe_names_1.hasUnsafeIdentifierName)(context, propertyIdentifier, false);
|
|
37
|
+
const name = isUnsafeName ? (0, safe_names_1.createSafeName)(propertyName) : propertyName;
|
|
39
38
|
let identifier = context.transformExpression(ts.factory.createIdentifier(name));
|
|
40
39
|
lua.setNodeOriginal(identifier, propertyIdentifier);
|
|
41
40
|
if (valueSymbol !== undefined && lua.isIdentifier(identifier)) {
|
|
42
|
-
identifier.symbolId = symbols_1.getSymbolIdOfSymbol(context, valueSymbol);
|
|
43
|
-
const exportScope = export_1.getSymbolExportScope(context, valueSymbol);
|
|
41
|
+
identifier.symbolId = (0, symbols_1.getSymbolIdOfSymbol)(context, valueSymbol);
|
|
42
|
+
const exportScope = (0, export_1.getSymbolExportScope)(context, valueSymbol);
|
|
44
43
|
if (exportScope) {
|
|
45
|
-
identifier = export_1.createExportedIdentifier(context, identifier, exportScope);
|
|
44
|
+
identifier = (0, export_1.createExportedIdentifier)(context, identifier, exportScope);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
return identifier;
|
|
@@ -56,96 +55,127 @@ const transformNumericLiteralExpression = expression => {
|
|
|
56
55
|
}
|
|
57
56
|
return lua.createNumericLiteral(Number(expression.text), expression);
|
|
58
57
|
};
|
|
59
|
-
const
|
|
60
|
-
const violations = multi_1.findMultiAssignmentViolations(context, expression);
|
|
58
|
+
const transformObjectLiteralExpression = (expression, context) => {
|
|
59
|
+
const violations = (0, multi_1.findMultiAssignmentViolations)(context, expression);
|
|
61
60
|
if (violations.length > 0) {
|
|
62
|
-
context.diagnostics.push(...violations.map(e => diagnostics_1.invalidMultiFunctionUse(e)));
|
|
61
|
+
context.diagnostics.push(...violations.map(e => (0, diagnostics_1.invalidMultiFunctionUse)(e)));
|
|
63
62
|
return lua.createNilLiteral(expression);
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
64
|
+
const properties = [];
|
|
65
|
+
const initializers = [];
|
|
66
|
+
const keyPrecedingStatements = [];
|
|
67
|
+
const valuePrecedingStatements = [];
|
|
68
|
+
let lastPrecedingStatementsIndex = -1;
|
|
69
|
+
for (let i = 0; i < expression.properties.length; ++i) {
|
|
70
|
+
const element = expression.properties[i];
|
|
71
|
+
// Transform key and cache preceding statements
|
|
72
|
+
context.pushPrecedingStatements();
|
|
68
73
|
const name = element.name ? transformPropertyName(context, element.name) : undefined;
|
|
74
|
+
let precedingStatements = context.popPrecedingStatements();
|
|
75
|
+
keyPrecedingStatements.push(precedingStatements);
|
|
76
|
+
if (precedingStatements.length > 0) {
|
|
77
|
+
lastPrecedingStatementsIndex = i;
|
|
78
|
+
}
|
|
79
|
+
// Transform value and cache preceding statements
|
|
80
|
+
context.pushPrecedingStatements();
|
|
69
81
|
if (ts.isPropertyAssignment(element)) {
|
|
70
82
|
const expression = context.transformExpression(element.initializer);
|
|
71
83
|
properties.push(lua.createTableFieldExpression(expression, name, element));
|
|
72
|
-
|
|
73
|
-
else if (ts.isJsxAttribute(element)) {
|
|
74
|
-
const initializer = element.initializer;
|
|
75
|
-
let expression;
|
|
76
|
-
if (initializer === undefined) {
|
|
77
|
-
expression = lua.createBooleanLiteral(true);
|
|
78
|
-
}
|
|
79
|
-
else if (ts.isStringLiteral(initializer)) {
|
|
80
|
-
const text = jsx_1.formatJSXStringValueLiteral(initializer.text);
|
|
81
|
-
expression = lua.createStringLiteral(text, initializer);
|
|
82
|
-
}
|
|
83
|
-
else if (ts.isJsxExpression(initializer)) {
|
|
84
|
-
expression = initializer.expression
|
|
85
|
-
? context.transformExpression(initializer.expression)
|
|
86
|
-
: lua.createBooleanLiteral(true);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
utils_1.assertNever(initializer);
|
|
90
|
-
}
|
|
91
|
-
properties.push(lua.createTableFieldExpression(expression, name, element));
|
|
84
|
+
initializers.push(element.initializer);
|
|
92
85
|
}
|
|
93
86
|
else if (ts.isShorthandPropertyAssignment(element)) {
|
|
94
87
|
const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(element);
|
|
95
88
|
if (valueSymbol) {
|
|
96
|
-
symbols_1.trackSymbolReference(context, valueSymbol, element.name);
|
|
89
|
+
(0, symbols_1.trackSymbolReference)(context, valueSymbol, element.name);
|
|
97
90
|
}
|
|
98
91
|
const identifier = createShorthandIdentifier(context, valueSymbol, element.name);
|
|
99
92
|
properties.push(lua.createTableFieldExpression(identifier, name, element));
|
|
93
|
+
initializers.push(element);
|
|
100
94
|
}
|
|
101
95
|
else if (ts.isMethodDeclaration(element)) {
|
|
102
|
-
const expression = function_1.transformFunctionLikeDeclaration(element, context);
|
|
96
|
+
const expression = (0, function_1.transformFunctionLikeDeclaration)(element, context);
|
|
103
97
|
properties.push(lua.createTableFieldExpression(expression, name, element));
|
|
98
|
+
initializers.push(element);
|
|
104
99
|
}
|
|
105
|
-
else if (ts.isSpreadAssignment(element)
|
|
106
|
-
// Create a table for preceding properties to preserve property order
|
|
107
|
-
// { x: 0, ...{ y: 2 }, y: 1, z: 2 } --> __TS__ObjectAssign({x = 0}, {y = 2}, {y = 1, z = 2})
|
|
108
|
-
if (properties.length > 0) {
|
|
109
|
-
const tableExpression = lua.createTableExpression(properties, expression);
|
|
110
|
-
tableExpressions.push(tableExpression);
|
|
111
|
-
properties = [];
|
|
112
|
-
}
|
|
100
|
+
else if (ts.isSpreadAssignment(element)) {
|
|
113
101
|
const type = context.checker.getTypeAtLocation(element.expression);
|
|
114
102
|
let tableExpression;
|
|
115
|
-
if (typescript_1.isArrayType(context, type)) {
|
|
116
|
-
tableExpression = lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ArrayToObject, element.expression, context.transformExpression(element.expression));
|
|
103
|
+
if ((0, typescript_1.isArrayType)(context, type)) {
|
|
104
|
+
tableExpression = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayToObject, element.expression, context.transformExpression(element.expression));
|
|
117
105
|
}
|
|
118
106
|
else {
|
|
119
107
|
tableExpression = context.transformExpression(element.expression);
|
|
120
108
|
}
|
|
121
|
-
|
|
109
|
+
properties.push(tableExpression);
|
|
110
|
+
initializers.push(element.expression);
|
|
122
111
|
}
|
|
123
112
|
else if (ts.isAccessor(element)) {
|
|
124
|
-
context.diagnostics.push(diagnostics_1.unsupportedAccessorInObjectLiteral(element));
|
|
113
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedAccessorInObjectLiteral)(element));
|
|
125
114
|
}
|
|
126
115
|
else {
|
|
127
|
-
utils_1.assertNever(element);
|
|
116
|
+
(0, utils_1.assertNever)(element);
|
|
117
|
+
}
|
|
118
|
+
precedingStatements = context.popPrecedingStatements();
|
|
119
|
+
valuePrecedingStatements.push(precedingStatements);
|
|
120
|
+
if (precedingStatements.length > 0) {
|
|
121
|
+
lastPrecedingStatementsIndex = i;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Expressions referenced before others that produced preceding statements need to be cached in temps
|
|
125
|
+
if (lastPrecedingStatementsIndex >= 0) {
|
|
126
|
+
for (let i = 0; i < properties.length; ++i) {
|
|
127
|
+
const property = properties[i];
|
|
128
|
+
// Bubble up key's preceding statements
|
|
129
|
+
context.addPrecedingStatements(keyPrecedingStatements[i]);
|
|
130
|
+
// Cache computed property name in temp if before the last expression that generated preceding statements
|
|
131
|
+
if (i <= lastPrecedingStatementsIndex && lua.isTableFieldExpression(property) && property.key) {
|
|
132
|
+
property.key = (0, expression_list_1.moveToPrecedingTemp)(context, property.key, expression.properties[i].name);
|
|
133
|
+
}
|
|
134
|
+
// Bubble up value's preceding statements
|
|
135
|
+
context.addPrecedingStatements(valuePrecedingStatements[i]);
|
|
136
|
+
// Cache property value in temp if before the last expression that generated preceding statements
|
|
137
|
+
if (i < lastPrecedingStatementsIndex) {
|
|
138
|
+
if (lua.isTableFieldExpression(property)) {
|
|
139
|
+
property.value = (0, expression_list_1.moveToPrecedingTemp)(context, property.value, initializers[i]);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
properties[i] = (0, expression_list_1.moveToPrecedingTemp)(context, property, initializers[i]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Sort into field expressions and tables to pass into __TS__ObjectAssign
|
|
148
|
+
let fields = [];
|
|
149
|
+
const tableExpressions = [];
|
|
150
|
+
for (const property of properties) {
|
|
151
|
+
if (lua.isTableFieldExpression(property)) {
|
|
152
|
+
fields.push(property);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (fields.length > 0) {
|
|
156
|
+
tableExpressions.push(lua.createTableExpression(fields));
|
|
157
|
+
}
|
|
158
|
+
tableExpressions.push(property);
|
|
159
|
+
fields = [];
|
|
128
160
|
}
|
|
129
161
|
}
|
|
130
162
|
if (tableExpressions.length === 0) {
|
|
131
|
-
return lua.createTableExpression(
|
|
163
|
+
return lua.createTableExpression(fields, expression);
|
|
132
164
|
}
|
|
133
165
|
else {
|
|
134
|
-
if (
|
|
135
|
-
const tableExpression = lua.createTableExpression(
|
|
166
|
+
if (fields.length > 0) {
|
|
167
|
+
const tableExpression = lua.createTableExpression(fields, expression);
|
|
136
168
|
tableExpressions.push(tableExpression);
|
|
137
169
|
}
|
|
138
170
|
if (tableExpressions[0].kind !== lua.SyntaxKind.TableExpression) {
|
|
139
171
|
tableExpressions.unshift(lua.createTableExpression(undefined, expression));
|
|
140
172
|
}
|
|
141
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ObjectAssign, expression, ...tableExpressions);
|
|
173
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectAssign, expression, ...tableExpressions);
|
|
142
174
|
}
|
|
143
175
|
};
|
|
144
|
-
const transformObjectLiteralExpression = transformObjectLiteralExpressionOrJsxAttributes;
|
|
145
|
-
exports.transformJsxAttributes = transformObjectLiteralExpressionOrJsxAttributes;
|
|
146
176
|
const transformArrayLiteralExpression = (expression, context) => {
|
|
147
177
|
const filteredElements = expression.elements.map(e => ts.isOmittedExpression(e) ? ts.factory.createIdentifier("undefined") : e);
|
|
148
|
-
const values =
|
|
178
|
+
const values = (0, expression_list_1.transformExpressionList)(context, filteredElements).map(e => lua.createTableFieldExpression(e));
|
|
149
179
|
return lua.createTableExpression(values, expression);
|
|
150
180
|
};
|
|
151
181
|
exports.literalVisitors = {
|