typescript-to-lua 1.6.1 → 1.7.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/dist/CompilerOptions.d.ts +1 -0
- package/dist/LuaPrinter.js +1 -0
- 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 +47 -11
- 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/Promise.lua +6 -3
- package/dist/lualib/SparseArraySpread.lua +5 -1
- package/dist/lualib/StringCharCodeAt.lua +5 -1
- package/dist/lualib/lualib_bundle.lua +44 -10
- 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 +7 -18
- 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 +21 -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/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/index.js +4 -8
- package/dist/transpilation/plugins.js +3 -0
- package/dist/transpilation/resolve.js +144 -161
- 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 +23 -4
- package/language-extensions/index.d.ts +156 -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
|
@@ -31,6 +31,7 @@ export interface TypeScriptToLuaOptions {
|
|
|
31
31
|
sourceMapTraceback?: boolean;
|
|
32
32
|
tstlVerbose?: boolean;
|
|
33
33
|
lua51AllowTryCatchInAsyncAwait?: boolean;
|
|
34
|
+
measurePerformance?: boolean;
|
|
34
35
|
}
|
|
35
36
|
export declare type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & TypeScriptToLuaOptions & {
|
|
36
37
|
[option: string]: any;
|
package/dist/LuaPrinter.js
CHANGED
|
@@ -142,6 +142,7 @@ class LuaPrinter {
|
|
|
142
142
|
// Inline lualib features
|
|
143
143
|
sourceChunks.push("-- Lua Library inline imports\n");
|
|
144
144
|
sourceChunks.push((0, LuaLib_1.loadInlineLualibFeatures)(file.luaLibFeatures, this.emitHost));
|
|
145
|
+
sourceChunks.push("-- End of Lua Library inline imports\n");
|
|
145
146
|
}
|
|
146
147
|
if (this.options.sourceMapTraceback && !(0, CompilerOptions_1.isBundleEnabled)(this.options)) {
|
|
147
148
|
// In bundle mode the traceback is being generated for the entire file in getBundleResult
|
|
@@ -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",
|
|
@@ -79,6 +79,11 @@ exports.optionDeclarations = [
|
|
|
79
79
|
description: "Always allow try/catch in async/await functions for Lua 5.1.",
|
|
80
80
|
type: "boolean",
|
|
81
81
|
},
|
|
82
|
+
{
|
|
83
|
+
name: "measurePerformance",
|
|
84
|
+
description: "Measure performance of the tstl compiler.",
|
|
85
|
+
type: "boolean",
|
|
86
|
+
},
|
|
82
87
|
];
|
|
83
88
|
function updateParsedConfigFile(parsedConfigFile) {
|
|
84
89
|
let hasRootLevelOptions = false;
|
|
@@ -101,7 +106,7 @@ function updateParsedConfigFile(parsedConfigFile) {
|
|
|
101
106
|
parsedConfigFile.errors.push(cliDiagnostics.unknownCompilerOption(name));
|
|
102
107
|
continue;
|
|
103
108
|
}
|
|
104
|
-
const { error, value } = readValue(option, rawValue);
|
|
109
|
+
const { error, value } = readValue(option, rawValue, OptionSource.TsConfig);
|
|
105
110
|
if (error)
|
|
106
111
|
parsedConfigFile.errors.push(error);
|
|
107
112
|
if (parsedConfigFile.options[name] === undefined)
|
|
@@ -140,9 +145,9 @@ function updateParsedCommandLine(parsedCommandLine, args) {
|
|
|
140
145
|
parsedCommandLine.errors.push(error);
|
|
141
146
|
parsedCommandLine.options[option.name] = value;
|
|
142
147
|
if (consumed) {
|
|
143
|
-
i += 1;
|
|
144
148
|
// Values of custom options are parsed as a file name, exclude them
|
|
145
|
-
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !==
|
|
149
|
+
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(f => f !== args[i + 1]);
|
|
150
|
+
i += 1;
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
}
|
|
@@ -165,15 +170,19 @@ function readCommandLineArgument(option, value) {
|
|
|
165
170
|
consumed: false,
|
|
166
171
|
};
|
|
167
172
|
}
|
|
168
|
-
return { ...readValue(option, value), consumed: true };
|
|
173
|
+
return { ...readValue(option, value, OptionSource.CommandLine), consumed: true };
|
|
169
174
|
}
|
|
170
|
-
|
|
175
|
+
var OptionSource;
|
|
176
|
+
(function (OptionSource) {
|
|
177
|
+
OptionSource[OptionSource["CommandLine"] = 0] = "CommandLine";
|
|
178
|
+
OptionSource[OptionSource["TsConfig"] = 1] = "TsConfig";
|
|
179
|
+
})(OptionSource || (OptionSource = {}));
|
|
180
|
+
function readValue(option, value, source) {
|
|
171
181
|
if (value === null)
|
|
172
182
|
return { value };
|
|
173
183
|
switch (option.type) {
|
|
174
184
|
case "boolean":
|
|
175
|
-
case "string":
|
|
176
|
-
case "object": {
|
|
185
|
+
case "string": {
|
|
177
186
|
if (typeof value !== option.type) {
|
|
178
187
|
return {
|
|
179
188
|
value: undefined,
|
|
@@ -182,14 +191,41 @@ function readValue(option, value) {
|
|
|
182
191
|
}
|
|
183
192
|
return { value };
|
|
184
193
|
}
|
|
185
|
-
case "array":
|
|
186
|
-
|
|
194
|
+
case "array":
|
|
195
|
+
case "json-array-of-objects": {
|
|
196
|
+
const isInvalidNonCliValue = source === OptionSource.TsConfig && !Array.isArray(value);
|
|
197
|
+
const isInvalidCliValue = source === OptionSource.CommandLine && typeof value !== "string";
|
|
198
|
+
if (isInvalidNonCliValue || isInvalidCliValue) {
|
|
187
199
|
return {
|
|
188
200
|
value: undefined,
|
|
189
201
|
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
190
202
|
};
|
|
191
203
|
}
|
|
192
|
-
|
|
204
|
+
const shouldParseValue = source === OptionSource.CommandLine && typeof value === "string";
|
|
205
|
+
if (!shouldParseValue)
|
|
206
|
+
return { value };
|
|
207
|
+
if (option.type === "array") {
|
|
208
|
+
const array = value.split(",");
|
|
209
|
+
return { value: array };
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const objects = JSON.parse(value);
|
|
213
|
+
if (!Array.isArray(objects)) {
|
|
214
|
+
return {
|
|
215
|
+
value: undefined,
|
|
216
|
+
error: cliDiagnostics.compilerOptionRequiresAValueOfType(option.name, option.type),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return { value: objects };
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
if (!(e instanceof SyntaxError))
|
|
223
|
+
throw e;
|
|
224
|
+
return {
|
|
225
|
+
value: undefined,
|
|
226
|
+
error: cliDiagnostics.compilerOptionCouldNotParseJson(option.name, e.message),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
193
229
|
}
|
|
194
230
|
case "enum": {
|
|
195
231
|
if (typeof value !== "string") {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
local function __TS__ArraySlice(self, first, last)
|
|
2
2
|
local len = #self
|
|
3
|
-
|
|
3
|
+
local ____first_0 = first
|
|
4
|
+
if ____first_0 == nil then
|
|
5
|
+
____first_0 = 0
|
|
6
|
+
end
|
|
7
|
+
first = ____first_0
|
|
4
8
|
if first < 0 then
|
|
5
9
|
first = len + first
|
|
6
10
|
if first < 0 then
|
|
@@ -11,7 +15,11 @@ local function __TS__ArraySlice(self, first, last)
|
|
|
11
15
|
first = len
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
|
-
|
|
18
|
+
local ____last_1 = last
|
|
19
|
+
if ____last_1 == nil then
|
|
20
|
+
____last_1 = len
|
|
21
|
+
end
|
|
22
|
+
last = ____last_1
|
|
15
23
|
if last < 0 then
|
|
16
24
|
last = len + last
|
|
17
25
|
if last < 0 then
|
|
@@ -22,7 +22,11 @@ local function __TS__ArraySplice(self, ...)
|
|
|
22
22
|
elseif actualArgumentCount == 1 then
|
|
23
23
|
actualDeleteCount = len - start
|
|
24
24
|
else
|
|
25
|
-
|
|
25
|
+
local ____deleteCount_0 = deleteCount
|
|
26
|
+
if ____deleteCount_0 == nil then
|
|
27
|
+
____deleteCount_0 = 0
|
|
28
|
+
end
|
|
29
|
+
actualDeleteCount = ____deleteCount_0
|
|
26
30
|
if actualDeleteCount < 0 then
|
|
27
31
|
actualDeleteCount = 0
|
|
28
32
|
end
|
|
@@ -22,7 +22,14 @@ do
|
|
|
22
22
|
local args = {...}
|
|
23
23
|
local argsLength = select("#", ...)
|
|
24
24
|
return {
|
|
25
|
-
____coroutine = coroutine.create(function()
|
|
25
|
+
____coroutine = coroutine.create(function()
|
|
26
|
+
local ____fn_1 = fn
|
|
27
|
+
local ____unpack_0 = unpack
|
|
28
|
+
if ____unpack_0 == nil then
|
|
29
|
+
____unpack_0 = table.unpack
|
|
30
|
+
end
|
|
31
|
+
return ____fn_1(____unpack_0(args, 1, argsLength))
|
|
32
|
+
end),
|
|
26
33
|
[Symbol.iterator] = generatorIterator,
|
|
27
34
|
next = generatorNext
|
|
28
35
|
}
|
|
@@ -10,5 +10,9 @@ local function __TS__ParseFloat(numberString)
|
|
|
10
10
|
return ____temp_0
|
|
11
11
|
end
|
|
12
12
|
local number = tonumber(string.match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
13
|
-
|
|
13
|
+
local ____number_1 = number
|
|
14
|
+
if ____number_1 == nil then
|
|
15
|
+
____number_1 = 0 / 0
|
|
16
|
+
end
|
|
17
|
+
return ____number_1
|
|
14
18
|
end
|
package/dist/lualib/Promise.lua
CHANGED
|
@@ -74,7 +74,7 @@ do
|
|
|
74
74
|
end
|
|
75
75
|
else
|
|
76
76
|
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
77
|
-
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function() return resolve(nil,
|
|
77
|
+
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
|
|
78
78
|
end
|
|
79
79
|
if onRejected then
|
|
80
80
|
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
@@ -83,6 +83,9 @@ do
|
|
|
83
83
|
if isRejected then
|
|
84
84
|
internalCallback(nil, self.rejectionReason)
|
|
85
85
|
end
|
|
86
|
+
else
|
|
87
|
+
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
|
|
88
|
+
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
|
|
86
89
|
end
|
|
87
90
|
if isFulfilled then
|
|
88
91
|
resolve(nil, self.value)
|
|
@@ -97,8 +100,8 @@ do
|
|
|
97
100
|
end
|
|
98
101
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
99
102
|
if onFinally then
|
|
100
|
-
local
|
|
101
|
-
|
|
103
|
+
local ____self_finallyCallbacks_5 = self.finallyCallbacks
|
|
104
|
+
____self_finallyCallbacks_5[#____self_finallyCallbacks_5 + 1] = onFinally
|
|
102
105
|
if self.state ~= 0 then
|
|
103
106
|
onFinally(nil)
|
|
104
107
|
end
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
local function __TS__SparseArraySpread(sparseArray)
|
|
2
|
-
local
|
|
2
|
+
local ____unpack_0 = unpack
|
|
3
|
+
if ____unpack_0 == nil then
|
|
4
|
+
____unpack_0 = table.unpack
|
|
5
|
+
end
|
|
6
|
+
local _unpack = ____unpack_0
|
|
3
7
|
return _unpack(sparseArray, 1, sparseArray.sparseLength)
|
|
4
8
|
end
|
|
@@ -5,5 +5,9 @@ local function __TS__StringCharCodeAt(self, index)
|
|
|
5
5
|
if index < 0 then
|
|
6
6
|
return 0 / 0
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
local ____string_byte_result_0 = string.byte(self, index + 1)
|
|
9
|
+
if ____string_byte_result_0 == nil then
|
|
10
|
+
____string_byte_result_0 = 0 / 0
|
|
11
|
+
end
|
|
12
|
+
return ____string_byte_result_0
|
|
9
13
|
end
|
|
@@ -345,7 +345,11 @@ end
|
|
|
345
345
|
|
|
346
346
|
local function __TS__ArraySlice(self, first, last)
|
|
347
347
|
local len = #self
|
|
348
|
-
|
|
348
|
+
local ____first_0 = first
|
|
349
|
+
if ____first_0 == nil then
|
|
350
|
+
____first_0 = 0
|
|
351
|
+
end
|
|
352
|
+
first = ____first_0
|
|
349
353
|
if first < 0 then
|
|
350
354
|
first = len + first
|
|
351
355
|
if first < 0 then
|
|
@@ -356,7 +360,11 @@ local function __TS__ArraySlice(self, first, last)
|
|
|
356
360
|
first = len
|
|
357
361
|
end
|
|
358
362
|
end
|
|
359
|
-
|
|
363
|
+
local ____last_1 = last
|
|
364
|
+
if ____last_1 == nil then
|
|
365
|
+
____last_1 = len
|
|
366
|
+
end
|
|
367
|
+
last = ____last_1
|
|
360
368
|
if last < 0 then
|
|
361
369
|
last = len + last
|
|
362
370
|
if last < 0 then
|
|
@@ -412,7 +420,11 @@ local function __TS__ArraySplice(self, ...)
|
|
|
412
420
|
elseif actualArgumentCount == 1 then
|
|
413
421
|
actualDeleteCount = len - start
|
|
414
422
|
else
|
|
415
|
-
|
|
423
|
+
local ____deleteCount_0 = deleteCount
|
|
424
|
+
if ____deleteCount_0 == nil then
|
|
425
|
+
____deleteCount_0 = 0
|
|
426
|
+
end
|
|
427
|
+
actualDeleteCount = ____deleteCount_0
|
|
416
428
|
if actualDeleteCount < 0 then
|
|
417
429
|
actualDeleteCount = 0
|
|
418
430
|
end
|
|
@@ -651,7 +663,7 @@ do
|
|
|
651
663
|
end
|
|
652
664
|
else
|
|
653
665
|
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
654
|
-
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function() return resolve(nil,
|
|
666
|
+
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
|
|
655
667
|
end
|
|
656
668
|
if onRejected then
|
|
657
669
|
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
@@ -660,6 +672,9 @@ do
|
|
|
660
672
|
if isRejected then
|
|
661
673
|
internalCallback(nil, self.rejectionReason)
|
|
662
674
|
end
|
|
675
|
+
else
|
|
676
|
+
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
|
|
677
|
+
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
|
|
663
678
|
end
|
|
664
679
|
if isFulfilled then
|
|
665
680
|
resolve(nil, self.value)
|
|
@@ -674,8 +689,8 @@ do
|
|
|
674
689
|
end
|
|
675
690
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
676
691
|
if onFinally then
|
|
677
|
-
local
|
|
678
|
-
|
|
692
|
+
local ____self_finallyCallbacks_5 = self.finallyCallbacks
|
|
693
|
+
____self_finallyCallbacks_5[#____self_finallyCallbacks_5 + 1] = onFinally
|
|
679
694
|
if self.state ~= 0 then
|
|
680
695
|
onFinally(nil)
|
|
681
696
|
end
|
|
@@ -1172,7 +1187,14 @@ do
|
|
|
1172
1187
|
local args = {...}
|
|
1173
1188
|
local argsLength = select("#", ...)
|
|
1174
1189
|
return {
|
|
1175
|
-
____coroutine = coroutine.create(function()
|
|
1190
|
+
____coroutine = coroutine.create(function()
|
|
1191
|
+
local ____fn_1 = fn
|
|
1192
|
+
local ____unpack_0 = unpack
|
|
1193
|
+
if ____unpack_0 == nil then
|
|
1194
|
+
____unpack_0 = table.unpack
|
|
1195
|
+
end
|
|
1196
|
+
return ____fn_1(____unpack_0(args, 1, argsLength))
|
|
1197
|
+
end),
|
|
1176
1198
|
[Symbol.iterator] = generatorIterator,
|
|
1177
1199
|
next = generatorNext
|
|
1178
1200
|
}
|
|
@@ -1550,7 +1572,11 @@ local function __TS__ParseFloat(numberString)
|
|
|
1550
1572
|
return ____temp_0
|
|
1551
1573
|
end
|
|
1552
1574
|
local number = tonumber(string.match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1553
|
-
|
|
1575
|
+
local ____number_1 = number
|
|
1576
|
+
if ____number_1 == nil then
|
|
1577
|
+
____number_1 = 0 / 0
|
|
1578
|
+
end
|
|
1579
|
+
return ____number_1
|
|
1554
1580
|
end
|
|
1555
1581
|
|
|
1556
1582
|
local function __TS__StringSubstr(self, from, length)
|
|
@@ -1944,7 +1970,11 @@ local function __TS__SparseArrayPush(sparseArray, ...)
|
|
|
1944
1970
|
end
|
|
1945
1971
|
|
|
1946
1972
|
local function __TS__SparseArraySpread(sparseArray)
|
|
1947
|
-
local
|
|
1973
|
+
local ____unpack_0 = unpack
|
|
1974
|
+
if ____unpack_0 == nil then
|
|
1975
|
+
____unpack_0 = table.unpack
|
|
1976
|
+
end
|
|
1977
|
+
local _unpack = ____unpack_0
|
|
1948
1978
|
return _unpack(sparseArray, 1, sparseArray.sparseLength)
|
|
1949
1979
|
end
|
|
1950
1980
|
|
|
@@ -2124,7 +2154,11 @@ local function __TS__StringCharCodeAt(self, index)
|
|
|
2124
2154
|
if index < 0 then
|
|
2125
2155
|
return 0 / 0
|
|
2126
2156
|
end
|
|
2127
|
-
|
|
2157
|
+
local ____string_byte_result_0 = string.byte(self, index + 1)
|
|
2158
|
+
if ____string_byte_result_0 == nil then
|
|
2159
|
+
____string_byte_result_0 = 0 / 0
|
|
2160
|
+
end
|
|
2161
|
+
return ____string_byte_result_0
|
|
2128
2162
|
end
|
|
2129
2163
|
|
|
2130
2164
|
local function __TS__StringEndsWith(self, searchString, endPosition)
|
|
@@ -4,7 +4,6 @@ exports.lualibDiagnostic = void 0;
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const tstl = require("..");
|
|
6
6
|
const path = require("path");
|
|
7
|
-
const lualib_1 = require("../transformation/utils/lualib");
|
|
8
7
|
const LuaLib_1 = require("../LuaLib");
|
|
9
8
|
const util_1 = require("./util");
|
|
10
9
|
const utils_1 = require("../utils");
|
|
@@ -51,7 +50,7 @@ class LuaLibPlugin {
|
|
|
51
50
|
}
|
|
52
51
|
// Transpile file as normal with tstl
|
|
53
52
|
const fileResult = context.superTransformNode(file)[0];
|
|
54
|
-
const usedFeatures = new Set(
|
|
53
|
+
const usedFeatures = new Set(context.usedLuaLibFeatures);
|
|
55
54
|
// Get all imports in file
|
|
56
55
|
const importNames = new Set();
|
|
57
56
|
const imports = file.statements.filter(ts.isImportDeclaration);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starts a performance measurement section.
|
|
3
|
+
* @param name name of the measurement
|
|
4
|
+
*/
|
|
5
|
+
export declare function startSection(name: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Ends a performance measurement section.
|
|
8
|
+
* @param name name of the measurement
|
|
9
|
+
*/
|
|
10
|
+
export declare function endSection(name: string): void;
|
|
11
|
+
export declare function isMeasurementEnabled(): boolean;
|
|
12
|
+
export declare function enableMeasurement(): void;
|
|
13
|
+
export declare function disableMeasurement(): void;
|
|
14
|
+
export declare function forEachMeasure(callback: (measureName: string, duration: number) => void): void;
|
|
15
|
+
export declare function getTotalDuration(): number;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTotalDuration = exports.forEachMeasure = exports.disableMeasurement = exports.enableMeasurement = exports.isMeasurementEnabled = exports.endSection = exports.startSection = void 0;
|
|
4
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
5
|
+
// We use our own performance hooks implementation for easier use, but also call node's performance hooks, so it shows up in the profiler.
|
|
6
|
+
let enabled = false;
|
|
7
|
+
const marks = new Map();
|
|
8
|
+
const durations = new Map();
|
|
9
|
+
function timestamp() {
|
|
10
|
+
return perf_hooks_1.performance.now();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Marks a performance event, with the given markName.
|
|
14
|
+
*/
|
|
15
|
+
function mark(markName) {
|
|
16
|
+
if (enabled) {
|
|
17
|
+
marks.set(markName, timestamp());
|
|
18
|
+
perf_hooks_1.performance.mark(markName);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Adds a performance measurement with the specified name.
|
|
23
|
+
*
|
|
24
|
+
* @param measureName The name of the performance measurement.
|
|
25
|
+
* @param startMarkName The name of the starting mark
|
|
26
|
+
* @param endMarkName The name of the ending mark
|
|
27
|
+
*/
|
|
28
|
+
function measure(measureName, startMarkName, endMarkName) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
if (enabled) {
|
|
31
|
+
const end = (_a = marks.get(endMarkName)) !== null && _a !== void 0 ? _a : timestamp();
|
|
32
|
+
const start = (_b = marks.get(startMarkName)) !== null && _b !== void 0 ? _b : perf_hooks_1.performance.timeOrigin;
|
|
33
|
+
const previousDuration = (_c = durations.get(measureName)) !== null && _c !== void 0 ? _c : 0;
|
|
34
|
+
durations.set(measureName, previousDuration + (end - start));
|
|
35
|
+
perf_hooks_1.performance.measure(measureName, startMarkName, endMarkName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Starts a performance measurement section.
|
|
40
|
+
* @param name name of the measurement
|
|
41
|
+
*/
|
|
42
|
+
function startSection(name) {
|
|
43
|
+
mark("start " + name);
|
|
44
|
+
}
|
|
45
|
+
exports.startSection = startSection;
|
|
46
|
+
/**
|
|
47
|
+
* Ends a performance measurement section.
|
|
48
|
+
* @param name name of the measurement
|
|
49
|
+
*/
|
|
50
|
+
function endSection(name) {
|
|
51
|
+
mark("end " + name);
|
|
52
|
+
measure(name, "start " + name, "end " + name);
|
|
53
|
+
}
|
|
54
|
+
exports.endSection = endSection;
|
|
55
|
+
function isMeasurementEnabled() {
|
|
56
|
+
return enabled;
|
|
57
|
+
}
|
|
58
|
+
exports.isMeasurementEnabled = isMeasurementEnabled;
|
|
59
|
+
function enableMeasurement() {
|
|
60
|
+
if (!enabled) {
|
|
61
|
+
enabled = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.enableMeasurement = enableMeasurement;
|
|
65
|
+
function disableMeasurement() {
|
|
66
|
+
if (enabled) {
|
|
67
|
+
enabled = false;
|
|
68
|
+
marks.clear();
|
|
69
|
+
durations.clear();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.disableMeasurement = disableMeasurement;
|
|
73
|
+
function forEachMeasure(callback) {
|
|
74
|
+
durations.forEach((duration, measureName) => callback(measureName, duration));
|
|
75
|
+
}
|
|
76
|
+
exports.forEachMeasure = forEachMeasure;
|
|
77
|
+
function getTotalDuration() {
|
|
78
|
+
let total = 0;
|
|
79
|
+
forEachMeasure((_, duration) => (total += duration));
|
|
80
|
+
return total;
|
|
81
|
+
}
|
|
82
|
+
exports.getTotalDuration = getTotalDuration;
|
|
83
|
+
//# sourceMappingURL=measure-performance.js.map
|
|
@@ -103,7 +103,8 @@ function transformArrayPrototypeCall(context, node, calledMethod) {
|
|
|
103
103
|
case "join":
|
|
104
104
|
const callerType = context.checker.getTypeAtLocation(calledMethod.expression);
|
|
105
105
|
const elementType = context.checker.getElementTypeOfArrayType(callerType);
|
|
106
|
-
if (elementType &&
|
|
106
|
+
if (elementType &&
|
|
107
|
+
(0, typescript_1.typeAlwaysHasSomeOfFlags)(context, elementType, ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) {
|
|
107
108
|
const defaultSeparatorLiteral = lua.createStringLiteral(",");
|
|
108
109
|
const param = params[0];
|
|
109
110
|
const parameters = [
|
|
@@ -5,9 +5,9 @@ const CompilerOptions_1 = require("../../CompilerOptions");
|
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
7
7
|
const function_context_1 = require("../utils/function-context");
|
|
8
|
-
const lua_ast_1 = require("../utils/lua-ast");
|
|
9
8
|
const lualib_1 = require("../utils/lualib");
|
|
10
9
|
const call_1 = require("../visitors/call");
|
|
10
|
+
const lua_ast_1 = require("../utils/lua-ast");
|
|
11
11
|
function transformFunctionPrototypeCall(context, node, calledMethod) {
|
|
12
12
|
const callerType = context.checker.getTypeAtLocation(calledMethod.expression);
|
|
13
13
|
if ((0, function_context_1.getFunctionContextType)(context, callerType) === function_context_1.ContextType.Void) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function tryTransformBuiltinGlobalCall(context: TransformationContext, node: ts.CallExpression, expressionType: ts.Type): lua.Expression | undefined;
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.tryTransformBuiltinGlobalCall = void 0;
|
|
4
4
|
const lualib_1 = require("../utils/lualib");
|
|
5
5
|
const typescript_1 = require("../utils/typescript");
|
|
6
6
|
const call_1 = require("../visitors/call");
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function tryTransformBuiltinGlobalCall(context, node, expressionType) {
|
|
8
|
+
function getParameters() {
|
|
9
|
+
const signature = context.checker.getResolvedSignature(node);
|
|
10
|
+
return (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
11
|
+
}
|
|
11
12
|
const name = expressionType.symbol.name;
|
|
12
13
|
switch (name) {
|
|
13
14
|
case "SymbolConstructor":
|
|
14
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Symbol, node, ...
|
|
15
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Symbol, node, ...getParameters());
|
|
15
16
|
case "NumberConstructor":
|
|
16
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Number, node, ...
|
|
17
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Number, node, ...getParameters());
|
|
17
18
|
case "isNaN":
|
|
18
19
|
case "isFinite":
|
|
19
20
|
const numberParameters = (0, typescript_1.isNumberType)(context, expressionType)
|
|
20
|
-
?
|
|
21
|
-
: [(0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Number, undefined, ...
|
|
21
|
+
? getParameters()
|
|
22
|
+
: [(0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Number, undefined, ...getParameters())];
|
|
22
23
|
return (0, lualib_1.transformLuaLibFunction)(context, name === "isNaN" ? lualib_1.LuaLibFeature.NumberIsNaN : lualib_1.LuaLibFeature.NumberIsFinite, node, ...numberParameters);
|
|
23
24
|
case "parseFloat":
|
|
24
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ParseFloat, node, ...
|
|
25
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ParseFloat, node, ...getParameters());
|
|
25
26
|
case "parseInt":
|
|
26
|
-
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ParseInt, node, ...
|
|
27
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ParseInt, node, ...getParameters());
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
exports.
|
|
30
|
+
exports.tryTransformBuiltinGlobalCall = tryTransformBuiltinGlobalCall;
|
|
30
31
|
//# sourceMappingURL=global.js.map
|
|
@@ -2,6 +2,6 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformBuiltinPropertyAccessExpression(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
|
-
export declare function transformBuiltinCallExpression(context: TransformationContext, node: ts.CallExpression
|
|
6
|
-
export declare function transformBuiltinIdentifierExpression(context: TransformationContext, node: ts.Identifier): lua.Expression | undefined;
|
|
5
|
+
export declare function transformBuiltinCallExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression | undefined;
|
|
6
|
+
export declare function transformBuiltinIdentifierExpression(context: TransformationContext, node: ts.Identifier, symbol: ts.Symbol | undefined): lua.Expression | undefined;
|
|
7
7
|
export declare function checkForLuaLibType(context: TransformationContext, type: ts.Type): void;
|