typescript-to-lua 1.6.2 → 1.6.3
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/cli/diagnostics.d.ts +3 -0
- package/dist/cli/diagnostics.js +2 -1
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +42 -11
- package/dist/transpilation/index.js +4 -8
- package/dist/tstl.js +2 -4
- package/package.json +1 -1
|
@@ -9,6 +9,9 @@ export declare const unknownCompilerOption: ((name: string) => ts.Diagnostic) &
|
|
|
9
9
|
export declare const compilerOptionRequiresAValueOfType: ((name: string, type: string) => ts.Diagnostic) & {
|
|
10
10
|
code: number;
|
|
11
11
|
};
|
|
12
|
+
export declare const compilerOptionCouldNotParseJson: ((name: string, error: string) => ts.Diagnostic) & {
|
|
13
|
+
code: number;
|
|
14
|
+
};
|
|
12
15
|
export declare const optionProjectCannotBeMixedWithSourceFilesOnACommandLine: (() => ts.Diagnostic) & {
|
|
13
16
|
code: number;
|
|
14
17
|
};
|
package/dist/cli/diagnostics.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
|
|
3
|
+
exports.optionBuildMustBeFirstCommandLineArgument = exports.optionCanOnlyBeSpecifiedInTsconfigJsonFile = exports.argumentForOptionMustBe = exports.compilerOptionExpectsAnArgument = exports.theSpecifiedPathDoesNotExist = exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = exports.compilerOptionCouldNotParseJson = exports.compilerOptionRequiresAValueOfType = exports.unknownCompilerOption = exports.watchErrorSummary = exports.tstlOptionsAreMovingToTheTstlObject = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
exports.tstlOptionsAreMovingToTheTstlObject = (0, utils_1.createSerialDiagnosticFactory)((tstl) => ({
|
|
@@ -22,6 +22,7 @@ exports.watchErrorSummary = watchErrorSummary;
|
|
|
22
22
|
const createCommandLineError = (code, getMessage) => (0, utils_1.createDiagnosticFactoryWithCode)(code, (...args) => ({ messageText: getMessage(...args) }));
|
|
23
23
|
exports.unknownCompilerOption = createCommandLineError(5023, (name) => `Unknown compiler option '${name}'.`);
|
|
24
24
|
exports.compilerOptionRequiresAValueOfType = createCommandLineError(5024, (name, type) => `Compiler option '${name}' requires a value of type ${type}.`);
|
|
25
|
+
exports.compilerOptionCouldNotParseJson = createCommandLineError(5025, (name, error) => `Compiler option '${name}' failed to parse the given JSON value: '${error}'.`);
|
|
25
26
|
exports.optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError(5042, () => "Option 'project' cannot be mixed with source files on a command line.");
|
|
26
27
|
exports.cannotFindATsconfigJsonAtTheSpecifiedDirectory = createCommandLineError(5057, (dir) => `Cannot find a tsconfig.json file at the specified directory: '${dir}'.`);
|
|
27
28
|
exports.theSpecifiedPathDoesNotExist = createCommandLineError(5058, (dir) => `The specified path does not exist: '${dir}'.`);
|
package/dist/cli/parse.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
|
|
|
13
13
|
choices: string[];
|
|
14
14
|
}
|
|
15
15
|
interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
|
|
16
|
-
type: "boolean" | "string" | "
|
|
16
|
+
type: "boolean" | "string" | "json-array-of-objects" | "array";
|
|
17
17
|
}
|
|
18
18
|
declare type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive;
|
|
19
19
|
export declare const optionDeclarations: CommandLineOption[];
|
package/dist/cli/parse.js
CHANGED
|
@@ -62,7 +62,7 @@ exports.optionDeclarations = [
|
|
|
62
62
|
{
|
|
63
63
|
name: "luaPlugins",
|
|
64
64
|
description: "List of TypeScriptToLua plugins.",
|
|
65
|
-
type: "
|
|
65
|
+
type: "json-array-of-objects",
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
name: "tstlVerbose",
|
|
@@ -101,7 +101,7 @@ function updateParsedConfigFile(parsedConfigFile) {
|
|
|
101
101
|
parsedConfigFile.errors.push(cliDiagnostics.unknownCompilerOption(name));
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
|
-
const { error, value } = readValue(option, rawValue);
|
|
104
|
+
const { error, value } = readValue(option, rawValue, OptionSource.TsConfig);
|
|
105
105
|
if (error)
|
|
106
106
|
parsedConfigFile.errors.push(error);
|
|
107
107
|
if (parsedConfigFile.options[name] === undefined)
|
|
@@ -140,9 +140,9 @@ function updateParsedCommandLine(parsedCommandLine, args) {
|
|
|
140
140
|
parsedCommandLine.errors.push(error);
|
|
141
141
|
parsedCommandLine.options[option.name] = value;
|
|
142
142
|
if (consumed) {
|
|
143
|
-
i += 1;
|
|
144
143
|
// Values of custom options are parsed as a file name, exclude them
|
|
145
|
-
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !==
|
|
144
|
+
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !== args[i + 1]);
|
|
145
|
+
i += 1;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -165,15 +165,19 @@ function readCommandLineArgument(option, value) {
|
|
|
165
165
|
consumed: false,
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
-
return { ...readValue(option, value), consumed: true };
|
|
168
|
+
return { ...readValue(option, value, OptionSource.CommandLine), consumed: true };
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
var OptionSource;
|
|
171
|
+
(function (OptionSource) {
|
|
172
|
+
OptionSource[OptionSource["CommandLine"] = 0] = "CommandLine";
|
|
173
|
+
OptionSource[OptionSource["TsConfig"] = 1] = "TsConfig";
|
|
174
|
+
})(OptionSource || (OptionSource = {}));
|
|
175
|
+
function readValue(option, value, source) {
|
|
171
176
|
if (value === null)
|
|
172
177
|
return { value };
|
|
173
178
|
switch (option.type) {
|
|
174
179
|
case "boolean":
|
|
175
|
-
case "string":
|
|
176
|
-
case "object": {
|
|
180
|
+
case "string": {
|
|
177
181
|
if (typeof value !== option.type) {
|
|
178
182
|
return {
|
|
179
183
|
value: undefined,
|
|
@@ -182,14 +186,41 @@ function readValue(option, value) {
|
|
|
182
186
|
}
|
|
183
187
|
return { value };
|
|
184
188
|
}
|
|
185
|
-
case "array":
|
|
186
|
-
|
|
189
|
+
case "array":
|
|
190
|
+
case "json-array-of-objects": {
|
|
191
|
+
const isInvalidNonCliValue = source === OptionSource.TsConfig && !Array.isArray(value);
|
|
192
|
+
const isInvalidCliValue = source === OptionSource.CommandLine && typeof value !== "string";
|
|
193
|
+
if (isInvalidNonCliValue || isInvalidCliValue) {
|
|
187
194
|
return {
|
|
188
195
|
value: undefined,
|
|
189
196
|
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
190
197
|
};
|
|
191
198
|
}
|
|
192
|
-
|
|
199
|
+
const shouldParseValue = source === OptionSource.CommandLine && typeof value === "string";
|
|
200
|
+
if (!shouldParseValue)
|
|
201
|
+
return { value };
|
|
202
|
+
if (option.type === "array") {
|
|
203
|
+
const array = value.split(",");
|
|
204
|
+
return { value: array };
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const objects = JSON.parse(value);
|
|
208
|
+
if (!Array.isArray(objects)) {
|
|
209
|
+
return {
|
|
210
|
+
value: undefined,
|
|
211
|
+
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { value: objects };
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
if (!(e instanceof SyntaxError))
|
|
218
|
+
throw e;
|
|
219
|
+
return {
|
|
220
|
+
value: undefined,
|
|
221
|
+
error: cliDiagnostics.compilerOptionCouldNotParseJson(option.name, e.message),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
193
224
|
}
|
|
194
225
|
case "enum": {
|
|
195
226
|
if (typeof value !== "string") {
|
|
@@ -26,11 +26,9 @@ __exportStar(require("./transpile"), exports);
|
|
|
26
26
|
__exportStar(require("./transpiler"), exports);
|
|
27
27
|
function transpileFiles(rootNames, options = {}, writeFile) {
|
|
28
28
|
const program = ts.createProgram(rootNames, options);
|
|
29
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
29
30
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new transpiler_1.Transpiler().emit({ program, writeFile });
|
|
30
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
31
|
-
...ts.getPreEmitDiagnostics(program),
|
|
32
|
-
...transpileDiagnostics,
|
|
33
|
-
]);
|
|
31
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
34
32
|
return { diagnostics: [...diagnostics], emitSkipped };
|
|
35
33
|
}
|
|
36
34
|
exports.transpileFiles = transpileFiles;
|
|
@@ -85,12 +83,10 @@ function createVirtualProgram(input, options = {}) {
|
|
|
85
83
|
exports.createVirtualProgram = createVirtualProgram;
|
|
86
84
|
function transpileVirtualProject(files, options = {}) {
|
|
87
85
|
const program = createVirtualProgram(files, options);
|
|
86
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
88
87
|
const collector = (0, output_collector_1.createEmitOutputCollector)();
|
|
89
88
|
const { diagnostics: transpileDiagnostics } = new transpiler_1.Transpiler().emit({ program, writeFile: collector.writeFile });
|
|
90
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
91
|
-
...ts.getPreEmitDiagnostics(program),
|
|
92
|
-
...transpileDiagnostics,
|
|
93
|
-
]);
|
|
89
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
94
90
|
return { diagnostics: [...diagnostics], transpiledFiles: collector.files };
|
|
95
91
|
}
|
|
96
92
|
exports.transpileVirtualProject = transpileVirtualProject;
|
package/dist/tstl.js
CHANGED
|
@@ -81,11 +81,9 @@ function performCompilation(rootNames, projectReferences, options, configFilePar
|
|
|
81
81
|
projectReferences,
|
|
82
82
|
configFileParsingDiagnostics,
|
|
83
83
|
});
|
|
84
|
+
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
84
85
|
const { diagnostics: transpileDiagnostics, emitSkipped } = new tstl.Transpiler().emit({ program });
|
|
85
|
-
const diagnostics = ts.sortAndDeduplicateDiagnostics([
|
|
86
|
-
...ts.getPreEmitDiagnostics(program),
|
|
87
|
-
...transpileDiagnostics,
|
|
88
|
-
]);
|
|
86
|
+
const diagnostics = ts.sortAndDeduplicateDiagnostics([...preEmitDiagnostics, ...transpileDiagnostics]);
|
|
89
87
|
diagnostics.forEach(reportDiagnostic);
|
|
90
88
|
const exitCode = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error).length === 0
|
|
91
89
|
? ts.ExitStatus.Success
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
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/",
|