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
|
@@ -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,7 +142,7 @@ 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
|
}
|
|
140
147
|
// Check if the import is relative
|
|
141
148
|
const isRelative = ["/", "./", "../"].some(p => dependency.startsWith(p));
|
|
@@ -246,13 +253,13 @@ function findRequiredPaths(code) {
|
|
|
246
253
|
return paths;
|
|
247
254
|
}
|
|
248
255
|
function replaceRequireInCode(file, originalRequire, newRequire) {
|
|
249
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
256
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
250
257
|
// Escape special characters to prevent the regex from breaking...
|
|
251
258
|
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
252
259
|
file.code = file.code.replace(new RegExp(`(^|\\s|;|=)require\\("${escapedRequire}"\\)`), `$1require("${requirePath}")`);
|
|
253
260
|
}
|
|
254
261
|
function replaceRequireInSourceMap(file, originalRequire, newRequire) {
|
|
255
|
-
const requirePath = utils_1.formatPathToLuaPath(newRequire.replace(".lua", ""));
|
|
262
|
+
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
256
263
|
if (file.sourceMapNode) {
|
|
257
264
|
replaceInSourceMap(file.sourceMapNode, file.sourceMapNode, `"${originalRequire}"`, `"${requirePath}"`);
|
|
258
265
|
}
|
|
@@ -281,14 +288,14 @@ function isProjectFile(file, program) {
|
|
|
281
288
|
return program.getSourceFile(file) !== undefined;
|
|
282
289
|
}
|
|
283
290
|
function hasSourceFileInProject(filePath, program) {
|
|
284
|
-
const pathWithoutExtension = utils_1.trimExtension(filePath);
|
|
291
|
+
const pathWithoutExtension = (0, utils_1.trimExtension)(filePath);
|
|
285
292
|
return (isProjectFile(pathWithoutExtension + ".ts", program) ||
|
|
286
293
|
isProjectFile(pathWithoutExtension + ".tsx", program) ||
|
|
287
294
|
isProjectFile(pathWithoutExtension + ".json", program));
|
|
288
295
|
}
|
|
289
296
|
// Transform an import path to a lua require that is probably not correct, but can be used as fallback when regular resolution fails
|
|
290
297
|
function fallbackResolve(required, sourceRootDir, fileDir) {
|
|
291
|
-
return utils_1.formatPathToLuaPath(path
|
|
298
|
+
return (0, utils_1.formatPathToLuaPath)(path
|
|
292
299
|
.normalize(path.join(path.relative(sourceRootDir, fileDir), required))
|
|
293
300
|
.split(path.sep)
|
|
294
301
|
.filter(s => s !== "." && s !== "..")
|
|
@@ -58,6 +58,9 @@ 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
|
+
}
|
|
61
64
|
return ts.visitEachChild(node, visit, context);
|
|
62
65
|
}
|
|
63
66
|
return ts.visitNode(sourceFile, visit);
|
|
@@ -70,32 +73,46 @@ function loadTransformersFromOptions(program, diagnostics) {
|
|
|
70
73
|
afterDeclarations: [],
|
|
71
74
|
};
|
|
72
75
|
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
|
-
|
|
76
|
+
if (options.plugins) {
|
|
77
|
+
for (const [index, transformerImport] of options.plugins.entries()) {
|
|
78
|
+
if (!("transform" in transformerImport))
|
|
79
|
+
continue;
|
|
80
|
+
const optionName = `compilerOptions.plugins[${index}]`;
|
|
81
|
+
const { error: resolveError, result: factory } = (0, utils_1.resolvePlugin)("transformer", `${optionName}.transform`, (0, utils_1.getConfigDirectory)(options), transformerImport.transform, transformerImport.import);
|
|
82
|
+
if (resolveError)
|
|
83
|
+
diagnostics.push(resolveError);
|
|
84
|
+
if (factory === undefined)
|
|
85
|
+
continue;
|
|
86
|
+
const { error: loadError, transformer } = loadTransformer(optionName, program, factory, transformerImport);
|
|
87
|
+
if (loadError)
|
|
88
|
+
diagnostics.push(loadError);
|
|
89
|
+
if (transformer === undefined)
|
|
90
|
+
continue;
|
|
91
|
+
if (transformer.before) {
|
|
92
|
+
customTransformers.before.push(transformer.before);
|
|
93
|
+
}
|
|
94
|
+
if (transformer.after) {
|
|
95
|
+
customTransformers.after.push(transformer.after);
|
|
96
|
+
}
|
|
97
|
+
if (transformer.afterDeclarations) {
|
|
98
|
+
customTransformers.afterDeclarations.push(transformer.afterDeclarations);
|
|
99
|
+
}
|
|
97
100
|
}
|
|
98
101
|
}
|
|
102
|
+
if (options.jsx === ts.JsxEmit.React) {
|
|
103
|
+
customTransformers.before.push(context => {
|
|
104
|
+
// if target < ES2017, typescript generates some unnecessary additional transformations in transformJSX.
|
|
105
|
+
// We can't control the target compiler option, so we override here.
|
|
106
|
+
const patchedContext = {
|
|
107
|
+
...context,
|
|
108
|
+
getCompilerOptions: () => ({
|
|
109
|
+
...context.getCompilerOptions(),
|
|
110
|
+
target: ts.ScriptTarget.ESNext,
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
return ts.transformJsx(patchedContext);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
99
116
|
return customTransformers;
|
|
100
117
|
}
|
|
101
118
|
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;
|
|
@@ -12,12 +12,13 @@ function resolvePlugin(kind, optionName, basedir, query, importName = "default")
|
|
|
12
12
|
if (typeof query !== "string") {
|
|
13
13
|
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "string") };
|
|
14
14
|
}
|
|
15
|
+
const isModuleNotFoundError = (error) => error.code === "MODULE_NOT_FOUND";
|
|
15
16
|
let resolved;
|
|
16
17
|
try {
|
|
17
18
|
resolved = resolve.sync(query, { basedir, extensions: [".js", ".ts", ".tsx"] });
|
|
18
19
|
}
|
|
19
20
|
catch (err) {
|
|
20
|
-
if (err
|
|
21
|
+
if (!isModuleNotFoundError(err))
|
|
21
22
|
throw err;
|
|
22
23
|
return { error: diagnosticFactories.couldNotResolveFrom(kind, query, basedir) };
|
|
23
24
|
}
|
|
@@ -29,7 +30,7 @@ function resolvePlugin(kind, optionName, basedir, query, importName = "default")
|
|
|
29
30
|
tsNode.register({ transpileOnly: true });
|
|
30
31
|
}
|
|
31
32
|
catch (err) {
|
|
32
|
-
if (err
|
|
33
|
+
if (!isModuleNotFoundError(err))
|
|
33
34
|
throw err;
|
|
34
35
|
return { error: diagnosticFactories.toLoadItShouldBeTranspiled(kind, query) };
|
|
35
36
|
}
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|
|
@@ -41,11 +41,13 @@
|
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=12.13.0"
|
|
43
43
|
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"typescript": "~4.4.4"
|
|
46
|
+
},
|
|
44
47
|
"dependencies": {
|
|
45
48
|
"enhanced-resolve": "^5.8.2",
|
|
46
49
|
"resolve": "^1.15.1",
|
|
47
|
-
"source-map": "^0.7.3"
|
|
48
|
-
"typescript": "~4.3.5"
|
|
50
|
+
"source-map": "^0.7.3"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@types/fs-extra": "^8.1.0",
|
|
@@ -53,19 +55,20 @@
|
|
|
53
55
|
"@types/jest": "^25.1.3",
|
|
54
56
|
"@types/node": "^13.7.7",
|
|
55
57
|
"@types/resolve": "1.14.0",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
57
|
-
"@typescript-eslint/parser": "^4.
|
|
58
|
-
"eslint": "^7.
|
|
59
|
-
"eslint-plugin-import": "^2.
|
|
60
|
-
"eslint-plugin-jest": "^
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
|
59
|
+
"@typescript-eslint/parser": "^4.31.0",
|
|
60
|
+
"eslint": "^7.32.0",
|
|
61
|
+
"eslint-plugin-import": "^2.24.2",
|
|
62
|
+
"eslint-plugin-jest": "^24.4.0",
|
|
61
63
|
"fs-extra": "^8.1.0",
|
|
62
64
|
"javascript-stringify": "^2.0.1",
|
|
63
|
-
"jest": "^
|
|
64
|
-
"jest-circus": "^
|
|
65
|
+
"jest": "^27.3.0",
|
|
66
|
+
"jest-circus": "^27.3.0",
|
|
65
67
|
"lua-types": "2.10.1",
|
|
66
68
|
"lua-wasm-bindings": "^0.2.2",
|
|
67
69
|
"prettier": "^2.3.2",
|
|
68
|
-
"ts-jest": "^
|
|
69
|
-
"ts-node": "^
|
|
70
|
+
"ts-jest": "^27.0.7",
|
|
71
|
+
"ts-node": "^10.3.0",
|
|
72
|
+
"typescript": "~4.4.4"
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Visitors } from "../../context";
|
|
2
|
-
/**
|
|
3
|
-
* Format a string in the value position of a JSX prop.
|
|
4
|
-
*
|
|
5
|
-
* Use the same implementation as convertAttribute from
|
|
6
|
-
* babel-helper-builder-react-jsx.
|
|
7
|
-
*/
|
|
8
|
-
export declare function formatJSXStringValueLiteral(text: string): string;
|
|
9
|
-
export declare const jsxVisitors: Visitors;
|