typescript-to-lua 1.6.3 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CompilerOptions.d.ts +1 -0
- package/dist/cli/parse.js +5 -0
- package/dist/lualib/ArraySlice.lua +10 -2
- package/dist/lualib/ArraySplice.lua +5 -1
- package/dist/lualib/Generator.lua +8 -1
- package/dist/lualib/ParseFloat.lua +5 -1
- package/dist/lualib/SparseArraySpread.lua +5 -1
- package/dist/lualib/StringCharCodeAt.lua +5 -1
- package/dist/lualib/lualib_bundle.lua +38 -7
- package/dist/lualib-build/plugin.js +1 -2
- package/dist/measure-performance.d.ts +15 -0
- package/dist/measure-performance.js +83 -0
- package/dist/transformation/builtins/array.js +2 -1
- package/dist/transformation/builtins/function.js +1 -1
- package/dist/transformation/builtins/global.d.ts +1 -1
- package/dist/transformation/builtins/global.js +13 -12
- package/dist/transformation/builtins/index.d.ts +2 -2
- package/dist/transformation/builtins/index.js +87 -89
- package/dist/transformation/builtins/object.d.ts +1 -1
- package/dist/transformation/builtins/object.js +4 -4
- package/dist/transformation/builtins/promise.js +4 -2
- package/dist/transformation/builtins/string.js +2 -0
- package/dist/transformation/context/context.d.ts +15 -0
- package/dist/transformation/context/context.js +66 -24
- package/dist/transformation/context/visitors.d.ts +1 -1
- package/dist/transformation/index.js +6 -5
- package/dist/transformation/utils/annotations.d.ts +1 -17
- package/dist/transformation/utils/annotations.js +48 -88
- package/dist/transformation/utils/assignment-validation.js +27 -23
- package/dist/transformation/utils/diagnostics.d.ts +1 -4
- package/dist/transformation/utils/diagnostics.js +2 -3
- package/dist/transformation/utils/function-context.d.ts +1 -1
- package/dist/transformation/utils/function-context.js +57 -51
- package/dist/transformation/utils/language-extensions.d.ts +57 -51
- package/dist/transformation/utils/language-extensions.js +99 -119
- package/dist/transformation/utils/lualib.d.ts +0 -1
- package/dist/transformation/utils/lualib.js +2 -8
- package/dist/transformation/utils/safe-names.d.ts +1 -1
- package/dist/transformation/utils/safe-names.js +3 -6
- package/dist/transformation/utils/scope.d.ts +0 -2
- package/dist/transformation/utils/scope.js +10 -27
- package/dist/transformation/utils/symbols.d.ts +1 -1
- package/dist/transformation/utils/symbols.js +7 -20
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +2 -1
- package/dist/transformation/utils/typescript/types.d.ts +2 -5
- package/dist/transformation/utils/typescript/types.js +27 -37
- package/dist/transformation/visitors/access.js +1 -4
- package/dist/transformation/visitors/block.js +4 -4
- package/dist/transformation/visitors/call.js +10 -21
- package/dist/transformation/visitors/class/index.js +8 -20
- package/dist/transformation/visitors/class/members/constructor.js +2 -2
- package/dist/transformation/visitors/class/new.js +2 -5
- package/dist/transformation/visitors/class/setup.d.ts +1 -1
- package/dist/transformation/visitors/class/setup.js +4 -4
- package/dist/transformation/visitors/class/utils.d.ts +1 -1
- package/dist/transformation/visitors/class/utils.js +2 -9
- package/dist/transformation/visitors/conditional.js +4 -4
- package/dist/transformation/visitors/function.d.ts +1 -1
- package/dist/transformation/visitors/function.js +8 -16
- package/dist/transformation/visitors/identifier.d.ts +1 -0
- package/dist/transformation/visitors/identifier.js +40 -44
- package/dist/transformation/visitors/language-extensions/call-extension.d.ts +10 -0
- package/dist/transformation/visitors/language-extensions/call-extension.js +23 -0
- package/dist/transformation/visitors/language-extensions/identifier.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/identifier.js +27 -0
- package/dist/transformation/visitors/language-extensions/iterable.d.ts +2 -3
- package/dist/transformation/visitors/language-extensions/iterable.js +23 -22
- package/dist/transformation/visitors/language-extensions/multi.d.ts +0 -1
- package/dist/transformation/visitors/language-extensions/multi.js +10 -24
- package/dist/transformation/visitors/language-extensions/operators.d.ts +2 -5
- package/dist/transformation/visitors/language-extensions/operators.js +89 -96
- package/dist/transformation/visitors/language-extensions/range.js +4 -2
- package/dist/transformation/visitors/language-extensions/table.d.ts +6 -3
- package/dist/transformation/visitors/language-extensions/table.js +46 -75
- package/dist/transformation/visitors/language-extensions/vararg.js +7 -3
- package/dist/transformation/visitors/literal.js +2 -23
- package/dist/transformation/visitors/loops/for-of.js +18 -18
- package/dist/transformation/visitors/loops/utils.js +5 -5
- package/dist/transformation/visitors/modules/import.js +2 -2
- package/dist/transformation/visitors/namespace.js +5 -14
- package/dist/transformation/visitors/return.js +2 -3
- package/dist/transformation/visitors/sourceFile.js +3 -4
- package/dist/transformation/visitors/spread.js +0 -5
- package/dist/transformation/visitors/switch.js +2 -2
- package/dist/transformation/visitors/variable-declaration.js +1 -1
- package/dist/transpilation/plugins.js +3 -0
- package/dist/transpilation/resolve.js +210 -186
- package/dist/transpilation/transpile.js +10 -0
- package/dist/transpilation/transpiler.d.ts +1 -0
- package/dist/transpilation/transpiler.js +18 -5
- package/dist/tstl.js +21 -0
- package/language-extensions/index.d.ts +167 -67
- package/package.json +2 -2
- package/dist/transformation/visitors/language-extensions/index.d.ts +0 -4
- package/dist/transformation/visitors/language-extensions/index.js +0 -17
- package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +0 -5
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +0 -53
|
@@ -8,8 +8,10 @@ const LuaPrinter_1 = require("../LuaPrinter");
|
|
|
8
8
|
const transformation_1 = require("../transformation");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const transformers_1 = require("./transformers");
|
|
11
|
+
const performance = require("../measure-performance");
|
|
11
12
|
function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceFiles: targetSourceFiles, customTransformers = {}, plugins = [] }) {
|
|
12
13
|
var _a, _b;
|
|
14
|
+
performance.startSection("beforeTransform");
|
|
13
15
|
const options = program.getCompilerOptions();
|
|
14
16
|
if (options.tstlVerbose) {
|
|
15
17
|
console.log("Parsing project settings");
|
|
@@ -36,6 +38,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
36
38
|
preEmitDiagnostics.push(...program.getDeclarationDiagnostics());
|
|
37
39
|
}
|
|
38
40
|
if (preEmitDiagnostics.length > 0) {
|
|
41
|
+
performance.endSection("beforeTransform");
|
|
39
42
|
return { diagnostics: preEmitDiagnostics, transpiledFiles };
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -51,9 +54,12 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
51
54
|
if (options.tstlVerbose) {
|
|
52
55
|
console.log(`Transforming ${sourceFile.fileName}`);
|
|
53
56
|
}
|
|
57
|
+
performance.startSection("transpile");
|
|
54
58
|
const { file, diagnostics: transformDiagnostics } = (0, transformation_1.transformSourceFile)(program, sourceFile, visitorMap);
|
|
55
59
|
diagnostics.push(...transformDiagnostics);
|
|
60
|
+
performance.endSection("transpile");
|
|
56
61
|
if (!options.noEmit && !options.emitDeclarationOnly) {
|
|
62
|
+
performance.startSection("print");
|
|
57
63
|
if (options.tstlVerbose) {
|
|
58
64
|
console.log(`Printing ${sourceFile.fileName}`);
|
|
59
65
|
}
|
|
@@ -64,6 +70,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
64
70
|
luaAst: file,
|
|
65
71
|
...printResult,
|
|
66
72
|
});
|
|
73
|
+
performance.endSection("print");
|
|
67
74
|
}
|
|
68
75
|
};
|
|
69
76
|
const transformers = (0, transformers_1.getTransformers)(program, diagnostics, customTransformers, processSourceFile);
|
|
@@ -78,6 +85,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
78
85
|
writeFileResult(fileName, ...rest);
|
|
79
86
|
}
|
|
80
87
|
};
|
|
88
|
+
performance.endSection("beforeTransform");
|
|
81
89
|
if (targetSourceFiles) {
|
|
82
90
|
for (const file of targetSourceFiles) {
|
|
83
91
|
if (isEmittableJsonFile(file)) {
|
|
@@ -93,6 +101,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
93
101
|
// JSON files don't get through transformers and aren't written when outDir is the same as rootDir
|
|
94
102
|
program.getSourceFiles().filter(isEmittableJsonFile).forEach(processSourceFile);
|
|
95
103
|
}
|
|
104
|
+
performance.startSection("afterPrint");
|
|
96
105
|
options.noEmit = oldNoEmit;
|
|
97
106
|
if (options.noEmit || (options.noEmitOnError && diagnostics.length > 0)) {
|
|
98
107
|
transpiledFiles = [];
|
|
@@ -103,6 +112,7 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
103
112
|
diagnostics.push(...pluginDiagnostics);
|
|
104
113
|
}
|
|
105
114
|
}
|
|
115
|
+
performance.endSection("afterPrint");
|
|
106
116
|
return { diagnostics, transpiledFiles };
|
|
107
117
|
}
|
|
108
118
|
exports.getProgramTranspileResult = getProgramTranspileResult;
|
|
@@ -15,6 +15,7 @@ export declare class Transpiler {
|
|
|
15
15
|
protected emitHost: EmitHost;
|
|
16
16
|
constructor({ emitHost }?: TranspilerOptions);
|
|
17
17
|
emit(emitOptions: EmitOptions): EmitResult;
|
|
18
|
+
private emitFiles;
|
|
18
19
|
protected getEmitPlan(program: ts.Program, diagnostics: ts.Diagnostic[], files: ProcessedFile[]): {
|
|
19
20
|
emitPlan: EmitFile[];
|
|
20
21
|
};
|
|
@@ -10,24 +10,34 @@ const bundle_1 = require("./bundle");
|
|
|
10
10
|
const plugins_1 = require("./plugins");
|
|
11
11
|
const resolve_1 = require("./resolve");
|
|
12
12
|
const transpile_1 = require("./transpile");
|
|
13
|
+
const performance = require("../measure-performance");
|
|
13
14
|
class Transpiler {
|
|
14
15
|
constructor({ emitHost = ts.sys } = {}) {
|
|
15
16
|
this.emitHost = emitHost;
|
|
16
17
|
}
|
|
17
18
|
emit(emitOptions) {
|
|
18
|
-
var _a, _b;
|
|
19
19
|
const { program, writeFile = this.emitHost.writeFile, plugins: optionsPlugins = [] } = emitOptions;
|
|
20
|
-
const options = program.getCompilerOptions();
|
|
21
20
|
const { diagnostics: getPluginsDiagnostics, plugins: configPlugins } = (0, plugins_1.getPlugins)(program);
|
|
22
21
|
const plugins = [...optionsPlugins, ...configPlugins];
|
|
23
|
-
const { diagnostics, transpiledFiles: freshFiles } = (0, transpile_1.getProgramTranspileResult)(this.emitHost, writeFile, {
|
|
22
|
+
const { diagnostics: transpileDiagnostics, transpiledFiles: freshFiles } = (0, transpile_1.getProgramTranspileResult)(this.emitHost, writeFile, {
|
|
24
23
|
...emitOptions,
|
|
25
24
|
plugins,
|
|
26
25
|
});
|
|
27
|
-
const { emitPlan } = this.getEmitPlan(program,
|
|
26
|
+
const { emitPlan } = this.getEmitPlan(program, transpileDiagnostics, freshFiles);
|
|
27
|
+
const emitDiagnostics = this.emitFiles(program, plugins, emitPlan, writeFile);
|
|
28
|
+
return {
|
|
29
|
+
diagnostics: getPluginsDiagnostics.concat(transpileDiagnostics, emitDiagnostics),
|
|
30
|
+
emitSkipped: emitPlan.length === 0,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
emitFiles(program, plugins, emitPlan, writeFile) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
performance.startSection("emit");
|
|
36
|
+
const options = program.getCompilerOptions();
|
|
28
37
|
if (options.tstlVerbose) {
|
|
29
38
|
console.log("Emitting output");
|
|
30
39
|
}
|
|
40
|
+
const diagnostics = [];
|
|
31
41
|
for (const plugin of plugins) {
|
|
32
42
|
if (plugin.beforeEmit) {
|
|
33
43
|
const beforeEmitPluginDiagnostics = (_a = plugin.beforeEmit(program, options, this.emitHost, emitPlan)) !== null && _a !== void 0 ? _a : [];
|
|
@@ -47,9 +57,11 @@ class Transpiler {
|
|
|
47
57
|
if (options.tstlVerbose) {
|
|
48
58
|
console.log("Emit finished!");
|
|
49
59
|
}
|
|
50
|
-
|
|
60
|
+
performance.endSection("emit");
|
|
61
|
+
return diagnostics;
|
|
51
62
|
}
|
|
52
63
|
getEmitPlan(program, diagnostics, files) {
|
|
64
|
+
performance.startSection("getEmitPlan");
|
|
53
65
|
const options = program.getCompilerOptions();
|
|
54
66
|
if (options.tstlVerbose) {
|
|
55
67
|
console.log("Constructing emit plan");
|
|
@@ -80,6 +92,7 @@ class Transpiler {
|
|
|
80
92
|
outputPath: getEmitPath(file.fileName, program),
|
|
81
93
|
}));
|
|
82
94
|
}
|
|
95
|
+
performance.endSection("getEmitPlan");
|
|
83
96
|
return { emitPlan };
|
|
84
97
|
}
|
|
85
98
|
}
|
package/dist/tstl.js
CHANGED
|
@@ -9,6 +9,7 @@ const parse_1 = require("./cli/parse");
|
|
|
9
9
|
const report_1 = require("./cli/report");
|
|
10
10
|
const tsconfig_1 = require("./cli/tsconfig");
|
|
11
11
|
const CompilerOptions_1 = require("./CompilerOptions");
|
|
12
|
+
const performance = require("./measure-performance");
|
|
12
13
|
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
14
|
let reportDiagnostic = (0, report_1.createDiagnosticReporter)(false);
|
|
14
15
|
function updateReportDiagnostic(options) {
|
|
@@ -75,6 +76,9 @@ function performBuild(_args) {
|
|
|
75
76
|
return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
|
76
77
|
}
|
|
77
78
|
function performCompilation(rootNames, projectReferences, options, configFileParsingDiagnostics) {
|
|
79
|
+
if (options.measurePerformance)
|
|
80
|
+
performance.enableMeasurement();
|
|
81
|
+
performance.startSection("createProgram");
|
|
78
82
|
const program = ts.createProgram({
|
|
79
83
|
rootNames,
|
|
80
84
|
options,
|
|
@@ -82,9 +86,12 @@ function performCompilation(rootNames, projectReferences, options, configFilePar
|
|
|
82
86
|
configFileParsingDiagnostics,
|
|
83
87
|
});
|
|
84
88
|
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
89
|
+
performance.endSection("createProgram");
|
|
85
90
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new tstl.Transpiler().emit({ program });
|
|
86
91
|
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
87
92
|
diagnostics.forEach(reportDiagnostic);
|
|
93
|
+
if (options.measurePerformance)
|
|
94
|
+
reportPerformance();
|
|
88
95
|
const exitCode = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error).length === 0
|
|
89
96
|
? ts.ExitStatus.Success
|
|
90
97
|
: emitSkipped
|
|
@@ -109,6 +116,8 @@ function updateWatchCompilationHost(host, optionsToExtend) {
|
|
|
109
116
|
host.afterProgramCreate = builderProgram => {
|
|
110
117
|
const program = builderProgram.getProgram();
|
|
111
118
|
const options = builderProgram.getCompilerOptions();
|
|
119
|
+
if (options.measurePerformance)
|
|
120
|
+
performance.enableMeasurement();
|
|
112
121
|
const configFileParsingDiagnostics = updateConfigFile(options);
|
|
113
122
|
let sourceFiles;
|
|
114
123
|
if (!(0, CompilerOptions_1.isBundleEnabled)(options) && !hadErrorLastTime) {
|
|
@@ -135,11 +144,23 @@ function updateWatchCompilationHost(host, optionsToExtend) {
|
|
|
135
144
|
...emitDiagnostics,
|
|
136
145
|
]);
|
|
137
146
|
diagnostics.forEach(reportDiagnostic);
|
|
147
|
+
if (options.measurePerformance)
|
|
148
|
+
reportPerformance();
|
|
138
149
|
const errors = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
|
|
139
150
|
hadErrorLastTime = errors.length > 0;
|
|
140
151
|
host.onWatchStatusChange(cliDiagnostics.watchErrorSummary(errors.length), host.getNewLine(), options);
|
|
141
152
|
};
|
|
142
153
|
}
|
|
154
|
+
function reportPerformance() {
|
|
155
|
+
if (performance.isMeasurementEnabled()) {
|
|
156
|
+
console.log("Performance measurements: ");
|
|
157
|
+
performance.forEachMeasure((name, duration) => {
|
|
158
|
+
console.log(` ${name}: ${duration.toFixed(2)}ms`);
|
|
159
|
+
});
|
|
160
|
+
console.log(`Total: ${performance.getTotalDuration().toFixed(2)}ms`);
|
|
161
|
+
performance.disableMeasurement();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
143
164
|
function checkNodeVersion() {
|
|
144
165
|
const [major, minor] = process.version.slice(1).split(".").map(Number);
|
|
145
166
|
const isValid = major > 12 || (major === 12 && minor >= 13);
|