typescript-to-lua 0.41.2 → 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 +46 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +7 -0
- package/dist/LuaLib.js +41 -5
- 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/ArrayJoin.lua +2 -4
- package/dist/lualib/Await.lua +59 -0
- package/dist/lualib/Iterator.lua +1 -5
- package/dist/lualib/NumberToString.lua +4 -8
- package/dist/lualib/OptionalMethodCall.lua +3 -1
- package/dist/lualib/ParseInt.lua +1 -3
- package/dist/lualib/Promise.lua +172 -0
- package/dist/lualib/PromiseAll.lua +44 -0
- package/dist/lualib/PromiseAllSettled.lua +48 -0
- package/dist/lualib/PromiseAny.lua +41 -0
- package/dist/lualib/PromiseRace.lua +28 -0
- package/dist/lualib/SourceMapTraceBack.lua +18 -8
- package/dist/lualib/StringConcat.lua +1 -1
- package/dist/lualib/StringPadEnd.lua +7 -11
- package/dist/lualib/StringPadStart.lua +8 -12
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSubstring.lua +1 -1
- package/dist/lualib/lualib_bundle.lua +660 -239
- 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 +35 -32
- 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.d.ts +7 -0
- package/dist/transformation/builtins/promise.js +46 -0
- 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 -4
- package/dist/transformation/utils/annotations.js +1 -32
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +6 -5
- package/dist/transformation/utils/export.js +4 -4
- package/dist/transformation/utils/function-context.js +19 -13
- 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 +25 -19
- package/dist/transformation/visitors/async-await.d.ts +6 -0
- package/dist/transformation/visitors/async-await.js +38 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +32 -31
- 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 +22 -20
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.js +38 -38
- 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 +13 -13
- 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 -31
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +33 -21
- package/dist/transformation/visitors/identifier.js +25 -19
- package/dist/transformation/visitors/index.js +4 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +2 -1
- package/dist/transformation/visitors/language-extensions/multi.js +8 -4
- 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 +41 -49
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +16 -13
- package/dist/transformation/visitors/switch.js +132 -30
- 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 +29 -30
- 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 +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 +28 -14
- package/dist/transpilation/transformers.d.ts +1 -0
- package/dist/transpilation/transformers.js +61 -25
- package/dist/transpilation/transpile.js +7 -7
- package/dist/transpilation/transpiler.js +13 -11
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +9 -9
- package/dist/utils.js +2 -2
- package/package.json +16 -13
- 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
|
@@ -4,7 +4,6 @@ exports.transformVariableStatement = exports.checkVariableDeclarationList = expo
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
-
const annotations_1 = require("../utils/annotations");
|
|
8
7
|
const assignment_validation_1 = require("../utils/assignment-validation");
|
|
9
8
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
10
9
|
const export_1 = require("../utils/export");
|
|
@@ -18,16 +17,16 @@ function transformArrayBindingElement(context, name) {
|
|
|
18
17
|
return lua.createAnonymousIdentifier(name);
|
|
19
18
|
}
|
|
20
19
|
else if (ts.isIdentifier(name)) {
|
|
21
|
-
return identifier_1.transformIdentifier(context, name);
|
|
20
|
+
return (0, identifier_1.transformIdentifier)(context, name);
|
|
22
21
|
}
|
|
23
22
|
else if (ts.isBindingElement(name)) {
|
|
24
23
|
// TODO: It should always be true when called from `transformVariableDeclaration`,
|
|
25
24
|
// but could be false from `transformForOfLuaIteratorStatement`.
|
|
26
|
-
utils_1.assert(ts.isIdentifier(name.name));
|
|
27
|
-
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);
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
utils_1.assertNever(name);
|
|
29
|
+
(0, utils_1.assertNever)(name);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
exports.transformArrayBindingElement = transformArrayBindingElement;
|
|
@@ -49,11 +48,11 @@ function transformBindingPattern(context, pattern, table, propertyAccessStack =
|
|
|
49
48
|
continue;
|
|
50
49
|
}
|
|
51
50
|
// Build the path to the table
|
|
52
|
-
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);
|
|
53
52
|
// The identifier of the new variable
|
|
54
|
-
const variableName = identifier_1.transformIdentifier(context, element.name);
|
|
53
|
+
const variableName = (0, identifier_1.transformIdentifier)(context, element.name);
|
|
55
54
|
// The field to extract
|
|
56
|
-
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);
|
|
57
56
|
let expression;
|
|
58
57
|
if (element.dotDotDotToken) {
|
|
59
58
|
if (index !== pattern.elements.length - 1) {
|
|
@@ -79,18 +78,18 @@ function transformBindingPattern(context, pattern, table, propertyAccessStack =
|
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
const excludedPropertiesTable = excludedProperties.map(e => lua.createTableFieldExpression(lua.createBooleanLiteral(true), lua.createStringLiteral(e.text, e)));
|
|
82
|
-
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));
|
|
83
82
|
}
|
|
84
83
|
else {
|
|
85
|
-
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));
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
88
|
expression = lua.createTableIndexExpression(tableExpression, ts.isObjectBindingPattern(pattern) ? propertyName : lua.createNumericLiteral(index + 1));
|
|
90
89
|
}
|
|
91
|
-
result.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, variableName, expression));
|
|
90
|
+
result.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, variableName, expression));
|
|
92
91
|
if (element.initializer) {
|
|
93
|
-
const identifier = export_1.addExportToIdentifier(context, variableName);
|
|
92
|
+
const identifier = (0, export_1.addExportToIdentifier)(context, variableName);
|
|
94
93
|
result.push(lua.createIfStatement(lua.createBinaryExpression(identifier, lua.createNilLiteral(), lua.SyntaxKind.EqualityOperator), lua.createBlock([
|
|
95
94
|
lua.createAssignmentStatement(identifier, context.transformExpression(element.initializer)),
|
|
96
95
|
])));
|
|
@@ -107,15 +106,15 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
|
|
|
107
106
|
if (ts.isObjectBindingPattern(bindingPattern) || bindingPattern.elements.some(isComplexBindingElement)) {
|
|
108
107
|
let table;
|
|
109
108
|
if (initializer !== undefined && ts.isIdentifier(initializer)) {
|
|
110
|
-
table = identifier_1.transformIdentifier(context, initializer);
|
|
109
|
+
table = (0, identifier_1.transformIdentifier)(context, initializer);
|
|
111
110
|
}
|
|
112
111
|
else {
|
|
113
112
|
// Contain the expression in a temporary variable
|
|
114
113
|
table = lua.createAnonymousIdentifier();
|
|
115
114
|
if (initializer) {
|
|
116
115
|
let expression = context.transformExpression(initializer);
|
|
117
|
-
if (
|
|
118
|
-
expression = lua_ast_1.wrapInTable(expression);
|
|
116
|
+
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
117
|
+
expression = (0, lua_ast_1.wrapInTable)(expression);
|
|
119
118
|
}
|
|
120
119
|
statements.push(lua.createVariableDeclarationStatement(table, expression));
|
|
121
120
|
}
|
|
@@ -127,30 +126,30 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
|
|
|
127
126
|
? bindingPattern.elements.map(e => transformArrayBindingElement(context, e))
|
|
128
127
|
: lua.createAnonymousIdentifier();
|
|
129
128
|
if (initializer) {
|
|
130
|
-
if (
|
|
131
|
-
// Don't unpack
|
|
132
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, context.transformExpression(initializer), initializer));
|
|
129
|
+
if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
|
|
130
|
+
// Don't unpack LuaMultiReturn functions
|
|
131
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, context.transformExpression(initializer), initializer));
|
|
133
132
|
}
|
|
134
133
|
else if (ts.isArrayLiteralExpression(initializer)) {
|
|
135
134
|
// Don't unpack array literals
|
|
136
135
|
const values = initializer.elements.length > 0
|
|
137
136
|
? initializer.elements.map(e => context.transformExpression(e))
|
|
138
137
|
: lua.createNilLiteral();
|
|
139
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, values, initializer));
|
|
138
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, values, initializer));
|
|
140
139
|
}
|
|
141
140
|
else {
|
|
142
141
|
// local vars = this.transpileDestructingAssignmentValue(node.initializer);
|
|
143
|
-
const unpackedInitializer = lua_ast_1.createUnpackCall(context, context.transformExpression(initializer), initializer);
|
|
144
|
-
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));
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
else {
|
|
148
|
-
statements.push(...lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, vars, lua.createNilLiteral(), initializer));
|
|
147
|
+
statements.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, vars, lua.createNilLiteral(), initializer));
|
|
149
148
|
}
|
|
150
149
|
for (const element of bindingPattern.elements) {
|
|
151
150
|
if (!ts.isOmittedExpression(element) && element.initializer) {
|
|
152
|
-
const variableName = identifier_1.transformIdentifier(context, element.name);
|
|
153
|
-
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);
|
|
154
153
|
statements.push(lua.createIfStatement(lua.createBinaryExpression(identifier, lua.createNilLiteral(), lua.SyntaxKind.EqualityOperator), lua.createBlock([
|
|
155
154
|
lua.createAssignmentStatement(identifier, context.transformExpression(element.initializer)),
|
|
156
155
|
])));
|
|
@@ -164,27 +163,27 @@ function transformVariableDeclaration(context, statement) {
|
|
|
164
163
|
if (statement.initializer && statement.type) {
|
|
165
164
|
const initializerType = context.checker.getTypeAtLocation(statement.initializer);
|
|
166
165
|
const varType = context.checker.getTypeFromTypeNode(statement.type);
|
|
167
|
-
assignment_validation_1.validateAssignment(context, statement.initializer, initializerType, varType);
|
|
166
|
+
(0, assignment_validation_1.validateAssignment)(context, statement.initializer, initializerType, varType);
|
|
168
167
|
}
|
|
169
168
|
if (ts.isIdentifier(statement.name)) {
|
|
170
169
|
// Find variable identifier
|
|
171
|
-
const identifierName = identifier_1.transformIdentifier(context, statement.name);
|
|
170
|
+
const identifierName = (0, identifier_1.transformIdentifier)(context, statement.name);
|
|
172
171
|
const value = statement.initializer && context.transformExpression(statement.initializer);
|
|
173
|
-
return lua_ast_1.createLocalOrExportedOrGlobalDeclaration(context, identifierName, value, statement);
|
|
172
|
+
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, identifierName, value, statement);
|
|
174
173
|
}
|
|
175
174
|
else if (ts.isArrayBindingPattern(statement.name) || ts.isObjectBindingPattern(statement.name)) {
|
|
176
175
|
return transformBindingVariableDeclaration(context, statement.name, statement.initializer);
|
|
177
176
|
}
|
|
178
177
|
else {
|
|
179
|
-
return utils_1.assertNever(statement.name);
|
|
178
|
+
return (0, utils_1.assertNever)(statement.name);
|
|
180
179
|
}
|
|
181
180
|
}
|
|
182
181
|
exports.transformVariableDeclaration = transformVariableDeclaration;
|
|
183
182
|
function checkVariableDeclarationList(context, node) {
|
|
184
183
|
if ((node.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) === 0) {
|
|
185
184
|
const token = node.getFirstToken();
|
|
186
|
-
utils_1.assert(token);
|
|
187
|
-
context.diagnostics.push(diagnostics_1.unsupportedVarDeclaration(token));
|
|
185
|
+
(0, utils_1.assert)(token);
|
|
186
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedVarDeclaration)(token));
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
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,24 +1,25 @@
|
|
|
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 = {}
|
|
14
14
|
local ____moduleCache = {}
|
|
15
15
|
local ____originalRequire = require
|
|
16
|
-
local function require(file)
|
|
16
|
+
local function require(file, ...)
|
|
17
17
|
if ____moduleCache[file] then
|
|
18
18
|
return ____moduleCache[file].value
|
|
19
19
|
end
|
|
20
20
|
if ____modules[file] then
|
|
21
|
-
|
|
21
|
+
local module = ____modules[file]
|
|
22
|
+
____moduleCache[file] = { value = (select("#", ...) > 0) and module(...) or module(file) }
|
|
22
23
|
return ____moduleCache[file].value
|
|
23
24
|
else
|
|
24
25
|
if ____originalRequire then
|
|
@@ -29,29 +30,71 @@ local function require(file)
|
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
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;
|
|
32
68
|
function getBundleResult(program, files) {
|
|
33
69
|
const diagnostics = [];
|
|
34
70
|
const options = program.getCompilerOptions();
|
|
35
|
-
const bundleFile = utils_1.cast(options.luaBundle, utils_1.isNonNull);
|
|
36
|
-
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);
|
|
37
73
|
// Resolve project settings relative to project file.
|
|
38
|
-
const resolvedEntryModule = path.resolve(transpiler_1.getSourceDir(program), entryModule);
|
|
39
|
-
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);
|
|
40
76
|
if (program.getSourceFile(resolvedEntryModule) === undefined && program.getSourceFile(entryModule) === undefined) {
|
|
41
|
-
diagnostics.push(diagnostics_1.couldNotFindBundleEntryPoint(entryModule));
|
|
77
|
+
diagnostics.push((0, diagnostics_1.couldNotFindBundleEntryPoint)(entryModule));
|
|
42
78
|
}
|
|
43
79
|
// For each file: ["<module path>"] = function() <lua content> end,
|
|
44
80
|
const moduleTableEntries = files.map(f => moduleSourceNode(f, createModulePath(f.fileName, program)));
|
|
45
81
|
// Create ____modules table containing all entries from moduleTableEntries
|
|
46
82
|
const moduleTable = createModuleTableNode(moduleTableEntries);
|
|
47
83
|
// return require("<entry module path>")
|
|
48
|
-
const entryPoint = `return require(${createModulePath(entryModule, program)})\n`;
|
|
49
|
-
const
|
|
84
|
+
const entryPoint = `return require(${createModulePath(entryModule, program)}, ...)\n`;
|
|
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];
|
|
50
92
|
if (!options.noHeader) {
|
|
51
93
|
sourceChunks.unshift(LuaPrinter_1.tstlHeader);
|
|
52
94
|
}
|
|
53
95
|
const bundleNode = joinSourceChunks(sourceChunks);
|
|
54
|
-
|
|
96
|
+
let { code, map } = bundleNode.toStringWithSourceMap();
|
|
97
|
+
code = code.replace(exports.sourceMapTracebackBundlePlaceholder, printStackTraceBundleOverride(bundleNode));
|
|
55
98
|
return [
|
|
56
99
|
diagnostics,
|
|
57
100
|
{
|
|
@@ -64,7 +107,7 @@ function getBundleResult(program, files) {
|
|
|
64
107
|
}
|
|
65
108
|
exports.getBundleResult = getBundleResult;
|
|
66
109
|
function moduleSourceNode({ code, sourceMapNode }, modulePath) {
|
|
67
|
-
const tableEntryHead = `[${modulePath}] = function() `;
|
|
110
|
+
const tableEntryHead = `[${modulePath}] = function(...) \n`;
|
|
68
111
|
const tableEntryTail = " end,\n";
|
|
69
112
|
return joinSourceChunks([tableEntryHead, sourceMapNode !== null && sourceMapNode !== void 0 ? sourceMapNode : code, tableEntryTail]);
|
|
70
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\"'.",
|
|
@@ -30,7 +30,7 @@ function transpileFiles(rootNames, options = {}, writeFile) {
|
|
|
30
30
|
}
|
|
31
31
|
exports.transpileFiles = transpileFiles;
|
|
32
32
|
function transpileProject(configFileName, optionsToExtend, writeFile) {
|
|
33
|
-
const parseResult = tsconfig_1.parseConfigFileWithSystem(configFileName, optionsToExtend);
|
|
33
|
+
const parseResult = (0, tsconfig_1.parseConfigFileWithSystem)(configFileName, optionsToExtend);
|
|
34
34
|
if (parseResult.errors.length > 0) {
|
|
35
35
|
return { diagnostics: parseResult.errors, emitSkipped: true };
|
|
36
36
|
}
|
|
@@ -76,7 +76,7 @@ function createVirtualProgram(input, options = {}) {
|
|
|
76
76
|
exports.createVirtualProgram = createVirtualProgram;
|
|
77
77
|
function transpileVirtualProject(files, options = {}) {
|
|
78
78
|
const program = createVirtualProgram(files, options);
|
|
79
|
-
const collector = output_collector_1.createEmitOutputCollector();
|
|
79
|
+
const collector = (0, output_collector_1.createEmitOutputCollector)();
|
|
80
80
|
const { diagnostics: transpileDiagnostics } = new transpiler_1.Transpiler().emit({ program, writeFile: collector.writeFile });
|
|
81
81
|
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
82
82
|
...ts.getPreEmitDiagnostics(program),
|
|
@@ -5,13 +5,13 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
function createEmitOutputCollector() {
|
|
6
6
|
const files = [];
|
|
7
7
|
const writeFile = (fileName, data, _bom, _onError, sourceFiles = []) => {
|
|
8
|
-
let file = files.find(f => utils_1.intersection(f.sourceFiles, sourceFiles).length > 0);
|
|
8
|
+
let file = files.find(f => (0, utils_1.intersection)(f.sourceFiles, sourceFiles).length > 0);
|
|
9
9
|
if (!file) {
|
|
10
10
|
file = { outPath: fileName, sourceFiles: [...sourceFiles] };
|
|
11
11
|
files.push(file);
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
file.sourceFiles = utils_1.union(file.sourceFiles, sourceFiles);
|
|
14
|
+
file.sourceFiles = (0, utils_1.union)(file.sourceFiles, sourceFiles);
|
|
15
15
|
}
|
|
16
16
|
if (fileName.endsWith(".lua")) {
|
|
17
17
|
file.lua = data;
|
|
@@ -8,7 +8,7 @@ function getPlugins(program, diagnostics, customPlugins) {
|
|
|
8
8
|
const options = program.getCompilerOptions();
|
|
9
9
|
for (const [index, pluginOption] of ((_a = options.luaPlugins) !== null && _a !== void 0 ? _a : []).entries()) {
|
|
10
10
|
const optionName = `tstl.luaPlugins[${index}]`;
|
|
11
|
-
const { error: resolveError, result: factory } = utils_1.resolvePlugin("plugin", `${optionName}.name`, utils_1.getConfigDirectory(options), pluginOption.name, pluginOption.import);
|
|
11
|
+
const { error: resolveError, result: factory } = (0, utils_1.resolvePlugin)("plugin", `${optionName}.name`, (0, utils_1.getConfigDirectory)(options), pluginOption.name, pluginOption.import);
|
|
12
12
|
if (resolveError)
|
|
13
13
|
diagnostics.push(resolveError);
|
|
14
14
|
if (factory === undefined)
|
|
@@ -21,15 +21,22 @@ class ResolutionContext {
|
|
|
21
21
|
this.options = options;
|
|
22
22
|
this.emitHost = emitHost;
|
|
23
23
|
this.resultsCache = new Map();
|
|
24
|
+
this.noResolvePaths = new Set(options.noResolvePaths);
|
|
24
25
|
}
|
|
25
26
|
resolve(file, required) {
|
|
27
|
+
if (this.noResolvePaths.has(required)) {
|
|
28
|
+
if (this.options.tstlVerbose) {
|
|
29
|
+
console.log(`Skipping module resolution of ${required} as it is in the tsconfig noResolvePaths.`);
|
|
30
|
+
}
|
|
31
|
+
return { resolvedFiles: [], diagnostics: [] };
|
|
32
|
+
}
|
|
26
33
|
const resolvedDependency = resolveDependency(file, required, this.program, this.emitHost);
|
|
27
34
|
if (resolvedDependency) {
|
|
28
35
|
if (this.options.tstlVerbose) {
|
|
29
|
-
console.log(`Resolved ${required} to ${utils_1.normalizeSlashes(resolvedDependency)}`);
|
|
36
|
+
console.log(`Resolved ${required} to ${(0, utils_1.normalizeSlashes)(resolvedDependency)}`);
|
|
30
37
|
}
|
|
31
38
|
// Figure out resolved require path and dependency output path
|
|
32
|
-
const resolvedRequire = transpiler_1.getEmitPathRelativeToOutDir(resolvedDependency, this.program);
|
|
39
|
+
const resolvedRequire = (0, transpiler_1.getEmitPathRelativeToOutDir)(resolvedDependency, this.program);
|
|
33
40
|
if (shouldRewriteRequires(resolvedDependency, this.program)) {
|
|
34
41
|
replaceRequireInCode(file, required, resolvedRequire);
|
|
35
42
|
replaceRequireInSourceMap(file, required, resolvedRequire);
|
|
@@ -37,7 +44,7 @@ class ResolutionContext {
|
|
|
37
44
|
// Check cache to prevent resolving nested dependencies double to break dependency loops
|
|
38
45
|
if (this.resultsCache.has(resolvedDependency)) {
|
|
39
46
|
if (this.options.tstlVerbose) {
|
|
40
|
-
console.log(`Resolution cache hit for ${utils_1.normalizeSlashes(resolvedDependency)}`);
|
|
47
|
+
console.log(`Resolution cache hit for ${(0, utils_1.normalizeSlashes)(resolvedDependency)}`);
|
|
41
48
|
}
|
|
42
49
|
return this.resultsCache.get(resolvedDependency);
|
|
43
50
|
}
|
|
@@ -46,7 +53,7 @@ class ResolutionContext {
|
|
|
46
53
|
// If dependency resolved successfully, read its content
|
|
47
54
|
const dependencyContent = this.emitHost.readFile(resolvedDependency);
|
|
48
55
|
if (dependencyContent === undefined) {
|
|
49
|
-
return { resolvedFiles: [], diagnostics: [diagnostics_1.couldNotReadDependency(resolvedDependency)] };
|
|
56
|
+
return { resolvedFiles: [], diagnostics: [(0, diagnostics_1.couldNotReadDependency)(resolvedDependency)] };
|
|
50
57
|
}
|
|
51
58
|
const dependency = {
|
|
52
59
|
fileName: resolvedDependency,
|
|
@@ -71,13 +78,13 @@ class ResolutionContext {
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
else {
|
|
74
|
-
const fallbackRequire = fallbackResolve(required, transpiler_1.getSourceDir(this.program), path.dirname(file.fileName));
|
|
81
|
+
const fallbackRequire = fallbackResolve(required, (0, transpiler_1.getSourceDir)(this.program), path.dirname(file.fileName));
|
|
75
82
|
replaceRequireInCode(file, required, fallbackRequire);
|
|
76
83
|
replaceRequireInSourceMap(file, required, fallbackRequire);
|
|
77
84
|
return {
|
|
78
85
|
resolvedFiles: [],
|
|
79
86
|
diagnostics: [
|
|
80
|
-
diagnostics_1.couldNotResolveRequire(required, path.relative(transpiler_1.getProjectRoot(this.program), file.fileName)),
|
|
87
|
+
(0, diagnostics_1.couldNotResolveRequire)(required, path.relative((0, transpiler_1.getProjectRoot)(this.program), file.fileName)),
|
|
81
88
|
],
|
|
82
89
|
};
|
|
83
90
|
}
|
|
@@ -91,7 +98,7 @@ function resolveDependencies(program, files, emitHost) {
|
|
|
91
98
|
// Resolve dependencies for all processed files
|
|
92
99
|
for (const file of files) {
|
|
93
100
|
if (options.tstlVerbose) {
|
|
94
|
-
console.log(`Resolving dependencies for ${utils_1.normalizeSlashes(file.fileName)}`);
|
|
101
|
+
console.log(`Resolving dependencies for ${(0, utils_1.normalizeSlashes)(file.fileName)}`);
|
|
95
102
|
}
|
|
96
103
|
const resolutionResult = resolveFileDependencies(file, resolutionContext);
|
|
97
104
|
outFiles.push(...resolutionResult.resolvedFiles);
|
|
@@ -109,6 +116,7 @@ function resolveFileDependencies(file, context) {
|
|
|
109
116
|
for (const required of findRequiredPaths(file.code)) {
|
|
110
117
|
// Do no resolve lualib
|
|
111
118
|
if (required === "lualib_bundle") {
|
|
119
|
+
dependencies.push({ fileName: "lualib_bundle", code: "" });
|
|
112
120
|
continue;
|
|
113
121
|
}
|
|
114
122
|
// Do not resolve noResolution paths
|
|
@@ -134,10 +142,15 @@ function resolveDependency(requiringFile, dependency, program, emitHost) {
|
|
|
134
142
|
const options = program.getCompilerOptions();
|
|
135
143
|
const fileDirectory = path.dirname(requiringFile.fileName);
|
|
136
144
|
if (options.tstlVerbose) {
|
|
137
|
-
console.log(`Resolving "${dependency}" from ${utils_1.normalizeSlashes(fileDirectory)}`);
|
|
145
|
+
console.log(`Resolving "${dependency}" from ${(0, utils_1.normalizeSlashes)(fileDirectory)}`);
|
|
138
146
|
}
|
|
147
|
+
// Check if the import is relative
|
|
148
|
+
const isRelative = ["/", "./", "../"].some(p => dependency.startsWith(p));
|
|
149
|
+
// If the import is relative, always resolve it relative to the requiring file
|
|
150
|
+
// If the import is not relative, resolve it relative to options.baseUrl if it is set
|
|
151
|
+
const relativeTo = isRelative ? fileDirectory : (_a = options.baseUrl) !== null && _a !== void 0 ? _a : fileDirectory;
|
|
139
152
|
// Check if file is a file in the project
|
|
140
|
-
const resolvedPath = path.join(
|
|
153
|
+
const resolvedPath = path.join(relativeTo, dependency);
|
|
141
154
|
const possibleProjectFiles = [
|
|
142
155
|
resolvedPath,
|
|
143
156
|
resolvedPath + ".ts",
|
|
@@ -153,7 +166,8 @@ function resolveDependency(requiringFile, dependency, program, emitHost) {
|
|
|
153
166
|
// Check if this is a lua file in the project sources
|
|
154
167
|
const possibleLuaProjectFiles = [
|
|
155
168
|
resolvedPath + ".lua",
|
|
156
|
-
path.join(resolvedPath, "index.lua"),
|
|
169
|
+
path.join(resolvedPath, "index.lua"),
|
|
170
|
+
path.join(resolvedPath, "init.lua"), // lua looks for <require>/init.lua if it cannot find <require>.lua
|
|
157
171
|
];
|
|
158
172
|
for (const possibleFile of possibleLuaProjectFiles) {
|
|
159
173
|
if (emitHost.fileExists(possibleFile)) {
|
|
@@ -239,13 +253,13 @@ function findRequiredPaths(code) {
|
|
|
239
253
|
return paths;
|
|
240
254
|
}
|
|
241
255
|
function replaceRequireInCode(file, originalRequire, newRequire) {
|
|
242
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
256
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
243
257
|
// Escape special characters to prevent the regex from breaking...
|
|
244
258
|
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
245
259
|
file.code = file.code.replace(new RegExp(`(^|\\s|;|=)require\\("${escapedRequire}"\\)`), `$1require("${requirePath}")`);
|
|
246
260
|
}
|
|
247
261
|
function replaceRequireInSourceMap(file, originalRequire, newRequire) {
|
|
248
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
262
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
249
263
|
if (file.sourceMapNode) {
|
|
250
264
|
replaceInSourceMap(file.sourceMapNode, file.sourceMapNode, `"${originalRequire}"`, `"${requirePath}"`);
|
|
251
265
|
}
|
|
@@ -274,14 +288,14 @@ function isProjectFile(file, program) {
|
|
|
274
288
|
return program.getSourceFile(file) !== undefined;
|
|
275
289
|
}
|
|
276
290
|
function hasSourceFileInProject(filePath, program) {
|
|
277
|
-
const pathWithoutExtension = utils_1.trimExtension(filePath);
|
|
291
|
+
const pathWithoutExtension = (0, utils_1.trimExtension)(filePath);
|
|
278
292
|
return (isProjectFile(pathWithoutExtension + ".ts", program) ||
|
|
279
293
|
isProjectFile(pathWithoutExtension + ".tsx", program) ||
|
|
280
294
|
isProjectFile(pathWithoutExtension + ".json", program));
|
|
281
295
|
}
|
|
282
296
|
// Transform an import path to a lua require that is probably not correct, but can be used as fallback when regular resolution fails
|
|
283
297
|
function fallbackResolve(required, sourceRootDir, fileDir) {
|
|
284
|
-
return utils_1.formatPathToLuaPath(path
|
|
298
|
+
return (0, utils_1.formatPathToLuaPath)(path
|
|
285
299
|
.normalize(path.join(path.relative(sourceRootDir, fileDir), required))
|
|
286
300
|
.split(path.sep)
|
|
287
301
|
.filter(s => s !== "." && s !== "..")
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
export declare function getTransformers(program: ts.Program, diagnostics: ts.Diagnostic[], customTransformers: ts.CustomTransformers, onSourceFile: (sourceFile: ts.SourceFile) => void): ts.CustomTransformers;
|
|
3
3
|
export declare const noImplicitSelfTransformer: ts.TransformerFactory<ts.SourceFile | ts.Bundle>;
|
|
4
|
+
export declare const stripParenthesisExpressionsTransformer: ts.TransformerFactory<ts.SourceFile>;
|