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
|
@@ -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 = {
|
|
@@ -2,19 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformDoStatement = exports.transformWhileStatement = void 0;
|
|
4
4
|
const lua = require("../../../LuaAST");
|
|
5
|
+
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
|
-
const transformWhileStatement = (statement, context) =>
|
|
7
|
+
const transformWhileStatement = (statement, context) => {
|
|
8
|
+
const body = (0, utils_1.transformLoopBody)(context, statement);
|
|
9
|
+
let [conditionPrecedingStatements, condition] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(statement.expression));
|
|
10
|
+
// If condition has preceding statements, ensure they are executed every iteration by using the form:
|
|
11
|
+
//
|
|
12
|
+
// while true do
|
|
13
|
+
// condition's preceding statements
|
|
14
|
+
// if not condition then
|
|
15
|
+
// break
|
|
16
|
+
// end
|
|
17
|
+
// ...
|
|
18
|
+
// end
|
|
19
|
+
if (conditionPrecedingStatements.length > 0) {
|
|
20
|
+
conditionPrecedingStatements.push(lua.createIfStatement((0, utils_1.invertCondition)(condition), lua.createBlock([lua.createBreakStatement()]), undefined, statement.expression));
|
|
21
|
+
body.unshift(...conditionPrecedingStatements);
|
|
22
|
+
condition = lua.createBooleanLiteral(true);
|
|
23
|
+
}
|
|
24
|
+
return lua.createWhileStatement(lua.createBlock(body), condition, statement);
|
|
25
|
+
};
|
|
7
26
|
exports.transformWhileStatement = transformWhileStatement;
|
|
8
27
|
const transformDoStatement = (statement, context) => {
|
|
9
|
-
const body = lua.createDoStatement(utils_1.transformLoopBody(context, statement));
|
|
10
|
-
let condition = context.transformExpression(statement.expression);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
const body = lua.createDoStatement((0, utils_1.transformLoopBody)(context, statement));
|
|
29
|
+
let [conditionPrecedingStatements, condition] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, utils_1.invertCondition)(context.transformExpression(statement.expression)));
|
|
30
|
+
// If condition has preceding statements, ensure they are executed every iteration by using the form:
|
|
31
|
+
//
|
|
32
|
+
// repeat
|
|
33
|
+
// ...
|
|
34
|
+
// condition's preceding statements
|
|
35
|
+
// if condition then
|
|
36
|
+
// break
|
|
37
|
+
// end
|
|
38
|
+
// end
|
|
39
|
+
if (conditionPrecedingStatements.length > 0) {
|
|
40
|
+
conditionPrecedingStatements.push(lua.createIfStatement(condition, lua.createBlock([lua.createBreakStatement()]), undefined, statement.expression));
|
|
41
|
+
condition = lua.createBooleanLiteral(false);
|
|
16
42
|
}
|
|
17
|
-
return lua.createRepeatStatement(lua.createBlock([body]), condition, statement);
|
|
43
|
+
return lua.createRepeatStatement(lua.createBlock([body, ...conditionPrecedingStatements]), condition, statement);
|
|
18
44
|
};
|
|
19
45
|
exports.transformDoStatement = transformDoStatement;
|
|
20
46
|
//# sourceMappingURL=do-while.js.map
|
|
@@ -6,15 +6,15 @@ const diagnostics_1 = require("../../utils/diagnostics");
|
|
|
6
6
|
const typescript_1 = require("../../utils/typescript");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const transformForInStatement = (statement, context) => {
|
|
9
|
-
if (typescript_1.isArrayType(context, context.checker.getTypeAtLocation(statement.expression))) {
|
|
10
|
-
context.diagnostics.push(diagnostics_1.forbiddenForIn(statement));
|
|
9
|
+
if ((0, typescript_1.isArrayType)(context, context.checker.getTypeAtLocation(statement.expression))) {
|
|
10
|
+
context.diagnostics.push((0, diagnostics_1.forbiddenForIn)(statement));
|
|
11
11
|
}
|
|
12
12
|
// Transpile expression
|
|
13
13
|
const pairsIdentifier = lua.createIdentifier("pairs");
|
|
14
14
|
const expression = context.transformExpression(statement.expression);
|
|
15
15
|
const pairsCall = lua.createCallExpression(pairsIdentifier, [expression]);
|
|
16
|
-
const body = lua.createBlock(utils_1.transformLoopBody(context, statement));
|
|
17
|
-
const valueVariable = utils_1.transformForInitializer(context, statement.initializer, body);
|
|
16
|
+
const body = lua.createBlock((0, utils_1.transformLoopBody)(context, statement));
|
|
17
|
+
const valueVariable = (0, utils_1.transformForInitializer)(context, statement.initializer, body);
|
|
18
18
|
return lua.createForInStatement(body, [valueVariable], [pairsCall], statement);
|
|
19
19
|
};
|
|
20
20
|
exports.transformForInStatement = transformForInStatement;
|
|
@@ -11,32 +11,32 @@ const iterable_1 = require("../language-extensions/iterable");
|
|
|
11
11
|
const range_1 = require("../language-extensions/range");
|
|
12
12
|
const utils_1 = require("./utils");
|
|
13
13
|
function transformForOfArrayStatement(context, statement, block) {
|
|
14
|
-
const valueVariable = utils_1.transformForInitializer(context, statement.initializer, block);
|
|
14
|
+
const valueVariable = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
15
15
|
const ipairsCall = lua.createCallExpression(lua.createIdentifier("ipairs"), [
|
|
16
16
|
context.transformExpression(statement.expression),
|
|
17
17
|
]);
|
|
18
18
|
return lua.createForInStatement(block, [lua.createAnonymousIdentifier(), valueVariable], [ipairsCall], statement);
|
|
19
19
|
}
|
|
20
20
|
function transformForOfIteratorStatement(context, statement, block) {
|
|
21
|
-
const valueVariable = utils_1.transformForInitializer(context, statement.initializer, block);
|
|
22
|
-
const iterable = lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.Iterator, statement.expression, context.transformExpression(statement.expression));
|
|
21
|
+
const valueVariable = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
22
|
+
const iterable = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Iterator, statement.expression, context.transformExpression(statement.expression));
|
|
23
23
|
return lua.createForInStatement(block, [lua.createAnonymousIdentifier(), valueVariable], [iterable], statement);
|
|
24
24
|
}
|
|
25
25
|
const transformForOfStatement = (node, context) => {
|
|
26
|
-
const body = lua.createBlock(utils_1.transformLoopBody(context, node));
|
|
27
|
-
if (ts.isCallExpression(node.expression) && range_1.isRangeFunction(context, node.expression)) {
|
|
28
|
-
return range_1.transformRangeStatement(context, node, body);
|
|
26
|
+
const body = lua.createBlock((0, utils_1.transformLoopBody)(context, node));
|
|
27
|
+
if (ts.isCallExpression(node.expression) && (0, range_1.isRangeFunction)(context, node.expression)) {
|
|
28
|
+
return (0, range_1.transformRangeStatement)(context, node, body);
|
|
29
29
|
}
|
|
30
|
-
else if (ts.isCallExpression(node.expression) && annotations_1.isForRangeType(context, node.expression.expression)) {
|
|
31
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node.expression, annotations_1.AnnotationKind.ForRange));
|
|
30
|
+
else if (ts.isCallExpression(node.expression) && (0, annotations_1.isForRangeType)(context, node.expression.expression)) {
|
|
31
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node.expression, annotations_1.AnnotationKind.ForRange));
|
|
32
32
|
}
|
|
33
|
-
else if (iterable_1.isIterableExpression(context, node.expression)) {
|
|
34
|
-
return iterable_1.transformForOfIterableStatement(context, node, body);
|
|
33
|
+
else if ((0, iterable_1.isIterableExpression)(context, node.expression)) {
|
|
34
|
+
return (0, iterable_1.transformForOfIterableStatement)(context, node, body);
|
|
35
35
|
}
|
|
36
|
-
else if (annotations_1.isLuaIteratorType(context, node.expression)) {
|
|
37
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node.expression, annotations_1.AnnotationKind.LuaIterator));
|
|
36
|
+
else if ((0, annotations_1.isLuaIteratorType)(context, node.expression)) {
|
|
37
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node.expression, annotations_1.AnnotationKind.LuaIterator));
|
|
38
38
|
}
|
|
39
|
-
else if (typescript_1.isArrayType(context, context.checker.getTypeAtLocation(node.expression))) {
|
|
39
|
+
else if ((0, typescript_1.isArrayType)(context, context.checker.getTypeAtLocation(node.expression))) {
|
|
40
40
|
return transformForOfArrayStatement(context, node, body);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
@@ -3,30 +3,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformForStatement = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
|
+
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
6
7
|
const variable_declaration_1 = require("../variable-declaration");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
const transformForStatement = (statement, context) => {
|
|
9
10
|
const result = [];
|
|
10
11
|
if (statement.initializer) {
|
|
11
12
|
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
12
|
-
variable_declaration_1.checkVariableDeclarationList(context, statement.initializer);
|
|
13
|
+
(0, variable_declaration_1.checkVariableDeclarationList)(context, statement.initializer);
|
|
13
14
|
// local initializer = value
|
|
14
|
-
result.push(...statement.initializer.declarations.flatMap(d => variable_declaration_1.transformVariableDeclaration(context, d)));
|
|
15
|
+
result.push(...statement.initializer.declarations.flatMap(d => (0, variable_declaration_1.transformVariableDeclaration)(context, d)));
|
|
15
16
|
}
|
|
16
17
|
else {
|
|
17
18
|
result.push(...context.transformStatements(ts.factory.createExpressionStatement(statement.initializer)));
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const body = (0, utils_1.transformLoopBody)(context, statement);
|
|
22
|
+
let condition;
|
|
23
|
+
if (statement.condition) {
|
|
24
|
+
let conditionPrecedingStatements;
|
|
25
|
+
const tsCondition = statement.condition;
|
|
26
|
+
[conditionPrecedingStatements, condition] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(tsCondition));
|
|
27
|
+
// If condition has preceding statements, ensure they are executed every iteration by using the form:
|
|
28
|
+
//
|
|
29
|
+
// while true do
|
|
30
|
+
// condition's preceding statements
|
|
31
|
+
// if not condition then
|
|
32
|
+
// break
|
|
33
|
+
// end
|
|
34
|
+
// ...
|
|
35
|
+
// end
|
|
36
|
+
if (conditionPrecedingStatements.length > 0) {
|
|
37
|
+
conditionPrecedingStatements.push(lua.createIfStatement((0, utils_1.invertCondition)(condition), lua.createBlock([lua.createBreakStatement()]), undefined, statement.condition));
|
|
38
|
+
body.unshift(...conditionPrecedingStatements);
|
|
39
|
+
condition = lua.createBooleanLiteral(true);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
condition = lua.createBooleanLiteral(true);
|
|
44
|
+
}
|
|
25
45
|
if (statement.incrementor) {
|
|
26
46
|
body.push(...context.transformStatements(ts.factory.createExpressionStatement(statement.incrementor)));
|
|
27
47
|
}
|
|
28
48
|
// while (condition) do ... end
|
|
29
|
-
result.push(lua.createWhileStatement(lua.createBlock(body), condition));
|
|
49
|
+
result.push(lua.createWhileStatement(lua.createBlock(body), condition, statement));
|
|
30
50
|
return lua.createDoStatement(result, statement);
|
|
31
51
|
};
|
|
32
52
|
exports.transformForStatement = transformForStatement;
|
|
@@ -4,3 +4,4 @@ import { TransformationContext } from "../../context";
|
|
|
4
4
|
export declare function transformLoopBody(context: TransformationContext, loop: ts.WhileStatement | ts.DoStatement | ts.ForStatement | ts.ForOfStatement | ts.ForInOrOfStatement): lua.Statement[];
|
|
5
5
|
export declare function getVariableDeclarationBinding(context: TransformationContext, node: ts.VariableDeclarationList): ts.BindingName;
|
|
6
6
|
export declare function transformForInitializer(context: TransformationContext, initializer: ts.ForInitializer, block: lua.Block): lua.Identifier;
|
|
7
|
+
export declare function invertCondition(expression: lua.Expression): lua.Expression;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformForInitializer = exports.getVariableDeclarationBinding = exports.transformLoopBody = void 0;
|
|
3
|
+
exports.invertCondition = exports.transformForInitializer = exports.getVariableDeclarationBinding = exports.transformLoopBody = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
6
|
const scope_1 = require("../../utils/scope");
|
|
@@ -11,9 +11,9 @@ const block_1 = require("../block");
|
|
|
11
11
|
const identifier_1 = require("../identifier");
|
|
12
12
|
const variable_declaration_1 = require("../variable-declaration");
|
|
13
13
|
function transformLoopBody(context, loop) {
|
|
14
|
-
scope_1.pushScope(context, scope_1.ScopeType.Loop);
|
|
15
|
-
const body = scope_1.performHoisting(context, block_1.transformBlockOrStatement(context, loop.statement));
|
|
16
|
-
const scope = scope_1.popScope(context);
|
|
14
|
+
(0, scope_1.pushScope)(context, scope_1.ScopeType.Loop);
|
|
15
|
+
const body = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, loop.statement));
|
|
16
|
+
const scope = (0, scope_1.popScope)(context);
|
|
17
17
|
const scopeId = scope.id;
|
|
18
18
|
if (!scope.loopContinued) {
|
|
19
19
|
return body;
|
|
@@ -25,7 +25,7 @@ function transformLoopBody(context, loop) {
|
|
|
25
25
|
}
|
|
26
26
|
exports.transformLoopBody = transformLoopBody;
|
|
27
27
|
function getVariableDeclarationBinding(context, node) {
|
|
28
|
-
variable_declaration_1.checkVariableDeclarationList(context, node);
|
|
28
|
+
(0, variable_declaration_1.checkVariableDeclarationList)(context, node);
|
|
29
29
|
if (node.declarations.length === 0) {
|
|
30
30
|
return ts.factory.createIdentifier("____");
|
|
31
31
|
}
|
|
@@ -38,20 +38,31 @@ function transformForInitializer(context, initializer, block) {
|
|
|
38
38
|
// Declaration of new variable
|
|
39
39
|
const binding = getVariableDeclarationBinding(context, initializer);
|
|
40
40
|
if (ts.isArrayBindingPattern(binding) || ts.isObjectBindingPattern(binding)) {
|
|
41
|
-
block.statements.unshift(...variable_declaration_1.transformBindingPattern(context, binding, valueVariable));
|
|
41
|
+
block.statements.unshift(...(0, variable_declaration_1.transformBindingPattern)(context, binding, valueVariable));
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
// Single variable declared in for loop
|
|
45
|
-
return identifier_1.transformIdentifier(context, binding);
|
|
45
|
+
return (0, identifier_1.transformIdentifier)(context, binding);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
// Assignment to existing variable(s)
|
|
50
|
-
block.statements.unshift(...(typescript_1.isAssignmentPattern(initializer)
|
|
51
|
-
? destructuring_assignments_1.transformAssignmentPattern(context, initializer, valueVariable)
|
|
52
|
-
: assignments_1.transformAssignment(context, initializer, valueVariable)));
|
|
50
|
+
block.statements.unshift(...((0, typescript_1.isAssignmentPattern)(initializer)
|
|
51
|
+
? (0, destructuring_assignments_1.transformAssignmentPattern)(context, initializer, valueVariable, false)
|
|
52
|
+
: (0, assignments_1.transformAssignment)(context, initializer, valueVariable)));
|
|
53
53
|
}
|
|
54
54
|
return valueVariable;
|
|
55
55
|
}
|
|
56
56
|
exports.transformForInitializer = transformForInitializer;
|
|
57
|
+
function invertCondition(expression) {
|
|
58
|
+
if (lua.isUnaryExpression(expression) && expression.operator === lua.SyntaxKind.NotOperator) {
|
|
59
|
+
return expression.operand;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const notExpression = lua.createUnaryExpression(expression, lua.SyntaxKind.NotOperator);
|
|
63
|
+
lua.setNodePosition(notExpression, lua.getOriginalPos(expression));
|
|
64
|
+
return notExpression;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.invertCondition = invertCondition;
|
|
57
68
|
//# sourceMappingURL=utils.js.map
|
|
@@ -19,25 +19,25 @@ const transformExportAssignment = (node, context) => {
|
|
|
19
19
|
// export = [expression];
|
|
20
20
|
// ____exports = [expression];
|
|
21
21
|
if (node.isExportEquals) {
|
|
22
|
-
return lua.createVariableDeclarationStatement(lua_ast_1.createExportsIdentifier(), exportedValue, node);
|
|
22
|
+
return lua.createVariableDeclarationStatement((0, lua_ast_1.createExportsIdentifier)(), exportedValue, node);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
// export default [expression];
|
|
26
26
|
// ____exports.default = [expression];
|
|
27
|
-
return lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createExportsIdentifier(), export_1.createDefaultExportStringLiteral(node)), exportedValue, node);
|
|
27
|
+
return lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, export_1.createDefaultExportStringLiteral)(node)), exportedValue, node);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
exports.transformExportAssignment = transformExportAssignment;
|
|
31
31
|
function transformExportAll(context, node) {
|
|
32
|
-
utils_1.assert(node.moduleSpecifier);
|
|
32
|
+
(0, utils_1.assert)(node.moduleSpecifier);
|
|
33
33
|
if (!context.resolver.moduleExportsSomeValue(node.moduleSpecifier)) {
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
|
-
const moduleRequire = import_1.createModuleRequire(context, node.moduleSpecifier);
|
|
36
|
+
const moduleRequire = (0, import_1.createModuleRequire)(context, node.moduleSpecifier);
|
|
37
37
|
// export * as ns from "...";
|
|
38
38
|
// exports.ns = require(...)
|
|
39
39
|
if (node.exportClause && ts.isNamespaceExport(node.exportClause)) {
|
|
40
|
-
const assignToExports = lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createExportsIdentifier(), lua.createStringLiteral(node.exportClause.name.text)), moduleRequire);
|
|
40
|
+
const assignToExports = lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), lua.createStringLiteral(node.exportClause.name.text)), moduleRequire);
|
|
41
41
|
return assignToExports;
|
|
42
42
|
}
|
|
43
43
|
// export * from "...";
|
|
@@ -50,7 +50,7 @@ function transformExportAll(context, node) {
|
|
|
50
50
|
// ____exports[____exportKey] = ____exportValue
|
|
51
51
|
const forKey = lua.createIdentifier("____exportKey");
|
|
52
52
|
const forValue = lua.createIdentifier("____exportValue");
|
|
53
|
-
const leftAssignment = lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createExportsIdentifier(), forKey), forValue);
|
|
53
|
+
const leftAssignment = lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), forKey), forValue);
|
|
54
54
|
// if key ~= "default" then
|
|
55
55
|
// -- export the value, do not export "default" values
|
|
56
56
|
// end
|
|
@@ -70,24 +70,23 @@ const isDefaultExportSpecifier = (node) => (node.name && node.name.originalKeywo
|
|
|
70
70
|
function transformExportSpecifier(context, node) {
|
|
71
71
|
const exportedSymbol = context.checker.getExportSpecifierLocalTargetSymbol(node);
|
|
72
72
|
const exportedIdentifier = node.propertyName ? node.propertyName : node.name;
|
|
73
|
-
const exportedExpression = literal_1.createShorthandIdentifier(context, exportedSymbol, exportedIdentifier);
|
|
73
|
+
const exportedExpression = (0, literal_1.createShorthandIdentifier)(context, exportedSymbol, exportedIdentifier);
|
|
74
74
|
const isDefault = isDefaultExportSpecifier(node);
|
|
75
|
-
const
|
|
76
|
-
? export_1.
|
|
77
|
-
: identifier_1.transformIdentifier(context, node.name);
|
|
78
|
-
const exportAssignmentLeftHandSide = export_1.createExportedIdentifier(context, identifierToExport);
|
|
75
|
+
const exportAssignmentLeftHandSide = isDefault
|
|
76
|
+
? (0, export_1.createDefaultExportExpression)(node)
|
|
77
|
+
: (0, export_1.createExportedIdentifier)(context, (0, identifier_1.transformIdentifier)(context, node.name));
|
|
79
78
|
return lua.createAssignmentStatement(exportAssignmentLeftHandSide, exportedExpression, node);
|
|
80
79
|
}
|
|
81
80
|
function transformExportSpecifiersFrom(context, statement, moduleSpecifier, exportSpecifiers) {
|
|
82
81
|
// First transpile as import clause
|
|
83
|
-
const importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(exportSpecifiers.map(s => ts.factory.createImportSpecifier(s.propertyName, s.name))));
|
|
82
|
+
const importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(exportSpecifiers.map(s => ts.factory.createImportSpecifier(statement.isTypeOnly, s.propertyName, s.name))));
|
|
84
83
|
const importDeclaration = ts.factory.createImportDeclaration(statement.decorators, statement.modifiers, importClause, moduleSpecifier);
|
|
85
84
|
// Wrap in block to prevent imports from hoisting out of `do` statement
|
|
86
|
-
const [block] = block_1.transformScopeBlock(context, ts.factory.createBlock([importDeclaration]), scope_1.ScopeType.Block);
|
|
85
|
+
const [block] = (0, block_1.transformScopeBlock)(context, ts.factory.createBlock([importDeclaration]), scope_1.ScopeType.Block);
|
|
87
86
|
const result = block.statements;
|
|
88
87
|
// Now the module is imported, add the imports to the export table
|
|
89
88
|
for (const specifier of exportSpecifiers) {
|
|
90
|
-
result.push(lua.createAssignmentStatement(export_1.createExportedIdentifier(context, identifier_1.transformIdentifier(context, specifier.name)), identifier_1.transformIdentifier(context, specifier.name)));
|
|
89
|
+
result.push(lua.createAssignmentStatement((0, export_1.createExportedIdentifier)(context, (0, identifier_1.transformIdentifier)(context, specifier.name)), (0, identifier_1.transformIdentifier)(context, specifier.name)));
|
|
91
90
|
}
|
|
92
91
|
// Wrap this in a DoStatement to prevent polluting the scope.
|
|
93
92
|
return lua.createDoStatement(result, statement);
|
|
@@ -106,7 +105,7 @@ const transformExportDeclaration = (node, context) => {
|
|
|
106
105
|
// export * as ns from "...";
|
|
107
106
|
return transformExportAll(context, node);
|
|
108
107
|
}
|
|
109
|
-
const exportSpecifiers = exports.getExported(context, node.exportClause);
|
|
108
|
+
const exportSpecifiers = (0, exports.getExported)(context, node.exportClause);
|
|
110
109
|
// export { ... };
|
|
111
110
|
if (!node.moduleSpecifier) {
|
|
112
111
|
return exportSpecifiers.map(exportSpecifier => transformExportSpecifier(context, exportSpecifier));
|
|
@@ -15,7 +15,7 @@ function isNoResolutionPath(context, moduleSpecifier) {
|
|
|
15
15
|
const moduleOwnerSymbol = context.checker.getSymbolAtLocation(moduleSpecifier);
|
|
16
16
|
if (!moduleOwnerSymbol)
|
|
17
17
|
return false;
|
|
18
|
-
const annotations = annotations_1.getSymbolAnnotations(moduleOwnerSymbol);
|
|
18
|
+
const annotations = (0, annotations_1.getSymbolAnnotations)(moduleOwnerSymbol);
|
|
19
19
|
return annotations.has(annotations_1.AnnotationKind.NoResolution);
|
|
20
20
|
}
|
|
21
21
|
function createModuleRequire(context, moduleSpecifier, tsOriginal = moduleSpecifier) {
|
|
@@ -33,12 +33,12 @@ function shouldBeImported(context, importNode) {
|
|
|
33
33
|
return context.resolver.isReferencedAliasDeclaration(importNode);
|
|
34
34
|
}
|
|
35
35
|
function transformImportSpecifier(context, importSpecifier, moduleTableName) {
|
|
36
|
-
const leftIdentifier = identifier_1.transformIdentifier(context, importSpecifier.name);
|
|
37
|
-
const propertyName = literal_1.transformPropertyName(context, importSpecifier.propertyName ? importSpecifier.propertyName : importSpecifier.name);
|
|
36
|
+
const leftIdentifier = (0, identifier_1.transformIdentifier)(context, importSpecifier.name);
|
|
37
|
+
const propertyName = (0, literal_1.transformPropertyName)(context, importSpecifier.propertyName ? importSpecifier.propertyName : importSpecifier.name);
|
|
38
38
|
return lua.createVariableDeclarationStatement(leftIdentifier, lua.createTableIndexExpression(moduleTableName, propertyName), importSpecifier);
|
|
39
39
|
}
|
|
40
40
|
const transformImportDeclaration = (statement, context) => {
|
|
41
|
-
const scope = scope_1.peekScope(context);
|
|
41
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
42
42
|
if (!scope.importStatements) {
|
|
43
43
|
scope.importStatements = [];
|
|
44
44
|
}
|
|
@@ -61,14 +61,14 @@ const transformImportDeclaration = (statement, context) => {
|
|
|
61
61
|
: "module";
|
|
62
62
|
// Create the require statement to extract values.
|
|
63
63
|
// local ____module = require("module")
|
|
64
|
-
const importUniqueName = lua.createIdentifier(safe_names_1.createSafeName(path.basename(importPath)));
|
|
64
|
+
const importUniqueName = lua.createIdentifier((0, safe_names_1.createSafeName)(path.basename(importPath)));
|
|
65
65
|
let usingRequireStatement = false;
|
|
66
66
|
// import defaultValue from "./module";
|
|
67
67
|
// local defaultValue = __module.default
|
|
68
68
|
if (statement.importClause.name) {
|
|
69
69
|
if (shouldBeImported(context, statement.importClause)) {
|
|
70
|
-
const propertyName = export_1.createDefaultExportStringLiteral(statement.importClause.name);
|
|
71
|
-
const defaultImportAssignmentStatement = lua.createVariableDeclarationStatement(identifier_1.transformIdentifier(context, statement.importClause.name), lua.createTableIndexExpression(importUniqueName, propertyName), statement.importClause.name);
|
|
70
|
+
const propertyName = (0, export_1.createDefaultExportStringLiteral)(statement.importClause.name);
|
|
71
|
+
const defaultImportAssignmentStatement = lua.createVariableDeclarationStatement((0, identifier_1.transformIdentifier)(context, statement.importClause.name), lua.createTableIndexExpression(importUniqueName, propertyName), statement.importClause.name);
|
|
72
72
|
result.push(defaultImportAssignmentStatement);
|
|
73
73
|
usingRequireStatement = true;
|
|
74
74
|
}
|
|
@@ -77,7 +77,7 @@ const transformImportDeclaration = (statement, context) => {
|
|
|
77
77
|
// local module = require("module")
|
|
78
78
|
if (statement.importClause.namedBindings && ts.isNamespaceImport(statement.importClause.namedBindings)) {
|
|
79
79
|
if (context.resolver.isReferencedAliasDeclaration(statement.importClause.namedBindings)) {
|
|
80
|
-
const requireStatement = lua.createVariableDeclarationStatement(identifier_1.transformIdentifier(context, statement.importClause.namedBindings.name), requireCall, statement);
|
|
80
|
+
const requireStatement = lua.createVariableDeclarationStatement((0, identifier_1.transformIdentifier)(context, statement.importClause.namedBindings.name), requireCall, statement);
|
|
81
81
|
result.push(requireStatement);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -118,9 +118,9 @@ const transformImportEqualsDeclaration = (node, context) => {
|
|
|
118
118
|
!context.resolver.isTopLevelValueImportEqualsWithEntityName(node))) {
|
|
119
119
|
return undefined;
|
|
120
120
|
}
|
|
121
|
-
const name = identifier_1.transformIdentifier(context, node.name);
|
|
121
|
+
const name = (0, identifier_1.transformIdentifier)(context, node.name);
|
|
122
122
|
const expression = context.transformExpression(node.moduleReference);
|
|
123
|
-
return lua_ast_1.createHoistableVariableDeclarationStatement(context, name, expression, node);
|
|
123
|
+
return (0, lua_ast_1.createHoistableVariableDeclarationStatement)(context, name, expression, node);
|
|
124
124
|
};
|
|
125
125
|
exports.transformImportEqualsDeclaration = transformImportEqualsDeclaration;
|
|
126
126
|
//# sourceMappingURL=import.js.map
|