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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNaN = exports.createLocalOrExportedOrGlobalDeclaration = exports.createHoistableVariableDeclarationStatement = exports.wrapInToStringForConcat = exports.wrapInTable = exports.createUnpackCall = exports.
|
|
3
|
+
exports.createNaN = exports.createLocalOrExportedOrGlobalDeclaration = exports.createHoistableVariableDeclarationStatement = exports.wrapInToStringForConcat = exports.wrapInTable = exports.createUnpackCall = exports.getNumberLiteralValue = exports.addToNumericExpression = exports.createExportsIdentifier = exports.createSelfIdentifier = exports.unwrapVisitorResult = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
6
6
|
const lua = require("../../LuaAST");
|
|
@@ -10,7 +10,7 @@ const scope_1 = require("./scope");
|
|
|
10
10
|
const lualib_1 = require("./lualib");
|
|
11
11
|
const LuaLib_1 = require("../../LuaLib");
|
|
12
12
|
function unwrapVisitorResult(result) {
|
|
13
|
-
return result === undefined ? [] : utils_1.castArray(result);
|
|
13
|
+
return result === undefined ? [] : (0, utils_1.castArray)(result);
|
|
14
14
|
}
|
|
15
15
|
exports.unwrapVisitorResult = unwrapVisitorResult;
|
|
16
16
|
function createSelfIdentifier(tsOriginal) {
|
|
@@ -55,18 +55,9 @@ function getNumberLiteralValue(expression) {
|
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
57
|
exports.getNumberLiteralValue = getNumberLiteralValue;
|
|
58
|
-
// Prefer use of transformToImmediatelyInvokedFunctionExpression to maintain correct scope. If you use this directly,
|
|
59
|
-
// ensure you push/pop a function scope appropriately to avoid incorrect vararg optimization.
|
|
60
|
-
function createImmediatelyInvokedFunctionExpression(statements, result, tsOriginal) {
|
|
61
|
-
const body = [...statements, lua.createReturnStatement(utils_1.castArray(result))];
|
|
62
|
-
const flags = statements.length === 0 ? lua.FunctionExpressionFlags.Inline : lua.FunctionExpressionFlags.None;
|
|
63
|
-
const iife = lua.createFunctionExpression(lua.createBlock(body), undefined, undefined, flags);
|
|
64
|
-
return lua.createCallExpression(iife, [], tsOriginal);
|
|
65
|
-
}
|
|
66
|
-
exports.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
|
|
67
58
|
function createUnpackCall(context, expression, tsOriginal) {
|
|
68
59
|
if (context.luaTarget === CompilerOptions_1.LuaTarget.Universal) {
|
|
69
|
-
return lualib_1.transformLuaLibFunction(context, LuaLib_1.LuaLibFeature.Unpack, tsOriginal, expression);
|
|
60
|
+
return (0, lualib_1.transformLuaLibFunction)(context, LuaLib_1.LuaLibFeature.Unpack, tsOriginal, expression);
|
|
70
61
|
}
|
|
71
62
|
const unpack = context.luaTarget === CompilerOptions_1.LuaTarget.Lua51 || context.luaTarget === CompilerOptions_1.LuaTarget.LuaJIT
|
|
72
63
|
? lua.createIdentifier("unpack")
|
|
@@ -91,12 +82,9 @@ exports.wrapInToStringForConcat = wrapInToStringForConcat;
|
|
|
91
82
|
function createHoistableVariableDeclarationStatement(context, identifier, initializer, tsOriginal) {
|
|
92
83
|
const declaration = lua.createVariableDeclarationStatement(identifier, initializer, tsOriginal);
|
|
93
84
|
if (identifier.symbolId !== undefined) {
|
|
94
|
-
const scope = scope_1.peekScope(context);
|
|
95
|
-
utils_1.assert(scope.type !== scope_1.ScopeType.Switch);
|
|
96
|
-
|
|
97
|
-
scope.variableDeclarations = [];
|
|
98
|
-
}
|
|
99
|
-
scope.variableDeclarations.push(declaration);
|
|
85
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
86
|
+
(0, utils_1.assert)(scope.type !== scope_1.ScopeType.Switch);
|
|
87
|
+
(0, scope_1.addScopeVariableDeclaration)(scope, declaration);
|
|
100
88
|
}
|
|
101
89
|
return declaration;
|
|
102
90
|
}
|
|
@@ -106,48 +94,50 @@ function hasMultipleReferences(scope, identifiers) {
|
|
|
106
94
|
if (!scopeSymbols) {
|
|
107
95
|
return false;
|
|
108
96
|
}
|
|
109
|
-
const referenceLists = utils_1.castArray(identifiers).map(i => i.symbolId && scopeSymbols.get(i.symbolId));
|
|
97
|
+
const referenceLists = (0, utils_1.castArray)(identifiers).map(i => i.symbolId && scopeSymbols.get(i.symbolId));
|
|
110
98
|
return referenceLists.some(symbolRefs => symbolRefs && symbolRefs.length > 1);
|
|
111
99
|
}
|
|
112
100
|
function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal, overrideExportScope) {
|
|
113
101
|
let declaration;
|
|
114
102
|
let assignment;
|
|
115
103
|
const isFunctionDeclaration = tsOriginal !== undefined && ts.isFunctionDeclaration(tsOriginal);
|
|
116
|
-
const identifiers = utils_1.castArray(lhs);
|
|
104
|
+
const identifiers = (0, utils_1.castArray)(lhs);
|
|
117
105
|
if (identifiers.length === 0) {
|
|
118
106
|
return [];
|
|
119
107
|
}
|
|
120
|
-
const exportScope = overrideExportScope !== null && overrideExportScope !== void 0 ? overrideExportScope : export_1.getIdentifierExportScope(context, identifiers[0]);
|
|
108
|
+
const exportScope = overrideExportScope !== null && overrideExportScope !== void 0 ? overrideExportScope : (0, export_1.getIdentifierExportScope)(context, identifiers[0]);
|
|
121
109
|
if (exportScope) {
|
|
122
110
|
// exported
|
|
123
111
|
if (!rhs) {
|
|
124
112
|
return [];
|
|
125
113
|
}
|
|
126
114
|
else {
|
|
127
|
-
assignment = lua.createAssignmentStatement(identifiers.map(identifier => export_1.createExportedIdentifier(context, identifier, exportScope)), rhs, tsOriginal);
|
|
115
|
+
assignment = lua.createAssignmentStatement(identifiers.map(identifier => (0, export_1.createExportedIdentifier)(context, identifier, exportScope)), rhs, tsOriginal);
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
118
|
else {
|
|
131
|
-
const scope = scope_1.peekScope(context);
|
|
119
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
132
120
|
const isTopLevelVariable = scope.type === scope_1.ScopeType.File;
|
|
133
121
|
if (context.isModule || !isTopLevelVariable) {
|
|
134
|
-
if (
|
|
135
|
-
// Split declaration and assignment of identifiers that reference themselves in their declaration
|
|
136
|
-
declaration
|
|
122
|
+
if (!isFunctionDeclaration && hasMultipleReferences(scope, lhs)) {
|
|
123
|
+
// Split declaration and assignment of identifiers that reference themselves in their declaration.
|
|
124
|
+
// Put declaration above preceding statements in case the identifier is referenced in those.
|
|
125
|
+
const precedingDeclaration = lua.createVariableDeclarationStatement(lhs, undefined, tsOriginal);
|
|
126
|
+
context.prependPrecedingStatements(precedingDeclaration);
|
|
137
127
|
if (rhs) {
|
|
138
128
|
assignment = lua.createAssignmentStatement(lhs, rhs, tsOriginal);
|
|
139
129
|
}
|
|
130
|
+
if (!isFunctionDeclaration) {
|
|
131
|
+
// Remember local variable declarations for hoisting later
|
|
132
|
+
(0, scope_1.addScopeVariableDeclaration)(scope, precedingDeclaration);
|
|
133
|
+
}
|
|
140
134
|
}
|
|
141
135
|
else {
|
|
142
136
|
declaration = lua.createVariableDeclarationStatement(lhs, rhs, tsOriginal);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
scope.variableDeclarations.push(declaration);
|
|
149
|
-
if (scope.type === scope_1.ScopeType.Switch) {
|
|
150
|
-
declaration = undefined;
|
|
137
|
+
if (!isFunctionDeclaration) {
|
|
138
|
+
// Remember local variable declarations for hoisting later
|
|
139
|
+
(0, scope_1.addScopeVariableDeclaration)(scope, declaration);
|
|
140
|
+
}
|
|
151
141
|
}
|
|
152
142
|
}
|
|
153
143
|
else if (rhs) {
|
|
@@ -161,7 +151,7 @@ function createLocalOrExportedOrGlobalDeclaration(context, lhs, rhs, tsOriginal,
|
|
|
161
151
|
if (isFunctionDeclaration) {
|
|
162
152
|
// Remember function definitions for hoisting later
|
|
163
153
|
const functionSymbolId = lhs.symbolId;
|
|
164
|
-
const scope = scope_1.peekScope(context);
|
|
154
|
+
const scope = (0, scope_1.peekScope)(context);
|
|
165
155
|
if (functionSymbolId && scope.functionDefinitions) {
|
|
166
156
|
const definitions = scope.functionDefinitions.get(functionSymbolId);
|
|
167
157
|
if (definitions) {
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "LuaLibFeature", { enumerable: true, get: functio
|
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const luaLibFeatures = new WeakMap();
|
|
9
9
|
function getUsedLuaLibFeatures(context) {
|
|
10
|
-
return utils_1.getOrUpdate(luaLibFeatures, context, () => new Set());
|
|
10
|
+
return (0, utils_1.getOrUpdate)(luaLibFeatures, context, () => new Set());
|
|
11
11
|
}
|
|
12
12
|
exports.getUsedLuaLibFeatures = getUsedLuaLibFeatures;
|
|
13
13
|
function importLuaLibFeature(context, feature) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as lua from "../../LuaAST";
|
|
2
|
+
import { TransformationContext } from "../context";
|
|
3
|
+
export declare function transformInPrecedingStatementScope<TReturn extends lua.Statement | lua.Statement[] | lua.Expression | lua.Expression[]>(context: TransformationContext, transformer: () => TReturn): [lua.Statement[], TReturn];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformInPrecedingStatementScope = void 0;
|
|
4
|
+
function transformInPrecedingStatementScope(context, transformer) {
|
|
5
|
+
context.pushPrecedingStatements();
|
|
6
|
+
const statementOrStatements = transformer();
|
|
7
|
+
const precedingStatements = context.popPrecedingStatements();
|
|
8
|
+
return [precedingStatements, statementOrStatements];
|
|
9
|
+
}
|
|
10
|
+
exports.transformInPrecedingStatementScope = transformInPrecedingStatementScope;
|
|
11
|
+
//# sourceMappingURL=preceding-statements.js.map
|
|
@@ -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,16 +26,23 @@ 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;
|
|
32
37
|
export declare function findScope(context: TransformationContext, scopeTypes: ScopeType): Scope | undefined;
|
|
33
38
|
export declare function pushScope(context: TransformationContext, scopeType: ScopeType): Scope;
|
|
34
39
|
export declare function popScope(context: TransformationContext): Scope;
|
|
40
|
+
export declare function addScopeVariableDeclaration(scope: Scope, declaration: lua.VariableDeclarationStatement): void;
|
|
35
41
|
export declare function hasReferencedUndefinedLocalFunction(context: TransformationContext, scope: Scope): boolean;
|
|
36
42
|
export declare function hasReferencedSymbol(context: TransformationContext, scope: Scope, symbol: ts.Symbol): boolean | undefined;
|
|
37
43
|
export declare function isFunctionScopeWithDefinition(scope: Scope): scope is Scope & {
|
|
38
44
|
node: ts.SignatureDeclaration;
|
|
39
45
|
};
|
|
46
|
+
export declare function separateHoistedStatements(context: TransformationContext, statements: lua.Statement[]): HoistingResult;
|
|
40
47
|
export declare function performHoisting(context: TransformationContext, statements: lua.Statement[]): lua.Statement[];
|
|
41
48
|
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.addScopeVariableDeclaration = 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,20 @@ 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
|
+
function addScopeVariableDeclaration(scope, declaration) {
|
|
72
|
+
if (!scope.variableDeclarations) {
|
|
73
|
+
scope.variableDeclarations = [];
|
|
74
|
+
}
|
|
75
|
+
scope.variableDeclarations.push(declaration);
|
|
76
|
+
}
|
|
77
|
+
exports.addScopeVariableDeclaration = addScopeVariableDeclaration;
|
|
71
78
|
function isHoistableFunctionDeclaredInScope(symbol, scopeNode) {
|
|
72
79
|
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));
|
|
80
|
+
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
81
|
}
|
|
75
82
|
// Checks for references to local functions which haven't been defined yet,
|
|
76
83
|
// and thus will be hoisted above the current position.
|
|
@@ -106,21 +113,43 @@ function isFunctionScopeWithDefinition(scope) {
|
|
|
106
113
|
return scope.node !== undefined && ts.isFunctionLike(scope.node);
|
|
107
114
|
}
|
|
108
115
|
exports.isFunctionScopeWithDefinition = isFunctionScopeWithDefinition;
|
|
109
|
-
function
|
|
116
|
+
function separateHoistedStatements(context, statements) {
|
|
110
117
|
const scope = peekScope(context);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
const allHoistedStatments = [];
|
|
119
|
+
const allHoistedIdentifiers = [];
|
|
120
|
+
let { unhoistedStatements, hoistedStatements, hoistedIdentifiers } = hoistFunctionDefinitions(context, scope, statements);
|
|
121
|
+
allHoistedStatments.push(...hoistedStatements);
|
|
122
|
+
allHoistedIdentifiers.push(...hoistedIdentifiers);
|
|
123
|
+
({ unhoistedStatements, hoistedIdentifiers } = hoistVariableDeclarations(context, scope, unhoistedStatements));
|
|
124
|
+
allHoistedIdentifiers.push(...hoistedIdentifiers);
|
|
125
|
+
({ unhoistedStatements, hoistedStatements } = hoistImportStatements(scope, unhoistedStatements));
|
|
126
|
+
allHoistedStatments.unshift(...hoistedStatements);
|
|
127
|
+
return {
|
|
128
|
+
statements: unhoistedStatements,
|
|
129
|
+
hoistedStatements: allHoistedStatments,
|
|
130
|
+
hoistedIdentifiers: allHoistedIdentifiers,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
exports.separateHoistedStatements = separateHoistedStatements;
|
|
134
|
+
function performHoisting(context, statements) {
|
|
135
|
+
const result = separateHoistedStatements(context, statements);
|
|
136
|
+
const modifiedStatements = [...result.hoistedStatements, ...result.statements];
|
|
137
|
+
if (result.hoistedIdentifiers.length > 0) {
|
|
138
|
+
modifiedStatements.unshift(lua.createVariableDeclarationStatement(result.hoistedIdentifiers));
|
|
139
|
+
}
|
|
140
|
+
return modifiedStatements;
|
|
116
141
|
}
|
|
117
142
|
exports.performHoisting = performHoisting;
|
|
118
143
|
function shouldHoistSymbol(context, symbolId, scope) {
|
|
119
|
-
|
|
144
|
+
// Always hoist in top-level of switch statements
|
|
145
|
+
if (scope.type === ScopeType.Switch) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
const symbolInfo = (0, symbols_1.getSymbolInfo)(context, symbolId);
|
|
120
149
|
if (!symbolInfo) {
|
|
121
150
|
return false;
|
|
122
151
|
}
|
|
123
|
-
const declaration = typescript_1.getFirstDeclarationInFile(symbolInfo.symbol, context.sourceFile);
|
|
152
|
+
const declaration = (0, typescript_1.getFirstDeclarationInFile)(symbolInfo.symbol, context.sourceFile);
|
|
124
153
|
if (!declaration) {
|
|
125
154
|
return false;
|
|
126
155
|
}
|
|
@@ -129,7 +158,7 @@ function shouldHoistSymbol(context, symbolId, scope) {
|
|
|
129
158
|
}
|
|
130
159
|
if (scope.functionDefinitions) {
|
|
131
160
|
for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) {
|
|
132
|
-
utils_1.assert(functionDefinition.definition);
|
|
161
|
+
(0, utils_1.assert)(functionDefinition.definition);
|
|
133
162
|
const { line, column } = lua.getOriginalPos(functionDefinition.definition);
|
|
134
163
|
if (line !== undefined && column !== undefined) {
|
|
135
164
|
const definitionPos = ts.getPositionOfLineAndCharacter(context.sourceFile, line, column);
|
|
@@ -146,52 +175,60 @@ function shouldHoistSymbol(context, symbolId, scope) {
|
|
|
146
175
|
}
|
|
147
176
|
function hoistVariableDeclarations(context, scope, statements) {
|
|
148
177
|
if (!scope.variableDeclarations) {
|
|
149
|
-
return statements;
|
|
178
|
+
return { unhoistedStatements: statements, hoistedIdentifiers: [] };
|
|
150
179
|
}
|
|
151
|
-
const
|
|
152
|
-
const
|
|
180
|
+
const unhoistedStatements = [...statements];
|
|
181
|
+
const hoistedIdentifiers = [];
|
|
153
182
|
for (const declaration of scope.variableDeclarations) {
|
|
154
183
|
const symbols = declaration.left.map(i => i.symbolId).filter(utils_1.isNonNull);
|
|
155
184
|
if (symbols.some(s => shouldHoistSymbol(context, s, scope))) {
|
|
156
|
-
const index =
|
|
157
|
-
|
|
185
|
+
const index = unhoistedStatements.indexOf(declaration);
|
|
186
|
+
if (index < 0) {
|
|
187
|
+
continue; // statements array may not contain all statements in the scope (switch-case)
|
|
188
|
+
}
|
|
158
189
|
if (declaration.right) {
|
|
159
190
|
const assignment = lua.createAssignmentStatement(declaration.left, declaration.right);
|
|
160
191
|
lua.setNodePosition(assignment, declaration); // Preserve position info for sourcemap
|
|
161
|
-
|
|
192
|
+
unhoistedStatements.splice(index, 1, assignment);
|
|
162
193
|
}
|
|
163
194
|
else {
|
|
164
|
-
|
|
195
|
+
unhoistedStatements.splice(index, 1);
|
|
165
196
|
}
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
else if (scope.type === ScopeType.Switch) {
|
|
169
|
-
utils_1.assert(!declaration.right);
|
|
170
|
-
hoistedLocals.push(...declaration.left);
|
|
197
|
+
hoistedIdentifiers.push(...declaration.left);
|
|
171
198
|
}
|
|
172
199
|
}
|
|
173
|
-
|
|
174
|
-
result.unshift(lua.createVariableDeclarationStatement(hoistedLocals));
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
200
|
+
return { unhoistedStatements, hoistedIdentifiers };
|
|
177
201
|
}
|
|
178
202
|
function hoistFunctionDefinitions(context, scope, statements) {
|
|
179
203
|
if (!scope.functionDefinitions) {
|
|
180
|
-
return statements;
|
|
204
|
+
return { unhoistedStatements: statements, hoistedStatements: [], hoistedIdentifiers: [] };
|
|
181
205
|
}
|
|
182
|
-
const
|
|
183
|
-
const
|
|
206
|
+
const unhoistedStatements = [...statements];
|
|
207
|
+
const hoistedStatements = [];
|
|
208
|
+
const hoistedIdentifiers = [];
|
|
184
209
|
for (const [functionSymbolId, functionDefinition] of scope.functionDefinitions) {
|
|
185
|
-
utils_1.assert(functionDefinition.definition);
|
|
210
|
+
(0, utils_1.assert)(functionDefinition.definition);
|
|
186
211
|
if (shouldHoistSymbol(context, functionSymbolId, scope)) {
|
|
187
|
-
const index =
|
|
188
|
-
|
|
189
|
-
|
|
212
|
+
const index = unhoistedStatements.indexOf(functionDefinition.definition);
|
|
213
|
+
if (index < 0) {
|
|
214
|
+
continue; // statements array may not contain all statements in the scope (switch-case)
|
|
215
|
+
}
|
|
216
|
+
unhoistedStatements.splice(index, 1);
|
|
217
|
+
if (lua.isVariableDeclarationStatement(functionDefinition.definition)) {
|
|
218
|
+
// Separate function definition and variable declaration
|
|
219
|
+
(0, utils_1.assert)(functionDefinition.definition.right);
|
|
220
|
+
hoistedIdentifiers.push(...functionDefinition.definition.left);
|
|
221
|
+
hoistedStatements.push(lua.createAssignmentStatement(functionDefinition.definition.left, functionDefinition.definition.right));
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
hoistedStatements.push(functionDefinition.definition);
|
|
225
|
+
}
|
|
190
226
|
}
|
|
191
227
|
}
|
|
192
|
-
return
|
|
228
|
+
return { unhoistedStatements, hoistedStatements, hoistedIdentifiers };
|
|
193
229
|
}
|
|
194
230
|
function hoistImportStatements(scope, statements) {
|
|
195
|
-
|
|
231
|
+
var _a;
|
|
232
|
+
return { unhoistedStatements: statements, hoistedStatements: (_a = scope.importStatements) !== null && _a !== void 0 ? _a : [] };
|
|
196
233
|
}
|
|
197
234
|
//# 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
|
}
|
|
@@ -14,3 +14,4 @@ export declare function inferAssignedType(context: TransformationContext, expres
|
|
|
14
14
|
export declare function getAllCallSignatures(type: ts.Type): readonly ts.Signature[];
|
|
15
15
|
export declare function isExpressionWithEvaluationEffect(node: ts.Expression): boolean;
|
|
16
16
|
export declare function getFunctionTypeForCall(context: TransformationContext, node: ts.CallExpression): ts.Type | undefined;
|
|
17
|
+
export declare function isConstIdentifier(context: TransformationContext, node: ts.Node): boolean;
|
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.getFirstDeclarationInFile = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
|
|
13
|
+
exports.isConstIdentifier = exports.getFunctionTypeForCall = exports.isExpressionWithEvaluationEffect = exports.getAllCallSignatures = exports.inferAssignedType = exports.hasStandardLibrarySignature = exports.isStandardLibraryType = exports.getFirstDeclarationInFile = exports.findFirstNodeAbove = exports.hasExportEquals = void 0;
|
|
14
14
|
const ts = require("typescript");
|
|
15
15
|
__exportStar(require("./nodes"), exports);
|
|
16
16
|
__exportStar(require("./types"), exports);
|
|
@@ -94,4 +94,19 @@ function getFunctionTypeForCall(context, node) {
|
|
|
94
94
|
return context.checker.getTypeFromTypeNode(typeDeclaration.type);
|
|
95
95
|
}
|
|
96
96
|
exports.getFunctionTypeForCall = getFunctionTypeForCall;
|
|
97
|
+
function isConstIdentifier(context, node) {
|
|
98
|
+
let identifier = node;
|
|
99
|
+
if (ts.isComputedPropertyName(identifier)) {
|
|
100
|
+
identifier = identifier.expression;
|
|
101
|
+
}
|
|
102
|
+
if (!ts.isIdentifier(identifier)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const symbol = context.checker.getSymbolAtLocation(identifier);
|
|
106
|
+
if (!symbol || !symbol.declarations) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return symbol.declarations.some(d => ts.isVariableDeclarationList(d.parent) && (d.parent.flags & ts.NodeFlags.Const) !== 0);
|
|
110
|
+
}
|
|
111
|
+
exports.isConstIdentifier = isConstIdentifier;
|
|
97
112
|
//# sourceMappingURL=index.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
|
*/
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
|
+
import { ExpressionWithThisValue } from "./optional-chaining";
|
|
4
5
|
export declare function transformElementAccessArgument(context: TransformationContext, node: ts.ElementAccessExpression): lua.Expression;
|
|
5
6
|
export declare const transformElementAccessExpression: FunctionVisitor<ts.ElementAccessExpression>;
|
|
7
|
+
export declare function transformElementAccessExpressionWithCapture(context: TransformationContext, node: ts.ElementAccessExpression, thisValueCapture: lua.Identifier | undefined): ExpressionWithThisValue;
|
|
6
8
|
export declare const transformPropertyAccessExpression: FunctionVisitor<ts.PropertyAccessExpression>;
|
|
9
|
+
export declare function transformPropertyAccessExpressionWithCapture(context: TransformationContext, node: ts.PropertyAccessExpression, thisValueCapture: lua.Identifier | undefined): ExpressionWithThisValue;
|
|
7
10
|
export declare const transformQualifiedName: FunctionVisitor<ts.QualifiedName>;
|