typescript-to-lua 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.d.ts +1 -0
- package/dist/LuaAST.js +14 -6
- package/dist/LuaLib.d.ts +4 -3
- package/dist/LuaLib.js +5 -4
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +79 -27
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +7 -1
- package/dist/lualib/ArrayReduceRight.lua +7 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArraySplice.lua +5 -5
- package/dist/lualib/Await.lua +39 -19
- package/dist/lualib/CloneDescriptor.lua +8 -8
- package/dist/lualib/Decorate.lua +1 -1
- package/dist/lualib/DelegatedYield.lua +1 -3
- package/dist/lualib/Delete.lua +6 -6
- package/dist/lualib/Error.lua +47 -44
- package/dist/lualib/Generator.lua +1 -5
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Map.lua +130 -134
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberToString.lua +3 -5
- package/dist/lualib/ObjectDefineProperty.lua +40 -8
- package/dist/lualib/ParseFloat.lua +9 -5
- package/dist/lualib/ParseInt.lua +15 -3
- package/dist/lualib/Promise.lua +36 -26
- package/dist/lualib/Set.lua +119 -123
- package/dist/lualib/SetDescriptor.lua +7 -1
- package/dist/lualib/SourceMapTraceBack.lua +19 -9
- package/dist/lualib/SparseArrayNew.lua +5 -0
- package/dist/lualib/SparseArrayPush.lua +9 -0
- package/dist/lualib/SparseArraySpread.lua +4 -0
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +2 -2
- package/dist/lualib/StringPadEnd.lua +2 -2
- package/dist/lualib/StringPadStart.lua +2 -2
- package/dist/lualib/StringReplace.lua +12 -11
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSlice.lua +2 -2
- package/dist/lualib/StringSplit.lua +3 -3
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +2 -2
- package/dist/lualib/Symbol.lua +3 -5
- package/dist/lualib/WeakMap.lua +40 -42
- package/dist/lualib/WeakSet.lua +36 -38
- package/dist/lualib/lualib_bundle.lua +705 -586
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -10
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.d.ts +1 -1
- package/dist/transformation/builtins/index.js +69 -36
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.d.ts +2 -1
- package/dist/transformation/builtins/object.js +12 -13
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -31
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.d.ts +12 -0
- package/dist/transformation/context/context.js +105 -6
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -3
- package/dist/transformation/utils/annotations.js +0 -2
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +6 -0
- package/dist/transformation/utils/diagnostics.js +7 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/lua-ast.d.ts +0 -1
- package/dist/transformation/utils/lua-ast.js +25 -35
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/preceding-statements.d.ts +3 -0
- package/dist/transformation/utils/preceding-statements.js +11 -0
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +7 -0
- package/dist/transformation/utils/scope.js +77 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +16 -1
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.d.ts +3 -0
- package/dist/transformation/visitors/access.js +74 -47
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
- package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
- package/dist/transformation/visitors/binary-expression/compound.js +69 -71
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
- package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
- package/dist/transformation/visitors/binary-expression/index.js +84 -40
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.d.ts +3 -2
- package/dist/transformation/visitors/call.js +130 -143
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +43 -39
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +14 -16
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +34 -20
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -30
- package/dist/transformation/visitors/expression-list.d.ts +7 -0
- package/dist/transformation/visitors/expression-list.js +120 -0
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +30 -32
- package/dist/transformation/visitors/identifier.js +26 -22
- package/dist/transformation/visitors/index.js +2 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -3
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +87 -57
- package/dist/transformation/visitors/loops/do-while.js +35 -9
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +28 -8
- package/dist/transformation/visitors/loops/utils.d.ts +1 -0
- package/dist/transformation/visitors/loops/utils.js +21 -10
- package/dist/transformation/visitors/modules/export.js +14 -15
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
- package/dist/transformation/visitors/optional-chaining.js +172 -0
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +12 -9
- package/dist/transformation/visitors/spread.js +11 -11
- package/dist/transformation/visitors/switch.js +152 -30
- package/dist/transformation/visitors/template.js +10 -7
- package/dist/transformation/visitors/typeof.js +4 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +46 -32
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +20 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +26 -14
- package/dist/transpilation/transformers.js +45 -25
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +5 -3
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/lualib/OptionalChainAccess.lua +0 -6
- package/dist/lualib/OptionalFunctionCall.lua +0 -6
- package/dist/lualib/OptionalMethodCall.lua +0 -11
- package/dist/transformation/utils/transform.d.ts +0 -8
- package/dist/transformation/utils/transform.js +0 -14
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -1,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);
|
|
@@ -135,10 +142,15 @@ function resolveDependency(requiringFile, dependency, program, emitHost) {
|
|
|
135
142
|
const options = program.getCompilerOptions();
|
|
136
143
|
const fileDirectory = path.dirname(requiringFile.fileName);
|
|
137
144
|
if (options.tstlVerbose) {
|
|
138
|
-
console.log(`Resolving "${dependency}" from ${utils_1.normalizeSlashes(fileDirectory)}`);
|
|
145
|
+
console.log(`Resolving "${dependency}" from ${(0, utils_1.normalizeSlashes)(fileDirectory)}`);
|
|
139
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;
|
|
140
152
|
// Check if file is a file in the project
|
|
141
|
-
const resolvedPath = path.join(
|
|
153
|
+
const resolvedPath = path.join(relativeTo, dependency);
|
|
142
154
|
const possibleProjectFiles = [
|
|
143
155
|
resolvedPath,
|
|
144
156
|
resolvedPath + ".ts",
|
|
@@ -232,7 +244,7 @@ function isBuildModeLibrary(program) {
|
|
|
232
244
|
function findRequiredPaths(code) {
|
|
233
245
|
// Find all require("<path>") paths in a lua code string
|
|
234
246
|
const paths = [];
|
|
235
|
-
const pattern = /(^|\s|;|=)require\("(
|
|
247
|
+
const pattern = /(^|\s|;|=)require\("(.+?)"\)/g;
|
|
236
248
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
237
249
|
let match;
|
|
238
250
|
while ((match = pattern.exec(code))) {
|
|
@@ -241,13 +253,13 @@ function findRequiredPaths(code) {
|
|
|
241
253
|
return paths;
|
|
242
254
|
}
|
|
243
255
|
function replaceRequireInCode(file, originalRequire, newRequire) {
|
|
244
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
256
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
245
257
|
// Escape special characters to prevent the regex from breaking...
|
|
246
258
|
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
247
259
|
file.code = file.code.replace(new RegExp(`(^|\\s|;|=)require\\("${escapedRequire}"\\)`), `$1require("${requirePath}")`);
|
|
248
260
|
}
|
|
249
261
|
function replaceRequireInSourceMap(file, originalRequire, newRequire) {
|
|
250
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
262
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
251
263
|
if (file.sourceMapNode) {
|
|
252
264
|
replaceInSourceMap(file.sourceMapNode, file.sourceMapNode, `"${originalRequire}"`, `"${requirePath}"`);
|
|
253
265
|
}
|
|
@@ -276,14 +288,14 @@ function isProjectFile(file, program) {
|
|
|
276
288
|
return program.getSourceFile(file) !== undefined;
|
|
277
289
|
}
|
|
278
290
|
function hasSourceFileInProject(filePath, program) {
|
|
279
|
-
const pathWithoutExtension = utils_1.trimExtension(filePath);
|
|
291
|
+
const pathWithoutExtension = (0, utils_1.trimExtension)(filePath);
|
|
280
292
|
return (isProjectFile(pathWithoutExtension + ".ts", program) ||
|
|
281
293
|
isProjectFile(pathWithoutExtension + ".tsx", program) ||
|
|
282
294
|
isProjectFile(pathWithoutExtension + ".json", program));
|
|
283
295
|
}
|
|
284
296
|
// Transform an import path to a lua require that is probably not correct, but can be used as fallback when regular resolution fails
|
|
285
297
|
function fallbackResolve(required, sourceRootDir, fileDir) {
|
|
286
|
-
return utils_1.formatPathToLuaPath(path
|
|
298
|
+
return (0, utils_1.formatPathToLuaPath)(path
|
|
287
299
|
.normalize(path.join(path.relative(sourceRootDir, fileDir), required))
|
|
288
300
|
.split(path.sep)
|
|
289
301
|
.filter(s => s !== "." && s !== "..")
|
|
@@ -48,7 +48,7 @@ exports.noImplicitSelfTransformer = noImplicitSelfTransformer;
|
|
|
48
48
|
const stripParenthesisExpressionsTransformer = context => sourceFile => {
|
|
49
49
|
// Remove parenthesis expressions before transforming to Lua, so transpiler is not hindered by extra ParenthesizedExpression nodes
|
|
50
50
|
function unwrapParentheses(node) {
|
|
51
|
-
while (ts.isParenthesizedExpression(node)) {
|
|
51
|
+
while (ts.isParenthesizedExpression(node) && !ts.isOptionalChain(node.expression)) {
|
|
52
52
|
node = node.expression;
|
|
53
53
|
}
|
|
54
54
|
return node;
|
|
@@ -58,6 +58,12 @@ const stripParenthesisExpressionsTransformer = context => sourceFile => {
|
|
|
58
58
|
if (ts.isCallExpression(node)) {
|
|
59
59
|
return ts.factory.updateCallExpression(node, unwrapParentheses(node.expression), node.typeArguments, node.arguments);
|
|
60
60
|
}
|
|
61
|
+
else if (ts.isVoidExpression(node)) {
|
|
62
|
+
return ts.factory.updateVoidExpression(node, unwrapParentheses(node.expression));
|
|
63
|
+
}
|
|
64
|
+
else if (ts.isDeleteExpression(node)) {
|
|
65
|
+
return ts.factory.updateDeleteExpression(node, unwrapParentheses(node.expression));
|
|
66
|
+
}
|
|
61
67
|
return ts.visitEachChild(node, visit, context);
|
|
62
68
|
}
|
|
63
69
|
return ts.visitNode(sourceFile, visit);
|
|
@@ -70,32 +76,46 @@ function loadTransformersFromOptions(program, diagnostics) {
|
|
|
70
76
|
afterDeclarations: [],
|
|
71
77
|
};
|
|
72
78
|
const options = program.getCompilerOptions();
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
if (options.plugins) {
|
|
80
|
+
for (const [index, transformerImport] of options.plugins.entries()) {
|
|
81
|
+
if (!("transform" in transformerImport))
|
|
82
|
+
continue;
|
|
83
|
+
const optionName = `compilerOptions.plugins[${index}]`;
|
|
84
|
+
const { error: resolveError, result: factory } = (0, utils_1.resolvePlugin)("transformer", `${optionName}.transform`, (0, utils_1.getConfigDirectory)(options), transformerImport.transform, transformerImport.import);
|
|
85
|
+
if (resolveError)
|
|
86
|
+
diagnostics.push(resolveError);
|
|
87
|
+
if (factory === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const { error: loadError, transformer } = loadTransformer(optionName, program, factory, transformerImport);
|
|
90
|
+
if (loadError)
|
|
91
|
+
diagnostics.push(loadError);
|
|
92
|
+
if (transformer === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
if (transformer.before) {
|
|
95
|
+
customTransformers.before.push(transformer.before);
|
|
96
|
+
}
|
|
97
|
+
if (transformer.after) {
|
|
98
|
+
customTransformers.after.push(transformer.after);
|
|
99
|
+
}
|
|
100
|
+
if (transformer.afterDeclarations) {
|
|
101
|
+
customTransformers.afterDeclarations.push(transformer.afterDeclarations);
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
}
|
|
105
|
+
if (options.jsx === ts.JsxEmit.React) {
|
|
106
|
+
customTransformers.before.push(context => {
|
|
107
|
+
// if target < ES2017, typescript generates some unnecessary additional transformations in transformJSX.
|
|
108
|
+
// We can't control the target compiler option, so we override here.
|
|
109
|
+
const patchedContext = {
|
|
110
|
+
...context,
|
|
111
|
+
getCompilerOptions: () => ({
|
|
112
|
+
...context.getCompilerOptions(),
|
|
113
|
+
target: ts.ScriptTarget.ESNext,
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
116
|
+
return ts.transformJsx(patchedContext);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
99
119
|
return customTransformers;
|
|
100
120
|
}
|
|
101
121
|
function loadTransformer(optionPath, program, factory, { transform, after = false, afterDeclarations = false, type = "program", ...extraOptions }) {
|
|
@@ -14,7 +14,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
14
14
|
if (options.tstlVerbose) {
|
|
15
15
|
console.log("Parsing project settings");
|
|
16
16
|
}
|
|
17
|
-
const diagnostics = CompilerOptions_1.validateOptions(options);
|
|
17
|
+
const diagnostics = (0, CompilerOptions_1.validateOptions)(options);
|
|
18
18
|
let transpiledFiles = [];
|
|
19
19
|
if (options.noEmitOnError) {
|
|
20
20
|
const preEmitDiagnostics = [
|
|
@@ -39,17 +39,17 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
39
39
|
return { diagnostics: preEmitDiagnostics, transpiledFiles };
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
const plugins = plugins_1.getPlugins(program, diagnostics, customPlugins);
|
|
42
|
+
const plugins = (0, plugins_1.getPlugins)(program, diagnostics, customPlugins);
|
|
43
43
|
if (options.tstlVerbose) {
|
|
44
44
|
console.log(`Successfully loaded ${plugins.length} plugins`);
|
|
45
45
|
}
|
|
46
|
-
const visitorMap = transformation_1.createVisitorMap(plugins.map(p => p.visitors).filter(utils_1.isNonNull));
|
|
47
|
-
const printer = LuaPrinter_1.createPrinter(plugins.map(p => p.printer).filter(utils_1.isNonNull));
|
|
46
|
+
const visitorMap = (0, transformation_1.createVisitorMap)(plugins.map(p => p.visitors).filter(utils_1.isNonNull));
|
|
47
|
+
const printer = (0, LuaPrinter_1.createPrinter)(plugins.map(p => p.printer).filter(utils_1.isNonNull));
|
|
48
48
|
const processSourceFile = (sourceFile) => {
|
|
49
49
|
if (options.tstlVerbose) {
|
|
50
50
|
console.log(`Transforming ${sourceFile.fileName}`);
|
|
51
51
|
}
|
|
52
|
-
const { file, diagnostics: transformDiagnostics } = transformation_1.transformSourceFile(program, sourceFile, visitorMap);
|
|
52
|
+
const { file, diagnostics: transformDiagnostics } = (0, transformation_1.transformSourceFile)(program, sourceFile, visitorMap);
|
|
53
53
|
diagnostics.push(...transformDiagnostics);
|
|
54
54
|
if (!options.noEmit && !options.emitDeclarationOnly) {
|
|
55
55
|
if (options.tstlVerbose) {
|
|
@@ -64,7 +64,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
const transformers = transformers_1.getTransformers(program, diagnostics, customTransformers, processSourceFile);
|
|
67
|
+
const transformers = (0, transformers_1.getTransformers)(program, diagnostics, customTransformers, processSourceFile);
|
|
68
68
|
const isEmittableJsonFile = (sourceFile) => sourceFile.flags & ts.NodeFlags.JsonFile &&
|
|
69
69
|
!options.emitDeclarationOnly &&
|
|
70
70
|
!program.isSourceFileFromExternalLibrary(sourceFile);
|
|
@@ -17,7 +17,7 @@ class Transpiler {
|
|
|
17
17
|
var _a;
|
|
18
18
|
const { program, writeFile = this.emitHost.writeFile } = emitOptions;
|
|
19
19
|
const verbose = program.getCompilerOptions().tstlVerbose;
|
|
20
|
-
const { diagnostics, transpiledFiles: freshFiles } = transpile_1.getProgramTranspileResult(this.emitHost, writeFile, emitOptions);
|
|
20
|
+
const { diagnostics, transpiledFiles: freshFiles } = (0, transpile_1.getProgramTranspileResult)(this.emitHost, writeFile, emitOptions);
|
|
21
21
|
const { emitPlan } = this.getEmitPlan(program, diagnostics, freshFiles);
|
|
22
22
|
if (verbose) {
|
|
23
23
|
console.log("Emitting output");
|
|
@@ -26,7 +26,7 @@ class Transpiler {
|
|
|
26
26
|
const emitBOM = (_a = options.emitBOM) !== null && _a !== void 0 ? _a : false;
|
|
27
27
|
for (const { outputPath, code, sourceMap, sourceFiles } of emitPlan) {
|
|
28
28
|
if (verbose) {
|
|
29
|
-
console.log(`Emitting ${utils_1.normalizeSlashes(outputPath)}`);
|
|
29
|
+
console.log(`Emitting ${(0, utils_1.normalizeSlashes)(outputPath)}`);
|
|
30
30
|
}
|
|
31
31
|
writeFile(outputPath, code, emitBOM, undefined, sourceFiles);
|
|
32
32
|
if (options.sourceMap && sourceMap !== undefined) {
|
|
@@ -44,7 +44,7 @@ class Transpiler {
|
|
|
44
44
|
console.log("Constructing emit plan");
|
|
45
45
|
}
|
|
46
46
|
// Resolve imported modules and modify output Lua requires
|
|
47
|
-
const resolutionResult = resolve_1.resolveDependencies(program, files, this.emitHost);
|
|
47
|
+
const resolutionResult = (0, resolve_1.resolveDependencies)(program, files, this.emitHost);
|
|
48
48
|
diagnostics.push(...resolutionResult.diagnostics);
|
|
49
49
|
const lualibRequired = resolutionResult.resolvedFiles.some(f => f.fileName === "lualib_bundle");
|
|
50
50
|
if (lualibRequired) {
|
|
@@ -54,12 +54,12 @@ class Transpiler {
|
|
|
54
54
|
console.log("Including lualib bundle");
|
|
55
55
|
}
|
|
56
56
|
// Add lualib bundle to source dir 'virtually', will be moved to correct output dir in emitPlan
|
|
57
|
-
const fileName = utils_1.normalizeSlashes(path.resolve(getSourceDir(program), "lualib_bundle.lua"));
|
|
58
|
-
resolutionResult.resolvedFiles.unshift({ fileName, code: LuaLib_1.getLuaLibBundle(this.emitHost) });
|
|
57
|
+
const fileName = (0, utils_1.normalizeSlashes)(path.resolve(getSourceDir(program), "lualib_bundle.lua"));
|
|
58
|
+
resolutionResult.resolvedFiles.unshift({ fileName, code: (0, LuaLib_1.getLuaLibBundle)(this.emitHost) });
|
|
59
59
|
}
|
|
60
60
|
let emitPlan;
|
|
61
|
-
if (CompilerOptions_1.isBundleEnabled(options)) {
|
|
62
|
-
const [bundleDiagnostics, bundleFile] = bundle_1.getBundleResult(program, resolutionResult.resolvedFiles);
|
|
61
|
+
if ((0, CompilerOptions_1.isBundleEnabled)(options)) {
|
|
62
|
+
const [bundleDiagnostics, bundleFile] = (0, bundle_1.getBundleResult)(program, resolutionResult.resolvedFiles);
|
|
63
63
|
diagnostics.push(...bundleDiagnostics);
|
|
64
64
|
emitPlan = [bundleFile];
|
|
65
65
|
}
|
|
@@ -90,7 +90,7 @@ function getEmitPathRelativeToOutDir(fileName, program) {
|
|
|
90
90
|
emitPathSplits[0] = "lua_modules";
|
|
91
91
|
}
|
|
92
92
|
// Make extension lua
|
|
93
|
-
emitPathSplits[emitPathSplits.length - 1] = utils_1.trimExtension(emitPathSplits[emitPathSplits.length - 1]) + ".lua";
|
|
93
|
+
emitPathSplits[emitPathSplits.length - 1] = (0, utils_1.trimExtension)(emitPathSplits[emitPathSplits.length - 1]) + ".lua";
|
|
94
94
|
return path.join(...emitPathSplits);
|
|
95
95
|
}
|
|
96
96
|
exports.getEmitPathRelativeToOutDir = getEmitPathRelativeToOutDir;
|
|
@@ -8,28 +8,30 @@ const cliDiagnostics = require("../cli/diagnostics");
|
|
|
8
8
|
const diagnosticFactories = require("./diagnostics");
|
|
9
9
|
const getConfigDirectory = (options) => options.configFilePath ? path.dirname(options.configFilePath) : process.cwd();
|
|
10
10
|
exports.getConfigDirectory = getConfigDirectory;
|
|
11
|
+
const getTstlDirectory = () => path.dirname(__dirname);
|
|
11
12
|
function resolvePlugin(kind, optionName, basedir, query, importName = "default") {
|
|
12
13
|
if (typeof query !== "string") {
|
|
13
14
|
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "string") };
|
|
14
15
|
}
|
|
16
|
+
const isModuleNotFoundError = (error) => error.code === "MODULE_NOT_FOUND";
|
|
15
17
|
let resolved;
|
|
16
18
|
try {
|
|
17
19
|
resolved = resolve.sync(query, { basedir, extensions: [".js", ".ts", ".tsx"] });
|
|
18
20
|
}
|
|
19
21
|
catch (err) {
|
|
20
|
-
if (err
|
|
22
|
+
if (!isModuleNotFoundError(err))
|
|
21
23
|
throw err;
|
|
22
24
|
return { error: diagnosticFactories.couldNotResolveFrom(kind, query, basedir) };
|
|
23
25
|
}
|
|
24
26
|
const hasNoRequireHook = require.extensions[".ts"] === undefined;
|
|
25
27
|
if (hasNoRequireHook && (resolved.endsWith(".ts") || resolved.endsWith(".tsx"))) {
|
|
26
28
|
try {
|
|
27
|
-
const tsNodePath = resolve.sync("ts-node", { basedir });
|
|
29
|
+
const tsNodePath = resolve.sync("ts-node", { basedir: getTstlDirectory() });
|
|
28
30
|
const tsNode = require(tsNodePath);
|
|
29
31
|
tsNode.register({ transpileOnly: true });
|
|
30
32
|
}
|
|
31
33
|
catch (err) {
|
|
32
|
-
if (err
|
|
34
|
+
if (!isModuleNotFoundError(err))
|
|
33
35
|
throw err;
|
|
34
36
|
return { error: diagnosticFactories.toLoadItShouldBeTranspiled(kind, query) };
|
|
35
37
|
}
|
package/dist/tstl.js
CHANGED
|
@@ -10,9 +10,9 @@ const report_1 = require("./cli/report");
|
|
|
10
10
|
const tsconfig_1 = require("./cli/tsconfig");
|
|
11
11
|
const CompilerOptions_1 = require("./CompilerOptions");
|
|
12
12
|
const shouldBePretty = ({ pretty } = {}) => { var _a, _b, _c; return pretty !== undefined ? pretty : (_c = (_b = (_a = ts.sys).writeOutputIsTTY) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false; };
|
|
13
|
-
let reportDiagnostic = report_1.createDiagnosticReporter(false);
|
|
13
|
+
let reportDiagnostic = (0, report_1.createDiagnosticReporter)(false);
|
|
14
14
|
function updateReportDiagnostic(options) {
|
|
15
|
-
reportDiagnostic = report_1.createDiagnosticReporter(shouldBePretty(options));
|
|
15
|
+
reportDiagnostic = (0, report_1.createDiagnosticReporter)(shouldBePretty(options));
|
|
16
16
|
}
|
|
17
17
|
function createWatchStatusReporter(options) {
|
|
18
18
|
return ts.createWatchStatusReporter(ts.sys, shouldBePretty(options));
|
|
@@ -24,7 +24,7 @@ function executeCommandLine(args) {
|
|
|
24
24
|
return performBuild(args.slice(1));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
const commandLine = parse_1.parseCommandLine(args);
|
|
27
|
+
const commandLine = (0, parse_1.parseCommandLine)(args);
|
|
28
28
|
if (commandLine.options.build) {
|
|
29
29
|
reportDiagnostic(cliDiagnostics.optionBuildMustBeFirstCommandLineArgument());
|
|
30
30
|
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
|
@@ -41,17 +41,17 @@ function executeCommandLine(args) {
|
|
|
41
41
|
}
|
|
42
42
|
if (commandLine.options.help) {
|
|
43
43
|
console.log(information_1.versionString);
|
|
44
|
-
console.log(information_1.getHelpString());
|
|
44
|
+
console.log((0, information_1.getHelpString)());
|
|
45
45
|
return ts.sys.exit(ts.ExitStatus.Success);
|
|
46
46
|
}
|
|
47
|
-
const configFileName = tsconfig_1.locateConfigFile(commandLine);
|
|
47
|
+
const configFileName = (0, tsconfig_1.locateConfigFile)(commandLine);
|
|
48
48
|
if (typeof configFileName === "object") {
|
|
49
49
|
reportDiagnostic(configFileName);
|
|
50
50
|
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
|
51
51
|
}
|
|
52
52
|
const commandLineOptions = commandLine.options;
|
|
53
53
|
if (configFileName) {
|
|
54
|
-
const configParseResult = tsconfig_1.parseConfigFileWithSystem(configFileName, commandLineOptions);
|
|
54
|
+
const configParseResult = (0, tsconfig_1.parseConfigFileWithSystem)(configFileName, commandLineOptions);
|
|
55
55
|
updateReportDiagnostic(configParseResult.options);
|
|
56
56
|
if (configParseResult.options.watch) {
|
|
57
57
|
createWatchOfConfigFile(configFileName, commandLineOptions);
|
|
@@ -106,14 +106,14 @@ function createWatchOfFilesAndCompilerOptions(rootFiles, options) {
|
|
|
106
106
|
}
|
|
107
107
|
function updateWatchCompilationHost(host, optionsToExtend) {
|
|
108
108
|
let hadErrorLastTime = true;
|
|
109
|
-
const updateConfigFile = tsconfig_1.createConfigFileUpdater(optionsToExtend);
|
|
109
|
+
const updateConfigFile = (0, tsconfig_1.createConfigFileUpdater)(optionsToExtend);
|
|
110
110
|
const transpiler = new tstl.Transpiler();
|
|
111
111
|
host.afterProgramCreate = builderProgram => {
|
|
112
112
|
const program = builderProgram.getProgram();
|
|
113
113
|
const options = builderProgram.getCompilerOptions();
|
|
114
114
|
const configFileParsingDiagnostics = updateConfigFile(options);
|
|
115
115
|
let sourceFiles;
|
|
116
|
-
if (!CompilerOptions_1.isBundleEnabled(options) && !hadErrorLastTime) {
|
|
116
|
+
if (!(0, CompilerOptions_1.isBundleEnabled)(options) && !hadErrorLastTime) {
|
|
117
117
|
sourceFiles = [];
|
|
118
118
|
while (true) {
|
|
119
119
|
const currentFile = builderProgram.getSemanticDiagnosticsOfNextAffectedFile();
|
package/dist/utils.js
CHANGED
|
@@ -12,7 +12,7 @@ const intersperse = (values, separator) => values.flatMap((value, index) => (ind
|
|
|
12
12
|
exports.intersperse = intersperse;
|
|
13
13
|
const union = (...values) => [...new Set(...values)];
|
|
14
14
|
exports.union = union;
|
|
15
|
-
const intersection = (first, ...rest) => exports.union(first).filter(x => rest.every(r => r.includes(x)));
|
|
15
|
+
const intersection = (first, ...rest) => (0, exports.union)(first).filter(x => rest.every(r => r.includes(x)));
|
|
16
16
|
exports.intersection = intersection;
|
|
17
17
|
const createDiagnosticFactoryWithCode = (code, create) => Object.assign((...args) => ({
|
|
18
18
|
file: undefined,
|
|
@@ -25,7 +25,7 @@ const createDiagnosticFactoryWithCode = (code, create) => Object.assign((...args
|
|
|
25
25
|
}), { code });
|
|
26
26
|
exports.createDiagnosticFactoryWithCode = createDiagnosticFactoryWithCode;
|
|
27
27
|
let serialDiagnosticCodeCounter = 100000;
|
|
28
|
-
const createSerialDiagnosticFactory = (create) => exports.createDiagnosticFactoryWithCode(serialDiagnosticCodeCounter++, create);
|
|
28
|
+
const createSerialDiagnosticFactory = (create) => (0, exports.createDiagnosticFactoryWithCode)(serialDiagnosticCodeCounter++, create);
|
|
29
29
|
exports.createSerialDiagnosticFactory = createSerialDiagnosticFactory;
|
|
30
30
|
const normalizeSlashes = (filePath) => filePath.replace(/\\/g, "/");
|
|
31
31
|
exports.normalizeSlashes = normalizeSlashes;
|