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
|
@@ -14,7 +14,7 @@ const transformSourceFileNode = (node, context) => {
|
|
|
14
14
|
if (node.flags & ts.NodeFlags.JsonFile) {
|
|
15
15
|
const [statement] = node.statements;
|
|
16
16
|
if (statement) {
|
|
17
|
-
utils_1.assert(ts.isExpressionStatement(statement));
|
|
17
|
+
(0, utils_1.assert)(ts.isExpressionStatement(statement));
|
|
18
18
|
statements.push(lua.createReturnStatement([context.transformExpression(statement.expression)]));
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
@@ -25,21 +25,21 @@ const transformSourceFileNode = (node, context) => {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
scope_1.pushScope(context, scope_1.ScopeType.File);
|
|
29
|
-
statements = scope_1.performHoisting(context, context.transformStatements(node.statements));
|
|
30
|
-
scope_1.popScope(context);
|
|
28
|
+
(0, scope_1.pushScope)(context, scope_1.ScopeType.File);
|
|
29
|
+
statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
30
|
+
(0, scope_1.popScope)(context);
|
|
31
31
|
if (context.isModule) {
|
|
32
32
|
// If export equals was not used. Create the exports table.
|
|
33
33
|
// local ____exports = {}
|
|
34
|
-
if (!typescript_1.hasExportEquals(node)) {
|
|
35
|
-
statements.unshift(lua.createVariableDeclarationStatement(lua_ast_1.createExportsIdentifier(), lua.createTableExpression()));
|
|
34
|
+
if (!(0, typescript_1.hasExportEquals)(node)) {
|
|
35
|
+
statements.unshift(lua.createVariableDeclarationStatement((0, lua_ast_1.createExportsIdentifier)(), lua.createTableExpression()));
|
|
36
36
|
}
|
|
37
37
|
// return ____exports
|
|
38
|
-
statements.push(lua.createReturnStatement([lua_ast_1.createExportsIdentifier()]));
|
|
38
|
+
statements.push(lua.createReturnStatement([(0, lua_ast_1.createExportsIdentifier)()]));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
const trivia = (_b = (_a = node.getFullText().match(/^#!.*\r?\n/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "";
|
|
42
|
-
return lua.createFile(statements, lualib_1.getUsedLuaLibFeatures(context), trivia, node);
|
|
42
|
+
return lua.createFile(statements, (0, lualib_1.getUsedLuaLibFeatures)(context), trivia, node);
|
|
43
43
|
};
|
|
44
44
|
exports.transformSourceFileNode = transformSourceFileNode;
|
|
45
45
|
//# sourceMappingURL=sourceFile.js.map
|
|
@@ -17,16 +17,16 @@ function isOptimizedVarArgSpread(context, symbol, identifier) {
|
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
// Walk up, stopping at any scope types which could stop optimization
|
|
20
|
-
const scope = scope_1.findScope(context, scope_1.ScopeType.Function | scope_1.ScopeType.Try | scope_1.ScopeType.Catch | scope_1.ScopeType.File);
|
|
20
|
+
const scope = (0, scope_1.findScope)(context, scope_1.ScopeType.Function | scope_1.ScopeType.Try | scope_1.ScopeType.Catch | scope_1.ScopeType.File);
|
|
21
21
|
if (!scope) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
// $vararg global constant
|
|
25
|
-
if (vararg_1.isGlobalVarargConstant(context, symbol, scope)) {
|
|
25
|
+
if ((0, vararg_1.isGlobalVarargConstant)(context, symbol, scope)) {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
// Scope must be a function scope associated with a real ts function
|
|
29
|
-
if (!scope_1.isFunctionScopeWithDefinition(scope)) {
|
|
29
|
+
if (!(0, scope_1.isFunctionScopeWithDefinition)(scope)) {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
// Scope cannot be an async function
|
|
@@ -39,11 +39,11 @@ function isOptimizedVarArgSpread(context, symbol, identifier) {
|
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
// De-optimize if already referenced outside of a spread, as the array may have been modified
|
|
42
|
-
if (scope_1.hasReferencedSymbol(context, scope, symbol)) {
|
|
42
|
+
if ((0, scope_1.hasReferencedSymbol)(context, scope, symbol)) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
45
|
// De-optimize if a function is being hoisted from below to above, as it may have modified the array
|
|
46
|
-
if (scope_1.hasReferencedUndefinedLocalFunction(context, scope)) {
|
|
46
|
+
if ((0, scope_1.hasReferencedUndefinedLocalFunction)(context, scope)) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
return true;
|
|
@@ -52,8 +52,8 @@ exports.isOptimizedVarArgSpread = isOptimizedVarArgSpread;
|
|
|
52
52
|
// TODO: Currently it's also used as an array member
|
|
53
53
|
const transformSpreadElement = (node, context) => {
|
|
54
54
|
if (ts.isIdentifier(node.expression)) {
|
|
55
|
-
if (annotations_1.isVarargType(context, node.expression)) {
|
|
56
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.Vararg));
|
|
55
|
+
if ((0, annotations_1.isVarargType)(context, node.expression)) {
|
|
56
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.Vararg));
|
|
57
57
|
}
|
|
58
58
|
const symbol = context.checker.getSymbolAtLocation(node.expression);
|
|
59
59
|
if (symbol && isOptimizedVarArgSpread(context, symbol, node.expression)) {
|
|
@@ -61,13 +61,13 @@ const transformSpreadElement = (node, context) => {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const innerExpression = context.transformExpression(node.expression);
|
|
64
|
-
if (multi_1.isMultiReturnCall(context, node.expression))
|
|
64
|
+
if ((0, multi_1.isMultiReturnCall)(context, node.expression))
|
|
65
65
|
return innerExpression;
|
|
66
66
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
67
|
-
if (typescript_1.isArrayType(context, type)) {
|
|
68
|
-
return lua_ast_1.createUnpackCall(context, innerExpression, node);
|
|
67
|
+
if ((0, typescript_1.isArrayType)(context, type)) {
|
|
68
|
+
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
69
69
|
}
|
|
70
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.Spread, node, innerExpression);
|
|
70
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Spread, node, innerExpression);
|
|
71
71
|
};
|
|
72
72
|
exports.transformSpreadElement = transformSpreadElement;
|
|
73
73
|
//# sourceMappingURL=spread.js.map
|
|
@@ -27,7 +27,7 @@ const coalesceCondition = (condition, switchVariable, expression, context) => {
|
|
|
27
27
|
return lua.createBinaryExpression(switchVariable, context.transformExpression(expression), lua.SyntaxKind.EqualityOperator);
|
|
28
28
|
};
|
|
29
29
|
const transformSwitchStatement = (statement, context) => {
|
|
30
|
-
const scope = scope_1.pushScope(context, scope_1.ScopeType.Switch);
|
|
30
|
+
const scope = (0, scope_1.pushScope)(context, scope_1.ScopeType.Switch);
|
|
31
31
|
// Give the switch and condition accumulator a unique name to prevent nested switches from acting up.
|
|
32
32
|
const switchName = `____switch${scope.id}`;
|
|
33
33
|
const conditionName = `____cond${scope.id}`;
|
|
@@ -35,16 +35,22 @@ const transformSwitchStatement = (statement, context) => {
|
|
|
35
35
|
const conditionVariable = lua.createIdentifier(conditionName);
|
|
36
36
|
// If the switch only has a default clause, wrap it in a single do.
|
|
37
37
|
// Otherwise, we need to generate a set of if statements to emulate the switch.
|
|
38
|
-
|
|
38
|
+
const statements = [];
|
|
39
|
+
const hoistedStatements = [];
|
|
40
|
+
const hoistedIdentifiers = [];
|
|
39
41
|
const clauses = statement.caseBlock.clauses;
|
|
40
42
|
if (clauses.length === 1 && ts.isDefaultClause(clauses[0])) {
|
|
41
43
|
const defaultClause = clauses[0].statements;
|
|
42
44
|
if (defaultClause.length) {
|
|
43
|
-
statements
|
|
45
|
+
const { statements: defaultStatements, hoistedStatements: defaultHoistedStatements, hoistedIdentifiers: defaultHoistedIdentifiers, } = (0, scope_1.separateHoistedStatements)(context, context.transformStatements(defaultClause));
|
|
46
|
+
hoistedStatements.push(...defaultHoistedStatements);
|
|
47
|
+
hoistedIdentifiers.push(...defaultHoistedIdentifiers);
|
|
48
|
+
statements.push(lua.createDoStatement(defaultStatements));
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
else {
|
|
47
52
|
// Build up the condition for each if statement
|
|
53
|
+
let defaultTransformed = false;
|
|
48
54
|
let isInitialCondition = true;
|
|
49
55
|
let condition = undefined;
|
|
50
56
|
for (let i = 0; i < clauses.length; i++) {
|
|
@@ -86,10 +92,16 @@ const transformSwitchStatement = (statement, context) => {
|
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
// Transform the clause and append the final break statement if necessary
|
|
89
|
-
const clauseStatements = context.transformStatements(clause.statements);
|
|
95
|
+
const { statements: clauseStatements, hoistedStatements: clauseHoistedStatements, hoistedIdentifiers: clauseHoistedIdentifiers, } = (0, scope_1.separateHoistedStatements)(context, context.transformStatements(clause.statements));
|
|
90
96
|
if (i === clauses.length - 1 && !containsBreakOrReturn(clause.statements)) {
|
|
91
97
|
clauseStatements.push(lua.createBreakStatement());
|
|
92
98
|
}
|
|
99
|
+
hoistedStatements.push(...clauseHoistedStatements);
|
|
100
|
+
hoistedIdentifiers.push(...clauseHoistedIdentifiers);
|
|
101
|
+
// Remember that we transformed default clause so we don't duplicate hoisted statements later
|
|
102
|
+
if (ts.isDefaultClause(clause)) {
|
|
103
|
+
defaultTransformed = true;
|
|
104
|
+
}
|
|
93
105
|
// Push if statement for case
|
|
94
106
|
statements.push(lua.createIfStatement(conditionVariable, lua.createBlock(clauseStatements)));
|
|
95
107
|
// Clear condition for next clause
|
|
@@ -101,11 +113,19 @@ const transformSwitchStatement = (statement, context) => {
|
|
|
101
113
|
if (start >= 0) {
|
|
102
114
|
// Find the last clause that we can fallthrough to
|
|
103
115
|
const end = clauses.findIndex((clause, index) => index >= start && containsBreakOrReturn(clause.statements));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
.
|
|
116
|
+
const { statements: defaultStatements, hoistedStatements: defaultHoistedStatements, hoistedIdentifiers: defaultHoistedIdentifiers, } = (0, scope_1.separateHoistedStatements)(context, context.transformStatements(clauses[start].statements));
|
|
117
|
+
// Only push hoisted statements if this is the first time we're transforming the default clause
|
|
118
|
+
if (!defaultTransformed) {
|
|
119
|
+
hoistedStatements.push(...defaultHoistedStatements);
|
|
120
|
+
hoistedIdentifiers.push(...defaultHoistedIdentifiers);
|
|
121
|
+
}
|
|
122
|
+
// Combine the fallthrough statements
|
|
123
|
+
for (const clause of clauses.slice(start + 1, end >= 0 ? end + 1 : undefined)) {
|
|
124
|
+
let statements = context.transformStatements(clause.statements);
|
|
125
|
+
// Drop hoisted statements as they were already added when clauses were initially transformed above
|
|
126
|
+
({ statements } = (0, scope_1.separateHoistedStatements)(context, statements));
|
|
127
|
+
defaultStatements.push(...statements);
|
|
128
|
+
}
|
|
109
129
|
// Add the default clause if it has any statements
|
|
110
130
|
// The switch will always break on the final clause and skip execution if valid to do so
|
|
111
131
|
if (defaultStatements.length) {
|
|
@@ -114,8 +134,11 @@ const transformSwitchStatement = (statement, context) => {
|
|
|
114
134
|
}
|
|
115
135
|
}
|
|
116
136
|
// Hoist the variable, function, and import statements to the top of the switch
|
|
117
|
-
statements
|
|
118
|
-
|
|
137
|
+
statements.unshift(...hoistedStatements);
|
|
138
|
+
if (hoistedIdentifiers.length > 0) {
|
|
139
|
+
statements.unshift(lua.createVariableDeclarationStatement(hoistedIdentifiers));
|
|
140
|
+
}
|
|
141
|
+
(0, scope_1.popScope)(context);
|
|
119
142
|
// Add the switch expression after hoisting
|
|
120
143
|
const expression = context.transformExpression(statement.expression);
|
|
121
144
|
statements.unshift(lua.createVariableDeclarationStatement(switchVariable, expression));
|
|
@@ -24,11 +24,11 @@ const transformTemplateExpression = (node, context) => {
|
|
|
24
24
|
for (const span of node.templateSpans) {
|
|
25
25
|
const expression = context.transformExpression(span.expression);
|
|
26
26
|
const spanType = context.checker.getTypeAtLocation(span.expression);
|
|
27
|
-
if (types_1.isStringType(context, spanType)) {
|
|
27
|
+
if ((0, types_1.isStringType)(context, spanType)) {
|
|
28
28
|
parts.push(expression);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
parts.push(lua_ast_1.wrapInToStringForConcat(expression));
|
|
31
|
+
parts.push((0, lua_ast_1.wrapInToStringForConcat)(expression));
|
|
32
32
|
}
|
|
33
33
|
const text = span.literal.text;
|
|
34
34
|
if (text.length > 0) {
|
|
@@ -65,12 +65,12 @@ const transformTaggedTemplateExpression = (expression, context) => {
|
|
|
65
65
|
// Evaluate if there is a self parameter to be used.
|
|
66
66
|
const signature = context.checker.getResolvedSignature(expression);
|
|
67
67
|
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
68
|
-
const useSelfParameter = signatureDeclaration && function_context_1.getDeclarationContextType(context, signatureDeclaration) !== function_context_1.ContextType.Void;
|
|
68
|
+
const useSelfParameter = signatureDeclaration && (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void;
|
|
69
69
|
if (useSelfParameter) {
|
|
70
|
-
return call_1.transformContextualCallExpression(context, expression, expressions, signature);
|
|
70
|
+
return (0, call_1.transformContextualCallExpression)(context, expression, expressions, signature);
|
|
71
71
|
}
|
|
72
72
|
// Argument evaluation.
|
|
73
|
-
const callArguments = call_1.transformArguments(context, expressions, signature);
|
|
73
|
+
const callArguments = (0, call_1.transformArguments)(context, expressions, signature);
|
|
74
74
|
const leftHandSideExpression = context.transformExpression(expression.tag);
|
|
75
75
|
return lua.createCallExpression(leftHandSideExpression, callArguments);
|
|
76
76
|
};
|
|
@@ -8,7 +8,7 @@ const lualib_1 = require("../utils/lualib");
|
|
|
8
8
|
const binary_expression_1 = require("./binary-expression");
|
|
9
9
|
const transformTypeOfExpression = (node, context) => {
|
|
10
10
|
const innerExpression = context.transformExpression(node.expression);
|
|
11
|
-
return lualib_1.transformLuaLibFunction(context, LuaLib_1.LuaLibFeature.TypeOf, node, innerExpression);
|
|
11
|
+
return (0, lualib_1.transformLuaLibFunction)(context, LuaLib_1.LuaLibFeature.TypeOf, node, innerExpression);
|
|
12
12
|
};
|
|
13
13
|
exports.transformTypeOfExpression = transformTypeOfExpression;
|
|
14
14
|
function transformTypeOfBinaryExpression(context, node) {
|
|
@@ -43,7 +43,7 @@ function transformTypeOfBinaryExpression(context, node) {
|
|
|
43
43
|
}
|
|
44
44
|
const innerExpression = context.transformExpression(typeOfExpression.expression);
|
|
45
45
|
const typeCall = lua.createCallExpression(lua.createIdentifier("type"), [innerExpression], typeOfExpression);
|
|
46
|
-
return binary_expression_1.transformBinaryOperation(context, typeCall, comparedExpression, operator, node);
|
|
46
|
+
return (0, binary_expression_1.transformBinaryOperation)(context, typeCall, comparedExpression, operator, node);
|
|
47
47
|
}
|
|
48
48
|
exports.transformTypeOfBinaryExpression = transformTypeOfBinaryExpression;
|
|
49
49
|
//# sourceMappingURL=typeof.js.map
|
|
@@ -5,7 +5,7 @@ const ts = require("typescript");
|
|
|
5
5
|
const assignment_validation_1 = require("../utils/assignment-validation");
|
|
6
6
|
const transformAssertionExpression = (expression, context) => {
|
|
7
7
|
if (!ts.isConstTypeReference(expression.type)) {
|
|
8
|
-
assignment_validation_1.validateAssignment(context, expression, context.checker.getTypeAtLocation(expression.expression), context.checker.getTypeAtLocation(expression.type));
|
|
8
|
+
(0, assignment_validation_1.validateAssignment)(context, expression, context.checker.getTypeAtLocation(expression.expression), context.checker.getTypeAtLocation(expression.type));
|
|
9
9
|
}
|
|
10
10
|
return context.transformExpression(expression.expression);
|
|
11
11
|
};
|
|
@@ -12,32 +12,32 @@ function transformUnaryExpressionStatement(context, node) {
|
|
|
12
12
|
(expression.operator === ts.SyntaxKind.PlusPlusToken || expression.operator === ts.SyntaxKind.MinusMinusToken)) {
|
|
13
13
|
// ++i, --i
|
|
14
14
|
const replacementOperator = expression.operator === ts.SyntaxKind.PlusPlusToken ? ts.SyntaxKind.PlusToken : ts.SyntaxKind.MinusToken;
|
|
15
|
-
return compound_1.transformCompoundAssignmentStatement(context, expression, expression.operand, ts.factory.createNumericLiteral(1), replacementOperator);
|
|
15
|
+
return (0, compound_1.transformCompoundAssignmentStatement)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), replacementOperator);
|
|
16
16
|
}
|
|
17
17
|
else if (ts.isPostfixUnaryExpression(expression)) {
|
|
18
18
|
// i++, i--
|
|
19
19
|
const replacementOperator = expression.operator === ts.SyntaxKind.PlusPlusToken ? ts.SyntaxKind.PlusToken : ts.SyntaxKind.MinusToken;
|
|
20
|
-
return compound_1.transformCompoundAssignmentStatement(context, expression, expression.operand, ts.factory.createNumericLiteral(1), replacementOperator);
|
|
20
|
+
return (0, compound_1.transformCompoundAssignmentStatement)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), replacementOperator);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.transformUnaryExpressionStatement = transformUnaryExpressionStatement;
|
|
24
24
|
const transformPostfixUnaryExpression = (expression, context) => {
|
|
25
25
|
switch (expression.operator) {
|
|
26
26
|
case ts.SyntaxKind.PlusPlusToken:
|
|
27
|
-
return compound_1.transformCompoundAssignmentExpression(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.PlusToken, true);
|
|
27
|
+
return (0, compound_1.transformCompoundAssignmentExpression)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.PlusToken, true);
|
|
28
28
|
case ts.SyntaxKind.MinusMinusToken:
|
|
29
|
-
return compound_1.transformCompoundAssignmentExpression(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.MinusToken, true);
|
|
29
|
+
return (0, compound_1.transformCompoundAssignmentExpression)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.MinusToken, true);
|
|
30
30
|
default:
|
|
31
|
-
utils_1.assertNever(expression.operator);
|
|
31
|
+
(0, utils_1.assertNever)(expression.operator);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
exports.transformPostfixUnaryExpression = transformPostfixUnaryExpression;
|
|
35
35
|
const transformPrefixUnaryExpression = (expression, context) => {
|
|
36
36
|
switch (expression.operator) {
|
|
37
37
|
case ts.SyntaxKind.PlusPlusToken:
|
|
38
|
-
return compound_1.transformCompoundAssignmentExpression(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.PlusToken, false);
|
|
38
|
+
return (0, compound_1.transformCompoundAssignmentExpression)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.PlusToken, false);
|
|
39
39
|
case ts.SyntaxKind.MinusMinusToken:
|
|
40
|
-
return compound_1.transformCompoundAssignmentExpression(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.MinusToken, false);
|
|
40
|
+
return (0, compound_1.transformCompoundAssignmentExpression)(context, expression, expression.operand, ts.factory.createNumericLiteral(1), ts.SyntaxKind.MinusToken, false);
|
|
41
41
|
case ts.SyntaxKind.PlusToken:
|
|
42
42
|
// TODO: Wrap with `Number`
|
|
43
43
|
return context.transformExpression(expression.operand);
|
|
@@ -46,9 +46,9 @@ const transformPrefixUnaryExpression = (expression, context) => {
|
|
|
46
46
|
case ts.SyntaxKind.ExclamationToken:
|
|
47
47
|
return lua.createUnaryExpression(context.transformExpression(expression.operand), lua.SyntaxKind.NotOperator);
|
|
48
48
|
case ts.SyntaxKind.TildeToken:
|
|
49
|
-
return bit_1.transformUnaryBitOperation(context, expression, context.transformExpression(expression.operand), lua.SyntaxKind.BitwiseNotOperator);
|
|
49
|
+
return (0, bit_1.transformUnaryBitOperation)(context, expression, context.transformExpression(expression.operand), lua.SyntaxKind.BitwiseNotOperator);
|
|
50
50
|
default:
|
|
51
|
-
utils_1.assertNever(expression.operator);
|
|
51
|
+
(0, utils_1.assertNever)(expression.operator);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
exports.transformPrefixUnaryExpression = transformPrefixUnaryExpression;
|
|
@@ -17,16 +17,16 @@ function transformArrayBindingElement(context, name) {
|
|
|
17
17
|
return lua.createAnonymousIdentifier(name);
|
|
18
18
|
}
|
|
19
19
|
else if (ts.isIdentifier(name)) {
|
|
20
|
-
return identifier_1.transformIdentifier(context, name);
|
|
20
|
+
return (0, identifier_1.transformIdentifier)(context, name);
|
|
21
21
|
}
|
|
22
22
|
else if (ts.isBindingElement(name)) {
|
|
23
23
|
// TODO: It should always be true when called from `transformVariableDeclaration`,
|
|
24
24
|
// but could be false from `transformForOfLuaIteratorStatement`.
|
|
25
|
-
utils_1.assert(ts.isIdentifier(name.name));
|
|
26
|
-
return identifier_1.transformIdentifier(context, name.name);
|
|
25
|
+
(0, utils_1.assert)(ts.isIdentifier(name.name));
|
|
26
|
+
return (0, identifier_1.transformIdentifier)(context, name.name);
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
utils_1.assertNever(name);
|
|
29
|
+
(0, utils_1.assertNever)(name);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.transformArrayBindingElement = transformArrayBindingElement;
|
|
@@ -48,11 +48,11 @@ function transformBindingPattern(context, pattern, table, propertyAccessStack =
|
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
50
|
// Build the path to the table
|
|
51
|
-
const tableExpression = propertyAccessStack.reduce((path, property) => lua.createTableIndexExpression(path, literal_1.transformPropertyName(context, property)), table);
|
|
51
|
+
const tableExpression = propertyAccessStack.reduce((path, property) => lua.createTableIndexExpression(path, (0, literal_1.transformPropertyName)(context, property)), table);
|
|
52
52
|
// The identifier of the new variable
|
|
53
|
-
const variableName = identifier_1.transformIdentifier(context, element.name);
|
|
53
|
+
const variableName = (0, identifier_1.transformIdentifier)(context, element.name);
|
|
54
54
|
// The field to extract
|
|
55
|
-
const propertyName = literal_1.transformPropertyName(context, (_a = element.propertyName) !== null && _a !== void 0 ? _a : element.name);
|
|
55
|
+
const propertyName = (0, literal_1.transformPropertyName)(context, (_a = element.propertyName) !== null && _a !== void 0 ? _a : element.name);
|
|
56
56
|
let expression;
|
|
57
57
|
if (element.dotDotDotToken) {
|
|
58
58
|
if (index !== pattern.elements.length - 1) {
|
|
@@ -78,18 +78,18 @@ function transformBindingPattern(context, pattern, table, propertyAccessStack =
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
const excludedPropertiesTable = excludedProperties.map(e => lua.createTableFieldExpression(lua.createBooleanLiteral(true), lua.createStringLiteral(e.text, e)));
|
|
81
|
-
expression = lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ObjectRest, undefined, tableExpression, lua.createTableExpression(excludedPropertiesTable));
|
|
81
|
+
expression = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ObjectRest, undefined, tableExpression, lua.createTableExpression(excludedPropertiesTable));
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
expression = lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ArraySlice, undefined, tableExpression, lua.createNumericLiteral(index));
|
|
84
|
+
expression = (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySlice, undefined, tableExpression, lua.createNumericLiteral(index));
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
88
|
expression = lua.createTableIndexExpression(tableExpression, ts.isObjectBindingPattern(pattern) ? propertyName : lua.createNumericLiteral(index + 1));
|
|
89
89
|
}
|
|
90
|
-
result.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, variableName, expression));
|
|
90
|
+
result.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, variableName, expression));
|
|
91
91
|
if (element.initializer) {
|
|
92
|
-
const identifier = export_1.addExportToIdentifier(context, variableName);
|
|
92
|
+
const identifier = (0, export_1.addExportToIdentifier)(context, variableName);
|
|
93
93
|
result.push(lua.createIfStatement(lua.createBinaryExpression(identifier, lua.createNilLiteral(), lua.SyntaxKind.EqualityOperator), lua.createBlock([
|
|
94
94
|
lua.createAssignmentStatement(identifier, context.transformExpression(element.initializer)),
|
|
95
95
|
])));
|
|
@@ -106,15 +106,15 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
|
|
|
106
106
|
if (ts.isObjectBindingPattern(bindingPattern) || bindingPattern.elements.some(isComplexBindingElement)) {
|
|
107
107
|
let table;
|
|
108
108
|
if (initializer !== undefined && ts.isIdentifier(initializer)) {
|
|
109
|
-
table = identifier_1.transformIdentifier(context, initializer);
|
|
109
|
+
table = (0, identifier_1.transformIdentifier)(context, initializer);
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
112
|
// Contain the expression in a temporary variable
|
|
113
113
|
table = lua.createAnonymousIdentifier();
|
|
114
114
|
if (initializer) {
|
|
115
115
|
let expression = context.transformExpression(initializer);
|
|
116
|
-
if (multi_1.isMultiReturnCall(context, initializer)) {
|
|
117
|
-
expression = lua_ast_1.wrapInTable(expression);
|
|
116
|
+
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
117
|
+
expression = (0, lua_ast_1.wrapInTable)(expression);
|
|
118
118
|
}
|
|
119
119
|
statements.push(lua.createVariableDeclarationStatement(table, expression));
|
|
120
120
|
}
|
|
@@ -126,30 +126,30 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
|
|
|
126
126
|
? bindingPattern.elements.map(e => transformArrayBindingElement(context, e))
|
|
127
127
|
: lua.createAnonymousIdentifier();
|
|
128
128
|
if (initializer) {
|
|
129
|
-
if (multi_1.isMultiReturnCall(context, initializer)) {
|
|
129
|
+
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
130
130
|
// Don't unpack LuaMultiReturn functions
|
|
131
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, context.transformExpression(initializer), initializer));
|
|
131
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, context.transformExpression(initializer), initializer));
|
|
132
132
|
}
|
|
133
133
|
else if (ts.isArrayLiteralExpression(initializer)) {
|
|
134
134
|
// Don't unpack array literals
|
|
135
135
|
const values = initializer.elements.length > 0
|
|
136
136
|
? initializer.elements.map(e => context.transformExpression(e))
|
|
137
137
|
: lua.createNilLiteral();
|
|
138
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, values, initializer));
|
|
138
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, values, initializer));
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
141
|
// local vars = this.transpileDestructingAssignmentValue(node.initializer);
|
|
142
|
-
const unpackedInitializer = lua_ast_1.createUnpackCall(context, context.transformExpression(initializer), initializer);
|
|
143
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, unpackedInitializer, initializer));
|
|
142
|
+
const unpackedInitializer = (0, lua_ast_1.createUnpackCall)(context, context.transformExpression(initializer), initializer);
|
|
143
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, unpackedInitializer, initializer));
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, lua.createNilLiteral(), initializer));
|
|
147
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, lua.createNilLiteral(), initializer));
|
|
148
148
|
}
|
|
149
149
|
for (const element of bindingPattern.elements) {
|
|
150
150
|
if (!ts.isOmittedExpression(element) && element.initializer) {
|
|
151
|
-
const variableName = identifier_1.transformIdentifier(context, element.name);
|
|
152
|
-
const identifier = export_1.addExportToIdentifier(context, variableName);
|
|
151
|
+
const variableName = (0, identifier_1.transformIdentifier)(context, element.name);
|
|
152
|
+
const identifier = (0, export_1.addExportToIdentifier)(context, variableName);
|
|
153
153
|
statements.push(lua.createIfStatement(lua.createBinaryExpression(identifier, lua.createNilLiteral(), lua.SyntaxKind.EqualityOperator), lua.createBlock([
|
|
154
154
|
lua.createAssignmentStatement(identifier, context.transformExpression(element.initializer)),
|
|
155
155
|
])));
|
|
@@ -163,27 +163,27 @@ function transformVariableDeclaration(context, statement) {
|
|
|
163
163
|
if (statement.initializer && statement.type) {
|
|
164
164
|
const initializerType = context.checker.getTypeAtLocation(statement.initializer);
|
|
165
165
|
const varType = context.checker.getTypeFromTypeNode(statement.type);
|
|
166
|
-
assignment_validation_1.validateAssignment(context, statement.initializer, initializerType, varType);
|
|
166
|
+
(0, assignment_validation_1.validateAssignment)(context, statement.initializer, initializerType, varType);
|
|
167
167
|
}
|
|
168
168
|
if (ts.isIdentifier(statement.name)) {
|
|
169
169
|
// Find variable identifier
|
|
170
|
-
const identifierName = identifier_1.transformIdentifier(context, statement.name);
|
|
170
|
+
const identifierName = (0, identifier_1.transformIdentifier)(context, statement.name);
|
|
171
171
|
const value = statement.initializer && context.transformExpression(statement.initializer);
|
|
172
|
-
return lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, identifierName, value, statement);
|
|
172
|
+
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, identifierName, value, statement);
|
|
173
173
|
}
|
|
174
174
|
else if (ts.isArrayBindingPattern(statement.name) || ts.isObjectBindingPattern(statement.name)) {
|
|
175
175
|
return transformBindingVariableDeclaration(context, statement.name, statement.initializer);
|
|
176
176
|
}
|
|
177
177
|
else {
|
|
178
|
-
return utils_1.assertNever(statement.name);
|
|
178
|
+
return (0, utils_1.assertNever)(statement.name);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
exports.transformVariableDeclaration = transformVariableDeclaration;
|
|
182
182
|
function checkVariableDeclarationList(context, node) {
|
|
183
183
|
if ((node.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) === 0) {
|
|
184
184
|
const token = node.getFirstToken();
|
|
185
|
-
utils_1.assert(token);
|
|
186
|
-
context.diagnostics.push(diagnostics_1.unsupportedVarDeclaration(token));
|
|
185
|
+
(0, utils_1.assert)(token);
|
|
186
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedVarDeclaration)(token));
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
exports.checkVariableDeclarationList = checkVariableDeclarationList;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import * as lua from "../../LuaAST";
|
|
3
|
+
import { TransformationContext } from "../context";
|
|
4
|
+
import { FunctionVisitor } from "../context/visitors";
|
|
5
|
+
export declare const transformVoidExpression: FunctionVisitor<ts.VoidExpression>;
|
|
6
|
+
export declare const transformVoidExpressionStatement: (node: ts.VoidExpression, context: TransformationContext) => lua.VariableDeclarationStatement;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformVoidExpressionStatement = exports.transformVoidExpression = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const lua = require("../../LuaAST");
|
|
6
|
+
const lua_ast_1 = require("../utils/lua-ast");
|
|
7
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
|
|
8
|
+
const transformVoidExpression = (node, context) => {
|
|
9
|
+
// If content is a literal it is safe to replace the entire expression with nil
|
|
10
|
+
if (ts.isLiteralExpression(node.expression)) {
|
|
11
|
+
return lua.createNilLiteral(node);
|
|
12
|
+
}
|
|
13
|
+
// (function() local ____ = <expression> end)()
|
|
14
|
+
return (0, lua_ast_1.createImmediatelyInvokedFunctionExpression)([
|
|
15
|
+
lua.createVariableDeclarationStatement(lua.createAnonymousIdentifier(), context.transformExpression(node.expression)),
|
|
16
|
+
], [], node);
|
|
17
|
+
};
|
|
18
|
+
exports.transformVoidExpression = transformVoidExpression;
|
|
19
|
+
const transformVoidExpressionStatement = (node, context) =>
|
|
20
|
+
// In case of a void expression statement we can omit the IIFE
|
|
21
|
+
lua.createVariableDeclarationStatement(lua.createAnonymousIdentifier(), context.transformExpression(node.expression), node);
|
|
22
|
+
exports.transformVoidExpressionStatement = transformVoidExpressionStatement;
|
|
23
|
+
//# sourceMappingURL=void.js.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { SourceNode } from "source-map";
|
|
1
2
|
import * as ts from "typescript";
|
|
2
3
|
import { EmitFile, ProcessedFile } from "./utils";
|
|
4
|
+
export declare const sourceMapTracebackBundlePlaceholder = "{#SourceMapTracebackBundle}";
|
|
5
|
+
export declare function printStackTraceBundleOverride(rootNode: SourceNode): string;
|
|
3
6
|
export declare function getBundleResult(program: ts.Program, files: ProcessedFile[]): [ts.Diagnostic[], EmitFile];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBundleResult = void 0;
|
|
3
|
+
exports.getBundleResult = exports.printStackTraceBundleOverride = exports.sourceMapTracebackBundlePlaceholder = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const source_map_1 = require("source-map");
|
|
6
6
|
const LuaPrinter_1 = require("../LuaPrinter");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const diagnostics_1 = require("./diagnostics");
|
|
9
9
|
const transpiler_1 = require("./transpiler");
|
|
10
|
-
const createModulePath = (pathToResolve, program) => LuaPrinter_1.escapeString(utils_1.formatPathToLuaPath(utils_1.trimExtension(transpiler_1.getEmitPathRelativeToOutDir(pathToResolve, program))));
|
|
10
|
+
const createModulePath = (pathToResolve, program) => (0, LuaPrinter_1.escapeString)((0, utils_1.formatPathToLuaPath)((0, utils_1.trimExtension)((0, transpiler_1.getEmitPathRelativeToOutDir)(pathToResolve, program))));
|
|
11
11
|
// Override `require` to read from ____modules table.
|
|
12
12
|
const requireOverride = `
|
|
13
13
|
local ____modules = {}
|
|
@@ -30,16 +30,51 @@ local function require(file, ...)
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
`;
|
|
33
|
+
exports.sourceMapTracebackBundlePlaceholder = "{#SourceMapTracebackBundle}";
|
|
34
|
+
function printStackTraceBundleOverride(rootNode) {
|
|
35
|
+
const map = {};
|
|
36
|
+
const getLineNumber = (line, fallback) => {
|
|
37
|
+
const data = map[line];
|
|
38
|
+
if (data === undefined) {
|
|
39
|
+
return fallback;
|
|
40
|
+
}
|
|
41
|
+
if (typeof data === "number") {
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
return data.line;
|
|
45
|
+
};
|
|
46
|
+
const transformLineData = (data) => {
|
|
47
|
+
if (typeof data === "number") {
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
return `{line = ${data.line}, file = "${data.file}"}`;
|
|
51
|
+
};
|
|
52
|
+
let currentLine = 1;
|
|
53
|
+
rootNode.walk((chunk, mappedPosition) => {
|
|
54
|
+
if (mappedPosition.line !== undefined && mappedPosition.line > 0) {
|
|
55
|
+
const line = getLineNumber(currentLine, mappedPosition.line);
|
|
56
|
+
map[currentLine] = {
|
|
57
|
+
line,
|
|
58
|
+
file: path.basename(mappedPosition.source),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
currentLine += chunk.split("\n").length - 1;
|
|
62
|
+
});
|
|
63
|
+
const mapItems = Object.entries(map).map(([line, original]) => `["${line}"] = ${transformLineData(original)}`);
|
|
64
|
+
const mapString = "{" + mapItems.join(",") + "}";
|
|
65
|
+
return `__TS__SourceMapTraceBack(debug.getinfo(1).short_src, ${mapString});`;
|
|
66
|
+
}
|
|
67
|
+
exports.printStackTraceBundleOverride = printStackTraceBundleOverride;
|
|
33
68
|
function getBundleResult(program, files) {
|
|
34
69
|
const diagnostics = [];
|
|
35
70
|
const options = program.getCompilerOptions();
|
|
36
|
-
const bundleFile = utils_1.cast(options.luaBundle, utils_1.isNonNull);
|
|
37
|
-
const entryModule = utils_1.cast(options.luaBundleEntry, utils_1.isNonNull);
|
|
71
|
+
const bundleFile = (0, utils_1.cast)(options.luaBundle, utils_1.isNonNull);
|
|
72
|
+
const entryModule = (0, utils_1.cast)(options.luaBundleEntry, utils_1.isNonNull);
|
|
38
73
|
// Resolve project settings relative to project file.
|
|
39
|
-
const resolvedEntryModule = path.resolve(transpiler_1.getSourceDir(program), entryModule);
|
|
40
|
-
const outputPath = path.resolve(transpiler_1.getEmitOutDir(program), bundleFile);
|
|
74
|
+
const resolvedEntryModule = path.resolve((0, transpiler_1.getSourceDir)(program), entryModule);
|
|
75
|
+
const outputPath = path.resolve((0, transpiler_1.getEmitOutDir)(program), bundleFile);
|
|
41
76
|
if (program.getSourceFile(resolvedEntryModule) === undefined && program.getSourceFile(entryModule) === undefined) {
|
|
42
|
-
diagnostics.push(diagnostics_1.couldNotFindBundleEntryPoint(entryModule));
|
|
77
|
+
diagnostics.push((0, diagnostics_1.couldNotFindBundleEntryPoint)(entryModule));
|
|
43
78
|
}
|
|
44
79
|
// For each file: ["<module path>"] = function() <lua content> end,
|
|
45
80
|
const moduleTableEntries = files.map(f => moduleSourceNode(f, createModulePath(f.fileName, program)));
|
|
@@ -47,12 +82,19 @@ function getBundleResult(program, files) {
|
|
|
47
82
|
const moduleTable = createModuleTableNode(moduleTableEntries);
|
|
48
83
|
// return require("<entry module path>")
|
|
49
84
|
const entryPoint = `return require(${createModulePath(entryModule, program)}, ...)\n`;
|
|
50
|
-
const
|
|
85
|
+
const footers = [];
|
|
86
|
+
if (options.sourceMapTraceback) {
|
|
87
|
+
// Generates SourceMapTraceback for the entire file
|
|
88
|
+
footers.push('require("lualib_bundle")\n');
|
|
89
|
+
footers.push(`${exports.sourceMapTracebackBundlePlaceholder}\n`);
|
|
90
|
+
}
|
|
91
|
+
const sourceChunks = [requireOverride, moduleTable, ...footers, entryPoint];
|
|
51
92
|
if (!options.noHeader) {
|
|
52
93
|
sourceChunks.unshift(LuaPrinter_1.tstlHeader);
|
|
53
94
|
}
|
|
54
95
|
const bundleNode = joinSourceChunks(sourceChunks);
|
|
55
|
-
|
|
96
|
+
let { code, map } = bundleNode.toStringWithSourceMap();
|
|
97
|
+
code = code.replace(exports.sourceMapTracebackBundlePlaceholder, printStackTraceBundleOverride(bundleNode));
|
|
56
98
|
return [
|
|
57
99
|
diagnostics,
|
|
58
100
|
{
|
|
@@ -65,7 +107,7 @@ function getBundleResult(program, files) {
|
|
|
65
107
|
}
|
|
66
108
|
exports.getBundleResult = getBundleResult;
|
|
67
109
|
function moduleSourceNode({ code, sourceMapNode }, modulePath) {
|
|
68
|
-
const tableEntryHead = `[${modulePath}] = function(...) `;
|
|
110
|
+
const tableEntryHead = `[${modulePath}] = function(...) \n`;
|
|
69
111
|
const tableEntryTail = " end,\n";
|
|
70
112
|
return joinSourceChunks([tableEntryHead, sourceMapNode !== null && sourceMapNode !== void 0 ? sourceMapNode : code, tableEntryTail]);
|
|
71
113
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.unsupportedJsxEmit = exports.cannotBundleLibrary = exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = exports.luaBundleEntryIsRequired = exports.couldNotFindBundleEntryPoint = exports.transformerShouldBeATsTransformerFactory = exports.shouldHaveAExport = exports.couldNotResolveFrom = exports.toLoadItShouldBeTranspiled = exports.couldNotReadDependency = exports.couldNotResolveRequire = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const createDiagnosticFactory = (getMessage, category = ts.DiagnosticCategory.Error) => utils_1.createSerialDiagnosticFactory((...args) => ({ messageText: getMessage(...args), category }));
|
|
7
|
-
exports.couldNotResolveRequire = createDiagnosticFactory((requirePath, containingFile) => `Could not resolve require path '${requirePath}' in file ${containingFile}.`);
|
|
6
|
+
const createDiagnosticFactory = (getMessage, category = ts.DiagnosticCategory.Error) => (0, utils_1.createSerialDiagnosticFactory)((...args) => ({ messageText: getMessage(...args), category }));
|
|
7
|
+
exports.couldNotResolveRequire = createDiagnosticFactory((requirePath, containingFile) => `Could not resolve lua source files for require path '${requirePath}' in file ${containingFile}.`);
|
|
8
8
|
exports.couldNotReadDependency = createDiagnosticFactory((dependency) => `Could not read content of resolved dependency ${dependency}.`);
|
|
9
9
|
exports.toLoadItShouldBeTranspiled = createDiagnosticFactory((kind, transform) => `To load "${transform}" ${kind} it should be transpiled or "ts-node" should be installed.`);
|
|
10
10
|
exports.couldNotResolveFrom = createDiagnosticFactory((kind, transform, base) => `Could not resolve "${transform}" ${kind} from "${base}".`);
|
|
@@ -12,7 +12,7 @@ exports.shouldHaveAExport = createDiagnosticFactory((kind, transform, importName
|
|
|
12
12
|
exports.transformerShouldBeATsTransformerFactory = createDiagnosticFactory((transform) => `"${transform}" transformer should be a ts.TransformerFactory or an object with ts.TransformerFactory values.`);
|
|
13
13
|
exports.couldNotFindBundleEntryPoint = createDiagnosticFactory((entryPoint) => `Could not find bundle entry point '${entryPoint}'. It should be a file in the project.`);
|
|
14
14
|
exports.luaBundleEntryIsRequired = createDiagnosticFactory(() => "'luaBundleEntry' is required when 'luaBundle' is enabled.");
|
|
15
|
-
exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = utils_1.createSerialDiagnosticFactory(() => ({
|
|
15
|
+
exports.usingLuaBundleWithInlineMightGenerateDuplicateCode = (0, utils_1.createSerialDiagnosticFactory)(() => ({
|
|
16
16
|
category: ts.DiagnosticCategory.Warning,
|
|
17
17
|
messageText: "Using 'luaBundle' with 'luaLibImport: \"inline\"' might generate duplicate code. " +
|
|
18
18
|
"It is recommended to use 'luaLibImport: \"require\"'.",
|