typescript-to-lua 1.0.1 → 1.1.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 +18 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +1 -0
- package/dist/LuaLib.js +1 -0
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/Await.lua +26 -10
- package/dist/lualib/Promise.lua +20 -6
- package/dist/lualib/SourceMapTraceBack.lua +18 -8
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/lualib_bundle.lua +106 -35
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +33 -33
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- 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.js +4 -4
- package/dist/transformation/utils/export.js +4 -4
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +16 -16
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +21 -21
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +2 -2
- package/dist/transformation/visitors/call.js +35 -35
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +34 -34
- 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 +12 -12
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -30
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +26 -26
- package/dist/transformation/visitors/identifier.js +22 -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 +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- 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 +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -13
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +11 -11
- package/dist/transformation/visitors/switch.js +34 -11
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -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 +28 -28
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -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 +19 -12
- package/dist/transpilation/transformers.js +41 -24
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- 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
|
@@ -51,27 +51,27 @@ const luaBuiltins = new Set([
|
|
|
51
51
|
"type",
|
|
52
52
|
"unpack",
|
|
53
53
|
]);
|
|
54
|
-
const isUnsafeName = (name) => !exports.isValidLuaIdentifier(name) || luaBuiltins.has(name);
|
|
54
|
+
const isUnsafeName = (name) => !(0, exports.isValidLuaIdentifier)(name) || luaBuiltins.has(name);
|
|
55
55
|
exports.isUnsafeName = isUnsafeName;
|
|
56
56
|
function checkName(context, name, node) {
|
|
57
|
-
const isInvalid = !exports.isValidLuaIdentifier(name);
|
|
57
|
+
const isInvalid = !(0, exports.isValidLuaIdentifier)(name);
|
|
58
58
|
if (isInvalid) {
|
|
59
59
|
// Empty identifier is a TypeScript error
|
|
60
60
|
if (name !== "") {
|
|
61
|
-
context.diagnostics.push(diagnostics_1.invalidAmbientIdentifierName(node, name));
|
|
61
|
+
context.diagnostics.push((0, diagnostics_1.invalidAmbientIdentifierName)(node, name));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
return isInvalid;
|
|
65
65
|
}
|
|
66
66
|
function hasUnsafeSymbolName(context, symbol, tsOriginal) {
|
|
67
67
|
var _a, _b;
|
|
68
|
-
const isAmbient = (_b = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => typescript_1.isAmbientNode(d))) !== null && _b !== void 0 ? _b : false;
|
|
68
|
+
const isAmbient = (_b = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => (0, typescript_1.isAmbientNode)(d))) !== null && _b !== void 0 ? _b : false;
|
|
69
69
|
// Catch ambient declarations of identifiers with bad names
|
|
70
70
|
if (isAmbient && checkName(context, symbol.name, tsOriginal)) {
|
|
71
71
|
return true;
|
|
72
72
|
}
|
|
73
73
|
// only unsafe when non-ambient and not exported
|
|
74
|
-
return exports.isUnsafeName(symbol.name) && !isAmbient && !export_1.isSymbolExported(context, symbol);
|
|
74
|
+
return (0, exports.isUnsafeName)(symbol.name) && !isAmbient && !(0, export_1.isSymbolExported)(context, symbol);
|
|
75
75
|
}
|
|
76
76
|
exports.hasUnsafeSymbolName = hasUnsafeSymbolName;
|
|
77
77
|
function hasUnsafeIdentifierName(context, identifier, checkSymbol = true) {
|
|
@@ -26,6 +26,11 @@ export interface Scope {
|
|
|
26
26
|
loopContinued?: boolean;
|
|
27
27
|
functionReturned?: boolean;
|
|
28
28
|
}
|
|
29
|
+
export interface HoistingResult {
|
|
30
|
+
statements: lua.Statement[];
|
|
31
|
+
hoistedStatements: lua.Statement[];
|
|
32
|
+
hoistedIdentifiers: lua.Identifier[];
|
|
33
|
+
}
|
|
29
34
|
export declare function walkScopesUp(context: TransformationContext): IterableIterator<Scope>;
|
|
30
35
|
export declare function markSymbolAsReferencedInCurrentScopes(context: TransformationContext, symbolId: lua.SymbolId, identifier: ts.Identifier): void;
|
|
31
36
|
export declare function peekScope(context: TransformationContext): Scope;
|
|
@@ -37,5 +42,6 @@ export declare function hasReferencedSymbol(context: TransformationContext, scop
|
|
|
37
42
|
export declare function isFunctionScopeWithDefinition(scope: Scope): scope is Scope & {
|
|
38
43
|
node: ts.SignatureDeclaration;
|
|
39
44
|
};
|
|
45
|
+
export declare function separateHoistedStatements(context: TransformationContext, statements: lua.Statement[]): HoistingResult;
|
|
40
46
|
export declare function performHoisting(context: TransformationContext, statements: lua.Statement[]): lua.Statement[];
|
|
41
47
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.performHoisting = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.popScope = exports.pushScope = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.ScopeType = void 0;
|
|
3
|
+
exports.performHoisting = exports.separateHoistedStatements = exports.isFunctionScopeWithDefinition = exports.hasReferencedSymbol = exports.hasReferencedUndefinedLocalFunction = exports.popScope = exports.pushScope = exports.findScope = exports.peekScope = exports.markSymbolAsReferencedInCurrentScopes = exports.walkScopesUp = exports.ScopeType = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
@@ -19,7 +19,7 @@ var ScopeType;
|
|
|
19
19
|
})(ScopeType = exports.ScopeType || (exports.ScopeType = {}));
|
|
20
20
|
const scopeStacks = new WeakMap();
|
|
21
21
|
function getScopeStack(context) {
|
|
22
|
-
return utils_1.getOrUpdate(scopeStacks, context, () => []);
|
|
22
|
+
return (0, utils_1.getOrUpdate)(scopeStacks, context, () => []);
|
|
23
23
|
}
|
|
24
24
|
function* walkScopesUp(context) {
|
|
25
25
|
const scopeStack = getScopeStack(context);
|
|
@@ -34,7 +34,7 @@ function markSymbolAsReferencedInCurrentScopes(context, symbolId, identifier) {
|
|
|
34
34
|
if (!scope.referencedSymbols) {
|
|
35
35
|
scope.referencedSymbols = new Map();
|
|
36
36
|
}
|
|
37
|
-
const references = utils_1.getOrUpdate(scope.referencedSymbols, symbolId, () => []);
|
|
37
|
+
const references = (0, utils_1.getOrUpdate)(scope.referencedSymbols, symbolId, () => []);
|
|
38
38
|
references.push(identifier);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -42,7 +42,7 @@ exports.markSymbolAsReferencedInCurrentScopes = markSymbolAsReferencedInCurrentS
|
|
|
42
42
|
function peekScope(context) {
|
|
43
43
|
const scopeStack = getScopeStack(context);
|
|
44
44
|
const scope = scopeStack[scopeStack.length - 1];
|
|
45
|
-
utils_1.assert(scope);
|
|
45
|
+
(0, utils_1.assert)(scope);
|
|
46
46
|
return scope;
|
|
47
47
|
}
|
|
48
48
|
exports.peekScope = peekScope;
|
|
@@ -64,13 +64,13 @@ exports.pushScope = pushScope;
|
|
|
64
64
|
function popScope(context) {
|
|
65
65
|
const scopeStack = getScopeStack(context);
|
|
66
66
|
const scope = scopeStack.pop();
|
|
67
|
-
utils_1.assert(scope);
|
|
67
|
+
(0, utils_1.assert)(scope);
|
|
68
68
|
return scope;
|
|
69
69
|
}
|
|
70
70
|
exports.popScope = popScope;
|
|
71
71
|
function isHoistableFunctionDeclaredInScope(symbol, scopeNode) {
|
|
72
72
|
var _a;
|
|
73
|
-
return (_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => ts.isFunctionDeclaration(d) && typescript_1.findFirstNodeAbove(d, (n) => n === scopeNode));
|
|
73
|
+
return (_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(d => ts.isFunctionDeclaration(d) && (0, typescript_1.findFirstNodeAbove)(d, (n) => n === scopeNode));
|
|
74
74
|
}
|
|
75
75
|
// Checks for references to local functions which haven't been defined yet,
|
|
76
76
|
// and thus will be hoisted above the current position.
|
|
@@ -106,21 +106,43 @@ function isFunctionScopeWithDefinition(scope) {
|
|
|
106
106
|
return scope.node !== undefined && ts.isFunctionLike(scope.node);
|
|
107
107
|
}
|
|
108
108
|
exports.isFunctionScopeWithDefinition = isFunctionScopeWithDefinition;
|
|
109
|
-
function
|
|
109
|
+
function separateHoistedStatements(context, statements) {
|
|
110
110
|
const scope = peekScope(context);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
const allHoistedStatments = [];
|
|
112
|
+
const allHoistedIdentifiers = [];
|
|
113
|
+
let { unhoistedStatements, hoistedStatements, hoistedIdentifiers } = hoistFunctionDefinitions(context, scope, statements);
|
|
114
|
+
allHoistedStatments.push(...hoistedStatements);
|
|
115
|
+
allHoistedIdentifiers.push(...hoistedIdentifiers);
|
|
116
|
+
({ unhoistedStatements, hoistedIdentifiers } = hoistVariableDeclarations(context, scope, unhoistedStatements));
|
|
117
|
+
allHoistedIdentifiers.push(...hoistedIdentifiers);
|
|
118
|
+
({ unhoistedStatements, hoistedStatements } = hoistImportStatements(scope, unhoistedStatements));
|
|
119
|
+
allHoistedStatments.unshift(...hoistedStatements);
|
|
120
|
+
return {
|
|
121
|
+
statements: unhoistedStatements,
|
|
122
|
+
hoistedStatements: allHoistedStatments,
|
|
123
|
+
hoistedIdentifiers: allHoistedIdentifiers,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
exports.separateHoistedStatements = separateHoistedStatements;
|
|
127
|
+
function performHoisting(context, statements) {
|
|
128
|
+
const result = separateHoistedStatements(context, statements);
|
|
129
|
+
const modifiedStatements = [...result.hoistedStatements, ...result.statements];
|
|
130
|
+
if (result.hoistedIdentifiers.length > 0) {
|
|
131
|
+
modifiedStatements.unshift(lua.createVariableDeclarationStatement(result.hoistedIdentifiers));
|
|
132
|
+
}
|
|
133
|
+
return modifiedStatements;
|
|
116
134
|
}
|
|
117
135
|
exports.performHoisting = performHoisting;
|
|
118
136
|
function shouldHoistSymbol(context, symbolId, scope) {
|
|
119
|
-
|
|
137
|
+
// Always hoist in top-level of switch statements
|
|
138
|
+
if (scope.type === ScopeType.Switch) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const symbolInfo = (0, symbols_1.getSymbolInfo)(context, symbolId);
|
|
120
142
|
if (!symbolInfo) {
|
|
121
143
|
return false;
|
|
122
144
|
}
|
|
123
|
-
const declaration = typescript_1.getFirstDeclarationInFile(symbolInfo.symbol, context.sourceFile);
|
|
145
|
+
const declaration = (0, typescript_1.getFirstDeclarationInFile)(symbolInfo.symbol, context.sourceFile);
|
|
124
146
|
if (!declaration) {
|
|
125
147
|
return false;
|
|
126
148
|
}
|
|
@@ -129,7 +151,7 @@ function shouldHoistSymbol(context, symbolId, scope) {
|
|
|
129
151
|
}
|
|
130
152
|
if (scope.functionDefinitions) {
|
|
131
153
|
for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) {
|
|
132
|
-
utils_1.assert(functionDefinition.definition);
|
|
154
|
+
(0, utils_1.assert)(functionDefinition.definition);
|
|
133
155
|
const { line, column } = lua.getOriginalPos(functionDefinition.definition);
|
|
134
156
|
if (line !== undefined && column !== undefined) {
|
|
135
157
|
const definitionPos = ts.getPositionOfLineAndCharacter(context.sourceFile, line, column);
|
|
@@ -146,52 +168,60 @@ function shouldHoistSymbol(context, symbolId, scope) {
|
|
|
146
168
|
}
|
|
147
169
|
function hoistVariableDeclarations(context, scope, statements) {
|
|
148
170
|
if (!scope.variableDeclarations) {
|
|
149
|
-
return statements;
|
|
171
|
+
return { unhoistedStatements: statements, hoistedIdentifiers: [] };
|
|
150
172
|
}
|
|
151
|
-
const
|
|
152
|
-
const
|
|
173
|
+
const unhoistedStatements = [...statements];
|
|
174
|
+
const hoistedIdentifiers = [];
|
|
153
175
|
for (const declaration of scope.variableDeclarations) {
|
|
154
176
|
const symbols = declaration.left.map(i => i.symbolId).filter(utils_1.isNonNull);
|
|
155
177
|
if (symbols.some(s => shouldHoistSymbol(context, s, scope))) {
|
|
156
|
-
const index =
|
|
157
|
-
|
|
178
|
+
const index = unhoistedStatements.indexOf(declaration);
|
|
179
|
+
if (index < 0) {
|
|
180
|
+
continue; // statements array may not contain all statements in the scope (switch-case)
|
|
181
|
+
}
|
|
158
182
|
if (declaration.right) {
|
|
159
183
|
const assignment = lua.createAssignmentStatement(declaration.left, declaration.right);
|
|
160
184
|
lua.setNodePosition(assignment, declaration); // Preserve position info for sourcemap
|
|
161
|
-
|
|
185
|
+
unhoistedStatements.splice(index, 1, assignment);
|
|
162
186
|
}
|
|
163
187
|
else {
|
|
164
|
-
|
|
188
|
+
unhoistedStatements.splice(index, 1);
|
|
165
189
|
}
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
else if (scope.type === ScopeType.Switch) {
|
|
169
|
-
utils_1.assert(!declaration.right);
|
|
170
|
-
hoistedLocals.push(...declaration.left);
|
|
190
|
+
hoistedIdentifiers.push(...declaration.left);
|
|
171
191
|
}
|
|
172
192
|
}
|
|
173
|
-
|
|
174
|
-
result.unshift(lua.createVariableDeclarationStatement(hoistedLocals));
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
193
|
+
return { unhoistedStatements, hoistedIdentifiers };
|
|
177
194
|
}
|
|
178
195
|
function hoistFunctionDefinitions(context, scope, statements) {
|
|
179
196
|
if (!scope.functionDefinitions) {
|
|
180
|
-
return statements;
|
|
197
|
+
return { unhoistedStatements: statements, hoistedStatements: [], hoistedIdentifiers: [] };
|
|
181
198
|
}
|
|
182
|
-
const
|
|
183
|
-
const
|
|
199
|
+
const unhoistedStatements = [...statements];
|
|
200
|
+
const hoistedStatements = [];
|
|
201
|
+
const hoistedIdentifiers = [];
|
|
184
202
|
for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) {
|
|
185
|
-
utils_1.assert(functionDefinition.definition);
|
|
203
|
+
(0, utils_1.assert)(functionDefinition.definition);
|
|
186
204
|
if (shouldHoistSymbol(context, functionSymbolId, scope)) {
|
|
187
|
-
const index =
|
|
188
|
-
|
|
189
|
-
|
|
205
|
+
const index = unhoistedStatements.indexOf(functionDefinition.definition);
|
|
206
|
+
if (index < 0) {
|
|
207
|
+
continue; // statements array may not contain all statements in the scope (switch-case)
|
|
208
|
+
}
|
|
209
|
+
unhoistedStatements.splice(index, 1);
|
|
210
|
+
if (lua.isVariableDeclarationStatement(functionDefinition.definition)) {
|
|
211
|
+
// Separate function definition and variable declaration
|
|
212
|
+
(0, utils_1.assert)(functionDefinition.definition.right);
|
|
213
|
+
hoistedIdentifiers.push(...functionDefinition.definition.left);
|
|
214
|
+
hoistedStatements.push(lua.createAssignmentStatement(functionDefinition.definition.left, functionDefinition.definition.right));
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
hoistedStatements.push(functionDefinition.definition);
|
|
218
|
+
}
|
|
190
219
|
}
|
|
191
220
|
}
|
|
192
|
-
return
|
|
221
|
+
return { unhoistedStatements, hoistedStatements, hoistedIdentifiers };
|
|
193
222
|
}
|
|
194
223
|
function hoistImportStatements(scope, statements) {
|
|
195
|
-
|
|
224
|
+
var _a;
|
|
225
|
+
return { unhoistedStatements: statements, hoistedStatements: (_a = scope.importStatements) !== null && _a !== void 0 ? _a : [] };
|
|
196
226
|
}
|
|
197
227
|
//# sourceMappingURL=scope.js.map
|
|
@@ -14,27 +14,27 @@ function nextSymbolId(context) {
|
|
|
14
14
|
const symbolInfoMap = new WeakMap();
|
|
15
15
|
const symbolIdMaps = new WeakMap();
|
|
16
16
|
function getSymbolInfo(context, symbolId) {
|
|
17
|
-
return utils_1.getOrUpdate(symbolInfoMap, context, () => new Map()).get(symbolId);
|
|
17
|
+
return (0, utils_1.getOrUpdate)(symbolInfoMap, context, () => new Map()).get(symbolId);
|
|
18
18
|
}
|
|
19
19
|
exports.getSymbolInfo = getSymbolInfo;
|
|
20
20
|
function getSymbolIdOfSymbol(context, symbol) {
|
|
21
|
-
return utils_1.getOrUpdate(symbolIdMaps, context, () => new Map()).get(symbol);
|
|
21
|
+
return (0, utils_1.getOrUpdate)(symbolIdMaps, context, () => new Map()).get(symbol);
|
|
22
22
|
}
|
|
23
23
|
exports.getSymbolIdOfSymbol = getSymbolIdOfSymbol;
|
|
24
24
|
function trackSymbolReference(context, symbol, identifier) {
|
|
25
|
-
const symbolIds = utils_1.getOrUpdate(symbolIdMaps, context, () => new Map());
|
|
25
|
+
const symbolIds = (0, utils_1.getOrUpdate)(symbolIdMaps, context, () => new Map());
|
|
26
26
|
// Track first time symbols are seen
|
|
27
27
|
let symbolId = symbolIds.get(symbol);
|
|
28
28
|
if (symbolId === undefined) {
|
|
29
29
|
symbolId = nextSymbolId(context);
|
|
30
30
|
symbolIds.set(symbol, symbolId);
|
|
31
|
-
const symbolInfo = utils_1.getOrUpdate(symbolInfoMap, context, () => new Map());
|
|
31
|
+
const symbolInfo = (0, utils_1.getOrUpdate)(symbolInfoMap, context, () => new Map());
|
|
32
32
|
symbolInfo.set(symbolId, { symbol, firstSeenAtPos: identifier.pos });
|
|
33
33
|
}
|
|
34
34
|
// If isOptimizedVarArgSpread returns true, the identifier will not appear in the resulting Lua.
|
|
35
35
|
// Only the optimized ellipses (...) will be used.
|
|
36
|
-
if (!spread_1.isOptimizedVarArgSpread(context, symbol, identifier)) {
|
|
37
|
-
scope_1.markSymbolAsReferencedInCurrentScopes(context, symbolId, identifier);
|
|
36
|
+
if (!(0, spread_1.isOptimizedVarArgSpread)(context, symbol, identifier)) {
|
|
37
|
+
(0, scope_1.markSymbolAsReferencedInCurrentScopes)(context, symbolId, identifier);
|
|
38
38
|
}
|
|
39
39
|
return symbolId;
|
|
40
40
|
}
|
|
@@ -5,10 +5,10 @@ const utils_1 = require("../../utils");
|
|
|
5
5
|
const lua_ast_1 = require("./lua-ast");
|
|
6
6
|
const scope_1 = require("./scope");
|
|
7
7
|
function transformToImmediatelyInvokedFunctionExpression(context, transformFunction, tsOriginal) {
|
|
8
|
-
scope_1.pushScope(context, scope_1.ScopeType.Function);
|
|
8
|
+
(0, scope_1.pushScope)(context, scope_1.ScopeType.Function);
|
|
9
9
|
const { statements, result } = transformFunction();
|
|
10
|
-
scope_1.popScope(context);
|
|
11
|
-
return lua_ast_1.createImmediatelyInvokedFunctionExpression(utils_1.castArray(statements), result, tsOriginal);
|
|
10
|
+
(0, scope_1.popScope)(context);
|
|
11
|
+
return (0, lua_ast_1.createImmediatelyInvokedFunctionExpression)((0, utils_1.castArray)(statements), result, tsOriginal);
|
|
12
12
|
}
|
|
13
13
|
exports.transformToImmediatelyInvokedFunctionExpression = transformToImmediatelyInvokedFunctionExpression;
|
|
14
14
|
//# sourceMappingURL=transform.js.map
|
|
@@ -4,6 +4,8 @@ export declare function isAssignmentPattern(node: ts.Node): node is ts.Assignmen
|
|
|
4
4
|
export declare function isDestructuringAssignment(node: ts.Node): node is ts.DestructuringAssignment;
|
|
5
5
|
export declare function isAmbientNode(node: ts.Declaration): boolean;
|
|
6
6
|
export declare function isInDestructingAssignment(node: ts.Node): boolean;
|
|
7
|
+
export declare function isInAsyncFunction(node: ts.Node): boolean;
|
|
8
|
+
export declare function isInGeneratorFunction(node: ts.Node): boolean;
|
|
7
9
|
/**
|
|
8
10
|
* Quite hacky, avoid unless absolutely necessary!
|
|
9
11
|
*/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isFirstDeclaration = exports.getSymbolOfNode = exports.isInDestructingAssignment = exports.isAmbientNode = exports.isDestructuringAssignment = exports.isAssignmentPattern = void 0;
|
|
3
|
+
exports.isFirstDeclaration = exports.getSymbolOfNode = exports.isInGeneratorFunction = exports.isInAsyncFunction = exports.isInDestructingAssignment = exports.isAmbientNode = exports.isDestructuringAssignment = exports.isAssignmentPattern = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const _1 = require(".");
|
|
5
6
|
function isAssignmentPattern(node) {
|
|
6
7
|
return ts.isObjectLiteralExpression(node) || ts.isArrayLiteralExpression(node);
|
|
7
8
|
}
|
|
@@ -22,6 +23,25 @@ function isInDestructingAssignment(node) {
|
|
|
22
23
|
(ts.isBinaryExpression(node.parent) && ts.isArrayLiteralExpression(node.parent.left))));
|
|
23
24
|
}
|
|
24
25
|
exports.isInDestructingAssignment = isInDestructingAssignment;
|
|
26
|
+
function isInAsyncFunction(node) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
// Check if node is in function declaration with `async`
|
|
29
|
+
const declaration = (0, _1.findFirstNodeAbove)(node, ts.isFunctionLike);
|
|
30
|
+
if (!declaration) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return (_b = (_a = declaration.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) !== null && _b !== void 0 ? _b : false;
|
|
34
|
+
}
|
|
35
|
+
exports.isInAsyncFunction = isInAsyncFunction;
|
|
36
|
+
function isInGeneratorFunction(node) {
|
|
37
|
+
// Check if node is in function declaration with `async`
|
|
38
|
+
const declaration = (0, _1.findFirstNodeAbove)(node, ts.isFunctionDeclaration);
|
|
39
|
+
if (!declaration) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return declaration.asteriskToken !== undefined;
|
|
43
|
+
}
|
|
44
|
+
exports.isInGeneratorFunction = isInGeneratorFunction;
|
|
25
45
|
/**
|
|
26
46
|
* Quite hacky, avoid unless absolutely necessary!
|
|
27
47
|
*/
|
|
@@ -15,29 +15,29 @@ function transformElementAccessArgument(context, node) {
|
|
|
15
15
|
const index = context.transformExpression(node.argumentExpression);
|
|
16
16
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
17
17
|
const argumentType = context.checker.getTypeAtLocation(node.argumentExpression);
|
|
18
|
-
if (typescript_1.isArrayType(context, type) && typescript_1.isNumberType(context, argumentType)) {
|
|
19
|
-
return lua_ast_1.addToNumericExpression(index, 1);
|
|
18
|
+
if ((0, typescript_1.isArrayType)(context, type) && (0, typescript_1.isNumberType)(context, argumentType)) {
|
|
19
|
+
return (0, lua_ast_1.addToNumericExpression)(index, 1);
|
|
20
20
|
}
|
|
21
21
|
return index;
|
|
22
22
|
}
|
|
23
23
|
exports.transformElementAccessArgument = transformElementAccessArgument;
|
|
24
24
|
const transformElementAccessExpression = (node, context) => {
|
|
25
|
-
const constEnumValue = enum_1.tryGetConstEnumValue(context, node);
|
|
25
|
+
const constEnumValue = (0, enum_1.tryGetConstEnumValue)(context, node);
|
|
26
26
|
if (constEnumValue) {
|
|
27
27
|
return constEnumValue;
|
|
28
28
|
}
|
|
29
29
|
const table = context.transformExpression(node.expression);
|
|
30
30
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
31
31
|
const argumentType = context.checker.getTypeAtLocation(node.argumentExpression);
|
|
32
|
-
if (typescript_1.isStringType(context, type) && typescript_1.isNumberType(context, argumentType)) {
|
|
32
|
+
if ((0, typescript_1.isStringType)(context, type) && (0, typescript_1.isNumberType)(context, argumentType)) {
|
|
33
33
|
const index = context.transformExpression(node.argumentExpression);
|
|
34
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.StringAccess, node, table, index);
|
|
34
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.StringAccess, node, table, index);
|
|
35
35
|
}
|
|
36
36
|
const accessExpression = transformElementAccessArgument(context, node);
|
|
37
|
-
if (multi_1.isMultiReturnCall(context, node.expression)) {
|
|
37
|
+
if ((0, multi_1.isMultiReturnCall)(context, node.expression)) {
|
|
38
38
|
const accessType = context.checker.getTypeAtLocation(node.argumentExpression);
|
|
39
|
-
if (!typescript_1.isNumberType(context, accessType)) {
|
|
40
|
-
context.diagnostics.push(diagnostics_1.invalidMultiReturnAccess(node));
|
|
39
|
+
if (!(0, typescript_1.isNumberType)(context, accessType)) {
|
|
40
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiReturnAccess)(node));
|
|
41
41
|
}
|
|
42
42
|
// When selecting the first element, we can shortcut
|
|
43
43
|
if (ts.isNumericLiteral(node.argumentExpression) && node.argumentExpression.text === "0") {
|
|
@@ -50,7 +50,7 @@ const transformElementAccessExpression = (node, context) => {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
if (ts.isOptionalChain(node)) {
|
|
53
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalChainAccess, node, table, accessExpression);
|
|
53
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalChainAccess, node, table, accessExpression);
|
|
54
54
|
}
|
|
55
55
|
return lua.createTableIndexExpression(table, accessExpression, node);
|
|
56
56
|
};
|
|
@@ -58,20 +58,20 @@ exports.transformElementAccessExpression = transformElementAccessExpression;
|
|
|
58
58
|
const transformPropertyAccessExpression = (node, context) => {
|
|
59
59
|
const property = node.name.text;
|
|
60
60
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
61
|
-
const annotations = annotations_1.getTypeAnnotations(type);
|
|
61
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
62
62
|
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
63
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.LuaTable));
|
|
63
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
64
64
|
}
|
|
65
|
-
const constEnumValue = enum_1.tryGetConstEnumValue(context, node);
|
|
65
|
+
const constEnumValue = (0, enum_1.tryGetConstEnumValue)(context, node);
|
|
66
66
|
if (constEnumValue) {
|
|
67
67
|
return constEnumValue;
|
|
68
68
|
}
|
|
69
|
-
const builtinResult = builtins_1.transformBuiltinPropertyAccessExpression(context, node);
|
|
69
|
+
const builtinResult = (0, builtins_1.transformBuiltinPropertyAccessExpression)(context, node);
|
|
70
70
|
if (builtinResult) {
|
|
71
71
|
return builtinResult;
|
|
72
72
|
}
|
|
73
|
-
if (ts.isCallExpression(node.expression) && multi_1.returnsMultiType(context, node.expression)) {
|
|
74
|
-
context.diagnostics.push(diagnostics_1.invalidMultiReturnAccess(node));
|
|
73
|
+
if (ts.isCallExpression(node.expression) && (0, multi_1.returnsMultiType)(context, node.expression)) {
|
|
74
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiReturnAccess)(node));
|
|
75
75
|
}
|
|
76
76
|
// Do not output path for member only enums
|
|
77
77
|
if (annotations.has(annotations_1.AnnotationKind.CompileMembersOnly)) {
|
|
@@ -94,7 +94,7 @@ exports.transformPropertyAccessExpression = transformPropertyAccessExpression;
|
|
|
94
94
|
function transformOptionalChain(context, node) {
|
|
95
95
|
const left = context.transformExpression(node.expression);
|
|
96
96
|
const right = lua.createStringLiteral(node.name.text, node.name);
|
|
97
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalChainAccess, node, left, right);
|
|
97
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalChainAccess, node, left, right);
|
|
98
98
|
}
|
|
99
99
|
const transformQualifiedName = (node, context) => {
|
|
100
100
|
const right = lua.createStringLiteral(node.right.text, node.right);
|
|
@@ -9,13 +9,14 @@ const typescript_1 = require("../utils/typescript");
|
|
|
9
9
|
const transformAwaitExpression = (node, context) => {
|
|
10
10
|
var _a;
|
|
11
11
|
// Check if await is inside an async function, it is not allowed at top level or in non-async functions
|
|
12
|
-
const containingFunction = typescript_1.findFirstNodeAbove(node, ts.isFunctionLike);
|
|
12
|
+
const containingFunction = (0, typescript_1.findFirstNodeAbove)(node, ts.isFunctionLike);
|
|
13
13
|
if (containingFunction === undefined ||
|
|
14
14
|
!((_a = containingFunction.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.AsyncKeyword))) {
|
|
15
|
-
context.diagnostics.push(diagnostics_1.awaitMustBeInAsyncFunction(node));
|
|
15
|
+
context.diagnostics.push((0, diagnostics_1.awaitMustBeInAsyncFunction)(node));
|
|
16
16
|
}
|
|
17
17
|
const expression = context.transformExpression(node.expression);
|
|
18
|
-
|
|
18
|
+
const catchIdentifier = lua.createIdentifier("____catch");
|
|
19
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Await, node, catchIdentifier, expression);
|
|
19
20
|
};
|
|
20
21
|
exports.transformAwaitExpression = transformAwaitExpression;
|
|
21
22
|
function isAsyncFunction(declaration) {
|
|
@@ -24,7 +25,7 @@ function isAsyncFunction(declaration) {
|
|
|
24
25
|
}
|
|
25
26
|
exports.isAsyncFunction = isAsyncFunction;
|
|
26
27
|
function wrapInAsyncAwaiter(context, statements) {
|
|
27
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Await);
|
|
28
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Await);
|
|
28
29
|
return [
|
|
29
30
|
lua.createReturnStatement([
|
|
30
31
|
lua.createCallExpression(lua.createIdentifier("__TS__AsyncAwaiter"), [
|
|
@@ -18,33 +18,33 @@ const diagnostics_1 = require("../../utils/diagnostics");
|
|
|
18
18
|
function transformAssignmentLeftHandSideExpression(context, node) {
|
|
19
19
|
const symbol = context.checker.getSymbolAtLocation(node);
|
|
20
20
|
const left = context.transformExpression(node);
|
|
21
|
-
return lua.isIdentifier(left) && symbol && export_1.isSymbolExported(context, symbol)
|
|
22
|
-
? export_1.createExportedIdentifier(context, left)
|
|
23
|
-
: utils_1.cast(left, lua.isAssignmentLeftHandSideExpression);
|
|
21
|
+
return lua.isIdentifier(left) && symbol && (0, export_1.isSymbolExported)(context, symbol)
|
|
22
|
+
? (0, export_1.createExportedIdentifier)(context, left)
|
|
23
|
+
: (0, utils_1.cast)(left, lua.isAssignmentLeftHandSideExpression);
|
|
24
24
|
}
|
|
25
25
|
exports.transformAssignmentLeftHandSideExpression = transformAssignmentLeftHandSideExpression;
|
|
26
26
|
function transformAssignment(context,
|
|
27
27
|
// TODO: Change type to ts.LeftHandSideExpression?
|
|
28
28
|
lhs, right, parent) {
|
|
29
29
|
if (ts.isOptionalChain(lhs)) {
|
|
30
|
-
context.diagnostics.push(diagnostics_1.notAllowedOptionalAssignment(lhs));
|
|
30
|
+
context.diagnostics.push((0, diagnostics_1.notAllowedOptionalAssignment)(lhs));
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
|
-
if (destructuring_assignments_1.isArrayLength(context, lhs)) {
|
|
34
|
-
const arrayLengthAssignment = lua.createExpressionStatement(lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ArraySetLength, parent, context.transformExpression(lhs.expression), right));
|
|
33
|
+
if ((0, destructuring_assignments_1.isArrayLength)(context, lhs)) {
|
|
34
|
+
const arrayLengthAssignment = lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySetLength, parent, context.transformExpression(lhs.expression), right));
|
|
35
35
|
return [arrayLengthAssignment];
|
|
36
36
|
}
|
|
37
37
|
const symbol = ts.isShorthandPropertyAssignment(lhs.parent)
|
|
38
38
|
? context.checker.getShorthandAssignmentValueSymbol(lhs.parent)
|
|
39
39
|
: context.checker.getSymbolAtLocation(lhs);
|
|
40
|
-
const dependentSymbols = symbol ? export_1.getDependenciesOfSymbol(context, symbol) : [];
|
|
40
|
+
const dependentSymbols = symbol ? (0, export_1.getDependenciesOfSymbol)(context, symbol) : [];
|
|
41
41
|
const left = transformAssignmentLeftHandSideExpression(context, lhs);
|
|
42
42
|
const rootAssignment = lua.createAssignmentStatement(left, right, lhs.parent);
|
|
43
43
|
return [
|
|
44
44
|
rootAssignment,
|
|
45
45
|
...dependentSymbols.map(symbol => {
|
|
46
46
|
const [left] = rootAssignment.left;
|
|
47
|
-
const identifierToAssign = export_1.createExportedIdentifier(context, lua.createIdentifier(symbol.name));
|
|
47
|
+
const identifierToAssign = (0, export_1.createExportedIdentifier)(context, lua.createIdentifier(symbol.name));
|
|
48
48
|
return lua.createAssignmentStatement(identifierToAssign, left);
|
|
49
49
|
}),
|
|
50
50
|
];
|
|
@@ -53,12 +53,12 @@ exports.transformAssignment = transformAssignment;
|
|
|
53
53
|
function transformDestructuredAssignmentExpression(context, expression) {
|
|
54
54
|
const rootIdentifier = lua.createAnonymousIdentifier(expression.left);
|
|
55
55
|
let right = context.transformExpression(expression.right);
|
|
56
|
-
if (multi_1.isMultiReturnCall(context, expression.right)) {
|
|
57
|
-
right = lua_ast_1.wrapInTable(right);
|
|
56
|
+
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
|
|
57
|
+
right = (0, lua_ast_1.wrapInTable)(right);
|
|
58
58
|
}
|
|
59
59
|
const statements = [
|
|
60
60
|
lua.createVariableDeclarationStatement(rootIdentifier, right),
|
|
61
|
-
...destructuring_assignments_1.transformDestructuringAssignment(context, expression, rootIdentifier),
|
|
61
|
+
...(0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rootIdentifier),
|
|
62
62
|
];
|
|
63
63
|
return { statements, result: rootIdentifier };
|
|
64
64
|
}
|
|
@@ -66,13 +66,13 @@ function transformAssignmentExpression(context, expression) {
|
|
|
66
66
|
// Validate assignment
|
|
67
67
|
const rightType = context.checker.getTypeAtLocation(expression.right);
|
|
68
68
|
const leftType = context.checker.getTypeAtLocation(expression.left);
|
|
69
|
-
assignment_validation_1.validateAssignment(context, expression.right, rightType, leftType);
|
|
70
|
-
if (destructuring_assignments_1.isArrayLength(context, expression.left)) {
|
|
69
|
+
(0, assignment_validation_1.validateAssignment)(context, expression.right, rightType, leftType);
|
|
70
|
+
if ((0, destructuring_assignments_1.isArrayLength)(context, expression.left)) {
|
|
71
71
|
// array.length = x
|
|
72
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ArraySetLength, expression, context.transformExpression(expression.left.expression), context.transformExpression(expression.right));
|
|
72
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySetLength, expression, context.transformExpression(expression.left.expression), context.transformExpression(expression.right));
|
|
73
73
|
}
|
|
74
|
-
if (typescript_1.isDestructuringAssignment(expression)) {
|
|
75
|
-
return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => transformDestructuredAssignmentExpression(context, expression), expression);
|
|
74
|
+
if ((0, typescript_1.isDestructuringAssignment)(expression)) {
|
|
75
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => transformDestructuredAssignmentExpression(context, expression), expression);
|
|
76
76
|
}
|
|
77
77
|
if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) {
|
|
78
78
|
// Left is property/element access: cache result while maintaining order of evaluation
|
|
@@ -90,7 +90,7 @@ function transformAssignmentExpression(context, expression) {
|
|
|
90
90
|
indexParameter,
|
|
91
91
|
valueParameter,
|
|
92
92
|
]);
|
|
93
|
-
scope_1.pushScope(context, scope_1.ScopeType.Function);
|
|
93
|
+
(0, scope_1.pushScope)(context, scope_1.ScopeType.Function);
|
|
94
94
|
const objExpression = context.transformExpression(expression.left.expression);
|
|
95
95
|
let indexExpression;
|
|
96
96
|
if (ts.isPropertyAccessExpression(expression.left)) {
|
|
@@ -99,14 +99,14 @@ function transformAssignmentExpression(context, expression) {
|
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
// Element access
|
|
102
|
-
indexExpression = access_1.transformElementAccessArgument(context, expression.left);
|
|
102
|
+
indexExpression = (0, access_1.transformElementAccessArgument)(context, expression.left);
|
|
103
103
|
}
|
|
104
104
|
const args = [objExpression, indexExpression, context.transformExpression(expression.right)];
|
|
105
|
-
scope_1.popScope(context);
|
|
105
|
+
(0, scope_1.popScope)(context);
|
|
106
106
|
return lua.createCallExpression(iife, args, expression);
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => {
|
|
109
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => {
|
|
110
110
|
// Simple assignment
|
|
111
111
|
// (function() ${left} = ${right}; return ${left} end)()
|
|
112
112
|
const left = context.transformExpression(expression.left);
|
|
@@ -119,7 +119,7 @@ function transformAssignmentExpression(context, expression) {
|
|
|
119
119
|
exports.transformAssignmentExpression = transformAssignmentExpression;
|
|
120
120
|
const canBeTransformedToLuaAssignmentStatement = (context, node) => ts.isArrayLiteralExpression(node.left) &&
|
|
121
121
|
node.left.elements.every(element => {
|
|
122
|
-
if (destructuring_assignments_1.isArrayLength(context, element)) {
|
|
122
|
+
if ((0, destructuring_assignments_1.isArrayLength)(context, element)) {
|
|
123
123
|
return false;
|
|
124
124
|
}
|
|
125
125
|
if (ts.isPropertyAccessExpression(element) || ts.isElementAccessExpression(element)) {
|
|
@@ -128,7 +128,7 @@ const canBeTransformedToLuaAssignmentStatement = (context, node) => ts.isArrayLi
|
|
|
128
128
|
if (ts.isIdentifier(element)) {
|
|
129
129
|
const symbol = context.checker.getSymbolAtLocation(element);
|
|
130
130
|
if (symbol) {
|
|
131
|
-
const aliases = export_1.getDependenciesOfSymbol(context, symbol);
|
|
131
|
+
const aliases = (0, export_1.getDependenciesOfSymbol)(context, symbol);
|
|
132
132
|
return aliases.length === 0;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -137,28 +137,28 @@ function transformAssignmentStatement(context, expression) {
|
|
|
137
137
|
// Validate assignment
|
|
138
138
|
const rightType = context.checker.getTypeAtLocation(expression.right);
|
|
139
139
|
const leftType = context.checker.getTypeAtLocation(expression.left);
|
|
140
|
-
assignment_validation_1.validateAssignment(context, expression.right, rightType, leftType);
|
|
141
|
-
if (typescript_1.isDestructuringAssignment(expression)) {
|
|
140
|
+
(0, assignment_validation_1.validateAssignment)(context, expression.right, rightType, leftType);
|
|
141
|
+
if ((0, typescript_1.isDestructuringAssignment)(expression)) {
|
|
142
142
|
if (canBeTransformedToLuaAssignmentStatement(context, expression)) {
|
|
143
143
|
const rightType = context.checker.getTypeAtLocation(expression.right);
|
|
144
144
|
let right = context.transformExpression(expression.right);
|
|
145
145
|
if (ts.isArrayLiteralExpression(expression.right)) {
|
|
146
146
|
right = expression.right.elements.map(e => context.transformExpression(e));
|
|
147
147
|
}
|
|
148
|
-
else if (!multi_1.isMultiReturnCall(context, expression.right) && typescript_1.isArrayType(context, rightType)) {
|
|
149
|
-
right = lua_ast_1.createUnpackCall(context, right, expression.right);
|
|
148
|
+
else if (!(0, multi_1.isMultiReturnCall)(context, expression.right) && (0, typescript_1.isArrayType)(context, rightType)) {
|
|
149
|
+
right = (0, lua_ast_1.createUnpackCall)(context, right, expression.right);
|
|
150
150
|
}
|
|
151
151
|
const left = expression.left.elements.map(e => transformAssignmentLeftHandSideExpression(context, e));
|
|
152
152
|
return [lua.createAssignmentStatement(left, right, expression)];
|
|
153
153
|
}
|
|
154
154
|
let right = context.transformExpression(expression.right);
|
|
155
|
-
if (multi_1.isMultiReturnCall(context, expression.right)) {
|
|
156
|
-
right = lua_ast_1.wrapInTable(right);
|
|
155
|
+
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
|
|
156
|
+
right = (0, lua_ast_1.wrapInTable)(right);
|
|
157
157
|
}
|
|
158
158
|
const rootIdentifier = lua.createAnonymousIdentifier(expression.left);
|
|
159
159
|
return [
|
|
160
160
|
lua.createVariableDeclarationStatement(rootIdentifier, right),
|
|
161
|
-
...destructuring_assignments_1.transformDestructuringAssignment(context, expression, rootIdentifier),
|
|
161
|
+
...(0, destructuring_assignments_1.transformDestructuringAssignment)(context, expression, rootIdentifier),
|
|
162
162
|
];
|
|
163
163
|
}
|
|
164
164
|
else {
|