typescript-to-lua 1.6.1 → 1.7.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/dist/CompilerOptions.d.ts +1 -0
- package/dist/LuaPrinter.js +1 -0
- package/dist/cli/diagnostics.d.ts +3 -0
- package/dist/cli/diagnostics.js +2 -1
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +47 -11
- package/dist/lualib/ArraySlice.lua +10 -2
- package/dist/lualib/ArraySplice.lua +5 -1
- package/dist/lualib/Generator.lua +8 -1
- package/dist/lualib/ParseFloat.lua +5 -1
- package/dist/lualib/Promise.lua +6 -3
- package/dist/lualib/SparseArraySpread.lua +5 -1
- package/dist/lualib/StringCharCodeAt.lua +5 -1
- package/dist/lualib/lualib_bundle.lua +44 -10
- package/dist/lualib-build/plugin.js +1 -2
- package/dist/measure-performance.d.ts +15 -0
- package/dist/measure-performance.js +83 -0
- package/dist/transformation/builtins/array.js +2 -1
- package/dist/transformation/builtins/function.js +1 -1
- package/dist/transformation/builtins/global.d.ts +1 -1
- package/dist/transformation/builtins/global.js +13 -12
- package/dist/transformation/builtins/index.d.ts +2 -2
- package/dist/transformation/builtins/index.js +87 -89
- package/dist/transformation/builtins/object.d.ts +1 -1
- package/dist/transformation/builtins/object.js +4 -4
- package/dist/transformation/builtins/promise.js +4 -2
- package/dist/transformation/builtins/string.js +2 -0
- package/dist/transformation/context/context.d.ts +15 -0
- package/dist/transformation/context/context.js +66 -24
- package/dist/transformation/context/visitors.d.ts +1 -1
- package/dist/transformation/index.js +6 -5
- package/dist/transformation/utils/annotations.d.ts +1 -17
- package/dist/transformation/utils/annotations.js +48 -88
- package/dist/transformation/utils/assignment-validation.js +27 -23
- package/dist/transformation/utils/diagnostics.d.ts +1 -4
- package/dist/transformation/utils/diagnostics.js +2 -3
- package/dist/transformation/utils/function-context.d.ts +1 -1
- package/dist/transformation/utils/function-context.js +57 -51
- package/dist/transformation/utils/language-extensions.d.ts +57 -51
- package/dist/transformation/utils/language-extensions.js +99 -119
- package/dist/transformation/utils/lualib.d.ts +0 -1
- package/dist/transformation/utils/lualib.js +2 -8
- package/dist/transformation/utils/safe-names.d.ts +1 -1
- package/dist/transformation/utils/safe-names.js +3 -6
- package/dist/transformation/utils/scope.d.ts +0 -2
- package/dist/transformation/utils/scope.js +10 -27
- package/dist/transformation/utils/symbols.d.ts +1 -1
- package/dist/transformation/utils/symbols.js +7 -20
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +2 -1
- package/dist/transformation/utils/typescript/types.d.ts +2 -5
- package/dist/transformation/utils/typescript/types.js +27 -37
- package/dist/transformation/visitors/access.js +1 -4
- package/dist/transformation/visitors/block.js +4 -4
- package/dist/transformation/visitors/call.js +7 -18
- package/dist/transformation/visitors/class/index.js +8 -20
- package/dist/transformation/visitors/class/members/constructor.js +2 -2
- package/dist/transformation/visitors/class/new.js +2 -5
- package/dist/transformation/visitors/class/setup.d.ts +1 -1
- package/dist/transformation/visitors/class/setup.js +4 -4
- package/dist/transformation/visitors/class/utils.d.ts +1 -1
- package/dist/transformation/visitors/class/utils.js +2 -9
- package/dist/transformation/visitors/conditional.js +4 -4
- package/dist/transformation/visitors/function.d.ts +1 -1
- package/dist/transformation/visitors/function.js +8 -16
- package/dist/transformation/visitors/identifier.d.ts +1 -0
- package/dist/transformation/visitors/identifier.js +40 -44
- package/dist/transformation/visitors/language-extensions/call-extension.d.ts +10 -0
- package/dist/transformation/visitors/language-extensions/call-extension.js +23 -0
- package/dist/transformation/visitors/language-extensions/identifier.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/identifier.js +27 -0
- package/dist/transformation/visitors/language-extensions/iterable.d.ts +2 -3
- package/dist/transformation/visitors/language-extensions/iterable.js +21 -22
- package/dist/transformation/visitors/language-extensions/multi.d.ts +0 -1
- package/dist/transformation/visitors/language-extensions/multi.js +10 -24
- package/dist/transformation/visitors/language-extensions/operators.d.ts +2 -5
- package/dist/transformation/visitors/language-extensions/operators.js +89 -96
- package/dist/transformation/visitors/language-extensions/range.js +4 -2
- package/dist/transformation/visitors/language-extensions/table.d.ts +6 -3
- package/dist/transformation/visitors/language-extensions/table.js +46 -75
- package/dist/transformation/visitors/language-extensions/vararg.js +7 -3
- package/dist/transformation/visitors/literal.js +2 -23
- package/dist/transformation/visitors/loops/for-of.js +18 -18
- package/dist/transformation/visitors/loops/utils.js +5 -5
- package/dist/transformation/visitors/namespace.js +5 -14
- package/dist/transformation/visitors/return.js +2 -3
- package/dist/transformation/visitors/sourceFile.js +3 -4
- package/dist/transformation/visitors/spread.js +0 -5
- package/dist/transformation/visitors/switch.js +2 -2
- package/dist/transformation/visitors/variable-declaration.js +1 -1
- package/dist/transpilation/index.js +4 -8
- package/dist/transpilation/plugins.js +3 -0
- package/dist/transpilation/resolve.js +144 -161
- package/dist/transpilation/transpile.js +10 -0
- package/dist/transpilation/transpiler.d.ts +1 -0
- package/dist/transpilation/transpiler.js +18 -5
- package/dist/tstl.js +23 -4
- package/language-extensions/index.d.ts +156 -67
- package/package.json +2 -2
- package/dist/transformation/visitors/language-extensions/index.d.ts +0 -4
- package/dist/transformation/visitors/language-extensions/index.js +0 -17
- package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +0 -5
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +0 -53
|
@@ -5,14 +5,12 @@ const ts = require("typescript");
|
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
8
|
-
const export_1 = require("../utils/export");
|
|
9
8
|
const lualib_1 = require("../utils/lualib");
|
|
10
|
-
const safe_names_1 = require("../utils/safe-names");
|
|
11
9
|
const symbols_1 = require("../utils/symbols");
|
|
12
10
|
const typescript_1 = require("../utils/typescript");
|
|
13
11
|
const function_1 = require("./function");
|
|
14
12
|
const expression_list_1 = require("./expression-list");
|
|
15
|
-
const
|
|
13
|
+
const identifier_1 = require("./identifier");
|
|
16
14
|
// TODO: Move to object-literal.ts?
|
|
17
15
|
function transformPropertyName(context, node) {
|
|
18
16
|
if (ts.isComputedPropertyName(node)) {
|
|
@@ -30,21 +28,7 @@ function transformPropertyName(context, node) {
|
|
|
30
28
|
}
|
|
31
29
|
exports.transformPropertyName = transformPropertyName;
|
|
32
30
|
function createShorthandIdentifier(context, valueSymbol, propertyIdentifier) {
|
|
33
|
-
|
|
34
|
-
const isUnsafeName = valueSymbol
|
|
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;
|
|
38
|
-
let identifier = context.transformExpression(ts.factory.createIdentifier(name));
|
|
39
|
-
lua.setNodeOriginal(identifier, propertyIdentifier);
|
|
40
|
-
if (valueSymbol !== undefined && lua.isIdentifier(identifier)) {
|
|
41
|
-
identifier.symbolId = (0, symbols_1.getSymbolIdOfSymbol)(context, valueSymbol);
|
|
42
|
-
const exportScope = (0, export_1.getSymbolExportScope)(context, valueSymbol);
|
|
43
|
-
if (exportScope) {
|
|
44
|
-
identifier = (0, export_1.createExportedIdentifier)(context, identifier, exportScope);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return identifier;
|
|
31
|
+
return (0, identifier_1.transformIdentifierWithSymbol)(context, propertyIdentifier, valueSymbol);
|
|
48
32
|
}
|
|
49
33
|
exports.createShorthandIdentifier = createShorthandIdentifier;
|
|
50
34
|
const transformNumericLiteralExpression = expression => {
|
|
@@ -56,11 +40,6 @@ const transformNumericLiteralExpression = expression => {
|
|
|
56
40
|
return lua.createNumericLiteral(Number(expression.text), expression);
|
|
57
41
|
};
|
|
58
42
|
const transformObjectLiteralExpression = (expression, context) => {
|
|
59
|
-
const violations = (0, multi_1.findMultiAssignmentViolations)(context, expression);
|
|
60
|
-
if (violations.length > 0) {
|
|
61
|
-
context.diagnostics.push(...violations.map(e => (0, diagnostics_1.invalidMultiFunctionUse)(e)));
|
|
62
|
-
return lua.createNilLiteral(expression);
|
|
63
|
-
}
|
|
64
43
|
const properties = [];
|
|
65
44
|
const initializers = [];
|
|
66
45
|
const keyPrecedingStatements = [];
|
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformForOfStatement = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
|
-
const annotations_1 = require("../../utils/annotations");
|
|
7
|
-
const diagnostics_1 = require("../../utils/diagnostics");
|
|
8
6
|
const lualib_1 = require("../../utils/lualib");
|
|
9
7
|
const typescript_1 = require("../../utils/typescript");
|
|
10
8
|
const iterable_1 = require("../language-extensions/iterable");
|
|
11
|
-
const pairsIterable_1 = require("../language-extensions/pairsIterable");
|
|
12
9
|
const range_1 = require("../language-extensions/range");
|
|
13
10
|
const utils_1 = require("./utils");
|
|
11
|
+
const language_extensions_1 = require("../../utils/language-extensions");
|
|
12
|
+
const utils_2 = require("../../../utils");
|
|
14
13
|
function transformForOfArrayStatement(context, statement, block) {
|
|
15
14
|
const valueVariable = (0, utils_1.transformForInitializer)(context, statement.initializer, block);
|
|
16
15
|
const ipairsCall = lua.createCallExpression(lua.createIdentifier("ipairs"), [
|
|
@@ -28,24 +27,25 @@ const transformForOfStatement = (node, context) => {
|
|
|
28
27
|
if (ts.isCallExpression(node.expression) && (0, range_1.isRangeFunction)(context, node.expression)) {
|
|
29
28
|
return (0, range_1.transformRangeStatement)(context, node, body);
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const iterableExtensionType = (0, language_extensions_1.getIterableExtensionKindForNode)(context, node.expression);
|
|
31
|
+
if (iterableExtensionType) {
|
|
32
|
+
if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Iterable) {
|
|
33
|
+
return (0, iterable_1.transformForOfIterableStatement)(context, node, body);
|
|
34
|
+
}
|
|
35
|
+
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.Pairs) {
|
|
36
|
+
return (0, iterable_1.transformForOfPairsIterableStatement)(context, node, body);
|
|
37
|
+
}
|
|
38
|
+
else if (iterableExtensionType === language_extensions_1.IterableExtensionKind.PairsKey) {
|
|
39
|
+
return (0, iterable_1.transformForOfPairsKeyIterableStatement)(context, node, body);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
(0, utils_2.assertNever)(iterableExtensionType);
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
|
-
|
|
35
|
-
return (0, iterable_1.transformForOfIterableStatement)(context, node, body);
|
|
36
|
-
}
|
|
37
|
-
else if ((0, pairsIterable_1.isPairsIterableExpression)(context, node.expression)) {
|
|
38
|
-
return (0, pairsIterable_1.transformForOfPairsIterableStatement)(context, node, body);
|
|
39
|
-
}
|
|
40
|
-
else if ((0, annotations_1.isLuaIteratorType)(context, node.expression)) {
|
|
41
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node.expression, annotations_1.AnnotationKind.LuaIterator));
|
|
42
|
-
}
|
|
43
|
-
else if ((0, typescript_1.isArrayType)(context, context.checker.getTypeAtLocation(node.expression))) {
|
|
45
|
+
if ((0, typescript_1.isArrayType)(context, context.checker.getTypeAtLocation(node.expression))) {
|
|
44
46
|
return transformForOfArrayStatement(context, node, body);
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
return transformForOfIteratorStatement(context, node, body);
|
|
48
|
-
}
|
|
48
|
+
return transformForOfIteratorStatement(context, node, body);
|
|
49
49
|
};
|
|
50
50
|
exports.transformForOfStatement = transformForOfStatement;
|
|
51
51
|
//# sourceMappingURL=for-of.js.map
|
|
@@ -12,9 +12,9 @@ const block_1 = require("../block");
|
|
|
12
12
|
const identifier_1 = require("../identifier");
|
|
13
13
|
const variable_declaration_1 = require("../variable-declaration");
|
|
14
14
|
function transformLoopBody(context, loop) {
|
|
15
|
-
|
|
15
|
+
context.pushScope(scope_1.ScopeType.Loop);
|
|
16
16
|
const body = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, loop.statement));
|
|
17
|
-
const scope =
|
|
17
|
+
const scope = context.popScope();
|
|
18
18
|
const scopeId = scope.id;
|
|
19
19
|
if (!scope.loopContinued) {
|
|
20
20
|
return body;
|
|
@@ -35,7 +35,7 @@ function getVariableDeclarationBinding(context, node) {
|
|
|
35
35
|
exports.getVariableDeclarationBinding = getVariableDeclarationBinding;
|
|
36
36
|
function transformForInitializer(context, initializer, block) {
|
|
37
37
|
const valueVariable = lua.createIdentifier("____value");
|
|
38
|
-
|
|
38
|
+
context.pushScope(scope_1.ScopeType.LoopInitializer);
|
|
39
39
|
if (ts.isVariableDeclarationList(initializer)) {
|
|
40
40
|
// Declaration of new variable
|
|
41
41
|
const binding = getVariableDeclarationBinding(context, initializer);
|
|
@@ -45,7 +45,7 @@ function transformForInitializer(context, initializer, block) {
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// Single variable declared in for loop
|
|
48
|
-
|
|
48
|
+
context.popScope();
|
|
49
49
|
return (0, identifier_1.transformIdentifier)(context, binding);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -55,7 +55,7 @@ function transformForInitializer(context, initializer, block) {
|
|
|
55
55
|
? (0, destructuring_assignments_1.transformAssignmentPattern)(context, initializer, valueVariable, false)
|
|
56
56
|
: (0, assignments_1.transformAssignment)(context, initializer, valueVariable)));
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
context.popScope();
|
|
59
59
|
return valueVariable;
|
|
60
60
|
}
|
|
61
61
|
exports.transformForInitializer = transformForInitializer;
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformModuleDeclaration = exports.createModuleLocalNameIdentifier = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
|
-
const annotations_1 = require("../utils/annotations");
|
|
7
|
-
const diagnostics_1 = require("../utils/diagnostics");
|
|
8
6
|
const export_1 = require("../utils/export");
|
|
9
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
10
8
|
const safe_names_1 = require("../utils/safe-names");
|
|
@@ -33,16 +31,9 @@ function moduleHasEmittedBody(node) {
|
|
|
33
31
|
}
|
|
34
32
|
return false;
|
|
35
33
|
}
|
|
36
|
-
// Static context -> namespace dictionary keeping the current namespace for each transformation context
|
|
37
|
-
const currentNamespaces = new WeakMap();
|
|
38
34
|
const transformModuleDeclaration = (node, context) => {
|
|
39
35
|
var _a, _b;
|
|
40
|
-
const
|
|
41
|
-
// If phantom namespace elide the declaration and return the body
|
|
42
|
-
if (annotations.has(annotations_1.AnnotationKind.Phantom)) {
|
|
43
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.Phantom));
|
|
44
|
-
}
|
|
45
|
-
const currentNamespace = currentNamespaces.get(context);
|
|
36
|
+
const currentNamespace = context.currentNamespaces;
|
|
46
37
|
const result = [];
|
|
47
38
|
const symbol = context.checker.getSymbolAtLocation(node.name);
|
|
48
39
|
const hasExports = symbol !== undefined && context.checker.getExportsOfModule(symbol).length > 0;
|
|
@@ -75,15 +66,15 @@ const transformModuleDeclaration = (node, context) => {
|
|
|
75
66
|
}
|
|
76
67
|
// Set current namespace for nested NS
|
|
77
68
|
// Keep previous namespace to reset after block transpilation
|
|
78
|
-
currentNamespaces
|
|
69
|
+
context.currentNamespaces = node;
|
|
79
70
|
// Transform moduleblock to block and visit it
|
|
80
71
|
if (moduleHasEmittedBody(node)) {
|
|
81
|
-
|
|
72
|
+
context.pushScope(scope_1.ScopeType.Block);
|
|
82
73
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(ts.isModuleBlock(node.body) ? node.body.statements : node.body));
|
|
83
|
-
|
|
74
|
+
context.popScope();
|
|
84
75
|
result.push(lua.createDoStatement(statements));
|
|
85
76
|
}
|
|
86
|
-
currentNamespaces
|
|
77
|
+
context.currentNamespaces = currentNamespace;
|
|
87
78
|
return result;
|
|
88
79
|
};
|
|
89
80
|
exports.transformModuleDeclaration = transformModuleDeclaration;
|
|
@@ -60,7 +60,6 @@ const transformReturnStatement = (statement, context) => {
|
|
|
60
60
|
};
|
|
61
61
|
exports.transformReturnStatement = transformReturnStatement;
|
|
62
62
|
function createReturnStatement(context, values, node) {
|
|
63
|
-
const results = [...values];
|
|
64
63
|
if ((0, typescript_1.isInAsyncFunction)(node)) {
|
|
65
64
|
return lua.createReturnStatement([
|
|
66
65
|
lua.createCallExpression(lua.createIdentifier("____awaiter_resolve"), [lua.createNilLiteral(), ...values]),
|
|
@@ -68,9 +67,9 @@ function createReturnStatement(context, values, node) {
|
|
|
68
67
|
}
|
|
69
68
|
if (isInTryCatch(context)) {
|
|
70
69
|
// Bubble up explicit return flag and check if we're inside a try/catch block
|
|
71
|
-
|
|
70
|
+
values = [lua.createBooleanLiteral(true), ...values];
|
|
72
71
|
}
|
|
73
|
-
return lua.createReturnStatement(
|
|
72
|
+
return lua.createReturnStatement(values, node);
|
|
74
73
|
}
|
|
75
74
|
exports.createReturnStatement = createReturnStatement;
|
|
76
75
|
function isInTryCatch(context) {
|
|
@@ -5,7 +5,6 @@ const ts = require("typescript");
|
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
8
|
-
const lualib_1 = require("../utils/lualib");
|
|
9
8
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
10
9
|
const scope_1 = require("../utils/scope");
|
|
11
10
|
const typescript_1 = require("../utils/typescript");
|
|
@@ -28,9 +27,9 @@ const transformSourceFileNode = (node, context) => {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
|
|
30
|
+
context.pushScope(scope_1.ScopeType.File);
|
|
32
31
|
statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
33
|
-
|
|
32
|
+
context.popScope();
|
|
34
33
|
if (context.isModule) {
|
|
35
34
|
// If export equals was not used. Create the exports table.
|
|
36
35
|
// local ____exports = {}
|
|
@@ -42,7 +41,7 @@ const transformSourceFileNode = (node, context) => {
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
const trivia = (_b = (_a = node.getFullText().match(/^#!.*\r?\n/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "";
|
|
45
|
-
return lua.createFile(statements,
|
|
44
|
+
return lua.createFile(statements, context.usedLuaLibFeatures, trivia, node);
|
|
46
45
|
};
|
|
47
46
|
exports.transformSourceFileNode = transformSourceFileNode;
|
|
48
47
|
//# sourceMappingURL=sourceFile.js.map
|
|
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformSpreadElement = exports.isOptimizedVarArgSpread = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
|
-
const annotations_1 = require("../utils/annotations");
|
|
7
6
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
8
7
|
const lualib_1 = require("../utils/lualib");
|
|
9
8
|
const scope_1 = require("../utils/scope");
|
|
10
9
|
const typescript_1 = require("../utils/typescript");
|
|
11
10
|
const multi_1 = require("./language-extensions/multi");
|
|
12
|
-
const diagnostics_1 = require("../utils/diagnostics");
|
|
13
11
|
const vararg_1 = require("./language-extensions/vararg");
|
|
14
12
|
function isOptimizedVarArgSpread(context, symbol, identifier) {
|
|
15
13
|
var _a;
|
|
@@ -53,9 +51,6 @@ exports.isOptimizedVarArgSpread = isOptimizedVarArgSpread;
|
|
|
53
51
|
const transformSpreadElement = (node, context) => {
|
|
54
52
|
const tsInnerExpression = ts.skipOuterExpressions(node.expression);
|
|
55
53
|
if (ts.isIdentifier(tsInnerExpression)) {
|
|
56
|
-
if ((0, annotations_1.isVarargType)(context, tsInnerExpression)) {
|
|
57
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.Vararg));
|
|
58
|
-
}
|
|
59
54
|
const symbol = context.checker.getSymbolAtLocation(tsInnerExpression);
|
|
60
55
|
if (symbol && isOptimizedVarArgSpread(context, symbol, tsInnerExpression)) {
|
|
61
56
|
return lua.createDotsLiteral(node);
|
|
@@ -39,7 +39,7 @@ const coalesceCondition = (condition, conditionPrecedingStatements, switchVariab
|
|
|
39
39
|
return [[...conditionPrecedingStatements, ...precedingStatements], comparison];
|
|
40
40
|
};
|
|
41
41
|
const transformSwitchStatement = (statement, context) => {
|
|
42
|
-
const scope =
|
|
42
|
+
const scope = context.pushScope(scope_1.ScopeType.Switch);
|
|
43
43
|
// Give the switch and condition accumulator a unique name to prevent nested switches from acting up.
|
|
44
44
|
const switchName = `____switch${scope.id}`;
|
|
45
45
|
const conditionName = `____cond${scope.id}`;
|
|
@@ -158,7 +158,7 @@ const transformSwitchStatement = (statement, context) => {
|
|
|
158
158
|
if (hoistedIdentifiers.length > 0) {
|
|
159
159
|
statements.unshift(lua.createVariableDeclarationStatement(hoistedIdentifiers));
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
context.popScope();
|
|
162
162
|
// Add the switch expression after hoisting
|
|
163
163
|
const expression = context.transformExpression(statement.expression);
|
|
164
164
|
statements.unshift(lua.createVariableDeclarationStatement(switchVariable, expression));
|
|
@@ -201,7 +201,7 @@ function transformVariableDeclaration(context, statement) {
|
|
|
201
201
|
// Skip named function expressions because they will have been wrapped already
|
|
202
202
|
if (ts.isFunctionExpression(initializer) && initializer.name)
|
|
203
203
|
return false;
|
|
204
|
-
return (0, function_1.isFunctionTypeWithProperties)(context.checker.getTypeAtLocation(statement.name));
|
|
204
|
+
return (0, function_1.isFunctionTypeWithProperties)(context, context.checker.getTypeAtLocation(statement.name));
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
exports.transformVariableDeclaration = transformVariableDeclaration;
|
|
@@ -26,11 +26,9 @@ __exportStar(require("./transpile"), exports);
|
|
|
26
26
|
__exportStar(require("./transpiler"), exports);
|
|
27
27
|
function transpileFiles(rootNames, options = {}, writeFile) {
|
|
28
28
|
const program = ts.createProgram(rootNames, options);
|
|
29
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
29
30
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new transpiler_1.Transpiler().emit({ program, writeFile });
|
|
30
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
31
|
-
...ts.getPreEmitDiagnostics(program),
|
|
32
|
-
...transpileDiagnostics,
|
|
33
|
-
]);
|
|
31
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
34
32
|
return { diagnostics: [...diagnostics], emitSkipped };
|
|
35
33
|
}
|
|
36
34
|
exports.transpileFiles = transpileFiles;
|
|
@@ -85,12 +83,10 @@ function createVirtualProgram(input, options = {}) {
|
|
|
85
83
|
exports.createVirtualProgram = createVirtualProgram;
|
|
86
84
|
function transpileVirtualProject(files, options = {}) {
|
|
87
85
|
const program = createVirtualProgram(files, options);
|
|
86
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
88
87
|
const collector = (0, output_collector_1.createEmitOutputCollector)();
|
|
89
88
|
const { diagnostics: transpileDiagnostics } = new transpiler_1.Transpiler().emit({ program, writeFile: collector.writeFile });
|
|
90
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
91
|
-
...ts.getPreEmitDiagnostics(program),
|
|
92
|
-
...transpileDiagnostics,
|
|
93
|
-
]);
|
|
89
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
94
90
|
return { diagnostics: [...diagnostics], transpiledFiles: collector.files };
|
|
95
91
|
}
|
|
96
92
|
exports.transpileVirtualProject = transpileVirtualProject;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPlugins = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
+
const performance = require("../measure-performance");
|
|
5
6
|
function getPlugins(program) {
|
|
6
7
|
var _a;
|
|
8
|
+
performance.startSection("getPlugins");
|
|
7
9
|
const diagnostics = [];
|
|
8
10
|
const pluginsFromOptions = [];
|
|
9
11
|
const options = program.getCompilerOptions();
|
|
@@ -20,6 +22,7 @@ function getPlugins(program) {
|
|
|
20
22
|
if (options.tstlVerbose) {
|
|
21
23
|
console.log(`Loaded ${pluginsFromOptions.length} plugins`);
|
|
22
24
|
}
|
|
25
|
+
performance.endSection("getPlugins");
|
|
23
26
|
return { diagnostics, plugins: pluginsFromOptions };
|
|
24
27
|
}
|
|
25
28
|
exports.getPlugins = getPlugins;
|