typescript-to-lua 1.10.0-beta.0 → 1.10.1
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/lualib/5.0/Generator.lua +1 -1
- package/dist/lualib/5.0/SparseArraySpread.lua +1 -1
- package/dist/lualib/5.0/Unpack.lua +18 -1
- package/dist/lualib/5.0/lualib_bundle.lua +32 -15
- package/dist/lualib/5.0/lualib_module_info.json +3 -1
- package/dist/transformation/utils/diagnostics.js +1 -1
- package/dist/transformation/visitors/conditional.js +4 -0
- package/dist/transpilation/resolve.js +3 -3
- package/package.json +2 -2
- package/dist/lualib/ArrayConcat.lua +0 -22
- package/dist/lualib/ArrayEntries.lua +0 -13
- package/dist/lualib/ArrayEvery.lua +0 -8
- package/dist/lualib/ArrayFilter.lua +0 -11
- package/dist/lualib/ArrayFind.lua +0 -9
- package/dist/lualib/ArrayFindIndex.lua +0 -8
- package/dist/lualib/ArrayFlat.lua +0 -27
- package/dist/lualib/ArrayFlatMap.lua +0 -17
- package/dist/lualib/ArrayForEach.lua +0 -5
- package/dist/lualib/ArrayFrom.lua +0 -29
- package/dist/lualib/ArrayIncludes.lua +0 -19
- package/dist/lualib/ArrayIndexOf.lua +0 -24
- package/dist/lualib/ArrayIsArray.lua +0 -3
- package/dist/lualib/ArrayJoin.lua +0 -10
- package/dist/lualib/ArrayMap.lua +0 -7
- package/dist/lualib/ArrayPush.lua +0 -9
- package/dist/lualib/ArrayPushArray.lua +0 -8
- package/dist/lualib/ArrayReduce.lua +0 -23
- package/dist/lualib/ArrayReduceRight.lua +0 -23
- package/dist/lualib/ArrayReverse.lua +0 -12
- package/dist/lualib/ArraySetLength.lua +0 -12
- package/dist/lualib/ArraySlice.lua +0 -43
- package/dist/lualib/ArraySome.lua +0 -8
- package/dist/lualib/ArraySort.lua +0 -11
- package/dist/lualib/ArraySplice.lua +0 -77
- package/dist/lualib/ArrayToObject.lua +0 -7
- package/dist/lualib/ArrayUnshift.lua +0 -14
- package/dist/lualib/Await.lua +0 -54
- package/dist/lualib/Class.lua +0 -6
- package/dist/lualib/ClassExtends.lua +0 -24
- package/dist/lualib/CloneDescriptor.lua +0 -28
- package/dist/lualib/Decorate.lua +0 -36
- package/dist/lualib/DecorateParam.lua +0 -3
- package/dist/lualib/DelegatedYield.lua +0 -34
- package/dist/lualib/Delete.lua +0 -19
- package/dist/lualib/Error.lua +0 -77
- package/dist/lualib/FunctionBind.lua +0 -11
- package/dist/lualib/Generator.lua +0 -38
- package/dist/lualib/InstanceOf.lua +0 -18
- package/dist/lualib/InstanceOfObject.lua +0 -4
- package/dist/lualib/Iterator.lua +0 -40
- package/dist/lualib/LuaIteratorSpread.lua +0 -9
- package/dist/lualib/Map.lua +0 -140
- package/dist/lualib/MathAtan2.lua +0 -1
- package/dist/lualib/MathSign.lua +0 -8
- package/dist/lualib/New.lua +0 -5
- package/dist/lualib/Number.lua +0 -26
- package/dist/lualib/NumberIsFinite.lua +0 -3
- package/dist/lualib/NumberIsNaN.lua +0 -3
- package/dist/lualib/NumberToString.lua +0 -44
- package/dist/lualib/ObjectAssign.lua +0 -10
- package/dist/lualib/ObjectDefineProperty.lua +0 -59
- package/dist/lualib/ObjectEntries.lua +0 -9
- package/dist/lualib/ObjectFromEntries.lua +0 -20
- package/dist/lualib/ObjectGetOwnPropertyDescriptor.lua +0 -10
- package/dist/lualib/ObjectGetOwnPropertyDescriptors.lua +0 -7
- package/dist/lualib/ObjectKeys.lua +0 -9
- package/dist/lualib/ObjectRest.lua +0 -9
- package/dist/lualib/ObjectValues.lua +0 -9
- package/dist/lualib/ParseFloat.lua +0 -18
- package/dist/lualib/ParseInt.lua +0 -43
- package/dist/lualib/Promise.lua +0 -176
- package/dist/lualib/PromiseAll.lua +0 -44
- package/dist/lualib/PromiseAllSettled.lua +0 -48
- package/dist/lualib/PromiseAny.lua +0 -41
- package/dist/lualib/PromiseRace.lua +0 -28
- package/dist/lualib/Set.lua +0 -130
- package/dist/lualib/SetDescriptor.lua +0 -79
- package/dist/lualib/SourceMapTraceBack.lua +0 -54
- package/dist/lualib/SparseArrayNew.lua +0 -5
- package/dist/lualib/SparseArrayPush.lua +0 -9
- package/dist/lualib/SparseArraySpread.lua +0 -8
- package/dist/lualib/Spread.lua +0 -15
- package/dist/lualib/StringAccess.lua +0 -5
- package/dist/lualib/StringCharAt.lua +0 -9
- package/dist/lualib/StringCharCodeAt.lua +0 -13
- package/dist/lualib/StringEndsWith.lua +0 -6
- package/dist/lualib/StringIncludes.lua +0 -9
- package/dist/lualib/StringPadEnd.lua +0 -26
- package/dist/lualib/StringPadStart.lua +0 -26
- package/dist/lualib/StringReplace.lua +0 -20
- package/dist/lualib/StringReplaceAll.lua +0 -42
- package/dist/lualib/StringSlice.lua +0 -15
- package/dist/lualib/StringSplit.lua +0 -36
- package/dist/lualib/StringStartsWith.lua +0 -6
- package/dist/lualib/StringSubstr.lua +0 -15
- package/dist/lualib/StringSubstring.lua +0 -17
- package/dist/lualib/StringTrim.lua +0 -4
- package/dist/lualib/StringTrimEnd.lua +0 -4
- package/dist/lualib/StringTrimStart.lua +0 -4
- package/dist/lualib/Symbol.lua +0 -15
- package/dist/lualib/SymbolRegistry.lua +0 -17
- package/dist/lualib/TypeOf.lua +0 -10
- package/dist/lualib/Unpack.lua +0 -1
- package/dist/lualib/WeakMap.lua +0 -45
- package/dist/lualib/WeakSet.lua +0 -41
- package/dist/lualib/lualib_bundle.lua +0 -2518
- package/dist/lualib/lualib_module_info.json +0 -626
- package/dist/lualib/universal/universal/CountVarargs.lua +0 -3
- package/dist/lualib/universal/universal/Match.lua +0 -1
- package/dist/lualib/universal/universal/MathModf.lua +0 -1
- package/dist/lualib/universal/universal/SparseArraySpread.lua +0 -8
- package/dist/lualib/universal/universal/Unpack.lua +0 -1
|
@@ -25,7 +25,7 @@ do
|
|
|
25
25
|
local args = arg
|
|
26
26
|
local argsLength = __TS__CountVarargs(unpack(arg))
|
|
27
27
|
return {
|
|
28
|
-
____coroutine = coroutine.create(function() return fn(
|
|
28
|
+
____coroutine = coroutine.create(function() return fn(__TS__Unpack(args, 1, argsLength)) end),
|
|
29
29
|
[Symbol.iterator] = generatorIterator,
|
|
30
30
|
next = generatorNext
|
|
31
31
|
}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
local __TS__Unpack
|
|
1
|
+
local function __TS__Unpack(list, i, j)
|
|
2
|
+
if i == 1 and j == nil then
|
|
3
|
+
return unpack(nil, list)
|
|
4
|
+
else
|
|
5
|
+
if j == nil then
|
|
6
|
+
j = table.getn(list)
|
|
7
|
+
end
|
|
8
|
+
local slice = {}
|
|
9
|
+
do
|
|
10
|
+
local n = i
|
|
11
|
+
while n <= j do
|
|
12
|
+
slice[n - i + 1] = list[n]
|
|
13
|
+
n = n + 1
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
return unpack(slice)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1184,24 +1184,25 @@ local function __TS__DelegatedYield(iterable)
|
|
|
1184
1184
|
end
|
|
1185
1185
|
end
|
|
1186
1186
|
|
|
1187
|
-
local function
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
for i = 0, string.len(iterable) - 1 do
|
|
1191
|
-
arr[i + 1] = __TS__StringAccess(iterable, i)
|
|
1192
|
-
end
|
|
1187
|
+
local function __TS__Unpack(list, i, j)
|
|
1188
|
+
if i == 1 and j == nil then
|
|
1189
|
+
return unpack(nil, list)
|
|
1193
1190
|
else
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1191
|
+
if j == nil then
|
|
1192
|
+
j = table.getn(list)
|
|
1193
|
+
end
|
|
1194
|
+
local slice = {}
|
|
1195
|
+
do
|
|
1196
|
+
local n = i
|
|
1197
|
+
while n <= j do
|
|
1198
|
+
slice[n - i + 1] = list[n]
|
|
1199
|
+
n = n + 1
|
|
1200
|
+
end
|
|
1198
1201
|
end
|
|
1202
|
+
return unpack(slice)
|
|
1199
1203
|
end
|
|
1200
|
-
return unpack(arr)
|
|
1201
1204
|
end
|
|
1202
1205
|
|
|
1203
|
-
local __TS__Unpack = unpack
|
|
1204
|
-
|
|
1205
1206
|
local __TS__Generator
|
|
1206
1207
|
do
|
|
1207
1208
|
local function generatorIterator(self)
|
|
@@ -1229,7 +1230,7 @@ do
|
|
|
1229
1230
|
local args = arg
|
|
1230
1231
|
local argsLength = __TS__CountVarargs(unpack(arg))
|
|
1231
1232
|
return {
|
|
1232
|
-
____coroutine = coroutine.create(function() return fn(
|
|
1233
|
+
____coroutine = coroutine.create(function() return fn(__TS__Unpack(args, 1, argsLength)) end),
|
|
1233
1234
|
[Symbol.iterator] = generatorIterator,
|
|
1234
1235
|
next = generatorNext
|
|
1235
1236
|
}
|
|
@@ -2069,7 +2070,7 @@ local function __TS__SparseArrayPush(sparseArray, ...)
|
|
|
2069
2070
|
end
|
|
2070
2071
|
|
|
2071
2072
|
local function __TS__SparseArraySpread(sparseArray)
|
|
2072
|
-
return
|
|
2073
|
+
return __TS__Unpack(sparseArray, 1, sparseArray.sparseLength)
|
|
2073
2074
|
end
|
|
2074
2075
|
|
|
2075
2076
|
local WeakMap
|
|
@@ -2217,6 +2218,22 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2217
2218
|
end
|
|
2218
2219
|
end
|
|
2219
2220
|
|
|
2221
|
+
local function __TS__Spread(iterable)
|
|
2222
|
+
local arr = {}
|
|
2223
|
+
if type(iterable) == "string" then
|
|
2224
|
+
for i = 0, string.len(iterable) - 1 do
|
|
2225
|
+
arr[i + 1] = __TS__StringAccess(iterable, i)
|
|
2226
|
+
end
|
|
2227
|
+
else
|
|
2228
|
+
local len = 0
|
|
2229
|
+
for ____, item in __TS__Iterator(iterable) do
|
|
2230
|
+
len = len + 1
|
|
2231
|
+
arr[len] = item
|
|
2232
|
+
end
|
|
2233
|
+
end
|
|
2234
|
+
return unpack(arr)
|
|
2235
|
+
end
|
|
2236
|
+
|
|
2220
2237
|
local function __TS__StringCharAt(self, pos)
|
|
2221
2238
|
if pos ~= pos then
|
|
2222
2239
|
pos = 0
|
|
@@ -254,7 +254,6 @@
|
|
|
254
254
|
"__TS__Generator"
|
|
255
255
|
],
|
|
256
256
|
"dependencies": [
|
|
257
|
-
"Spread",
|
|
258
257
|
"Symbol",
|
|
259
258
|
"CountVarargs",
|
|
260
259
|
"Unpack"
|
|
@@ -518,6 +517,9 @@
|
|
|
518
517
|
"SparseArraySpread": {
|
|
519
518
|
"exports": [
|
|
520
519
|
"__TS__SparseArraySpread"
|
|
520
|
+
],
|
|
521
|
+
"dependencies": [
|
|
522
|
+
"Unpack"
|
|
521
523
|
]
|
|
522
524
|
},
|
|
523
525
|
"WeakMap": {
|
|
@@ -57,7 +57,7 @@ exports.annotationRemoved = createErrorDiagnosticFactory((kind) => `'@${kind}' h
|
|
|
57
57
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
58
58
|
exports.annotationDeprecated = createWarningDiagnosticFactory((kind) => `'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
|
|
59
59
|
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`);
|
|
60
|
-
exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("
|
|
60
|
+
exports.truthyOnlyConditionalValue = createWarningDiagnosticFactory("Only false and nil evaluate to 'false' in Lua, everything else is considered 'true'. Explicitly compare the value with ===.");
|
|
61
61
|
exports.notAllowedOptionalAssignment = createErrorDiagnosticFactory("The left-hand side of an assignment expression may not be an optional property access.");
|
|
62
62
|
exports.awaitMustBeInAsyncFunction = createErrorDiagnosticFactory("Await can only be used inside async functions.");
|
|
63
63
|
exports.unsupportedBuiltinOptionalCall = createErrorDiagnosticFactory("Optional calls are not supported for builtin or language extension functions.");
|
|
@@ -76,6 +76,10 @@ function transformIfStatement(statement, context) {
|
|
|
76
76
|
}
|
|
77
77
|
exports.transformIfStatement = transformIfStatement;
|
|
78
78
|
function checkOnlyTruthyCondition(condition, context) {
|
|
79
|
+
if (context.options.strictNullChecks === false)
|
|
80
|
+
return; // This check is not valid if everything could implicitly be nil
|
|
81
|
+
if (ts.isElementAccessExpression(condition))
|
|
82
|
+
return; // Array index could always implicitly return nil
|
|
79
83
|
if (!(0, typescript_1.canBeFalsy)(context, context.checker.getTypeAtLocation(condition))) {
|
|
80
84
|
context.diagnostics.push((0, diagnostics_1.truthyOnlyConditionalValue)(condition));
|
|
81
85
|
}
|
|
@@ -260,11 +260,11 @@ function isBuildModeLibrary(program) {
|
|
|
260
260
|
function findRequiredPaths(code) {
|
|
261
261
|
// Find all require("<path>") paths in a lua code string
|
|
262
262
|
const paths = [];
|
|
263
|
-
const pattern = /(^|\s|;|=|\()require\("(.+?)
|
|
263
|
+
const pattern = /(^|\s|;|=|\()require\s*\(?(["|'])(.+?)\2\)?/g;
|
|
264
264
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
265
265
|
let match;
|
|
266
266
|
while ((match = pattern.exec(code))) {
|
|
267
|
-
paths.push(match[
|
|
267
|
+
paths.push(match[3]);
|
|
268
268
|
}
|
|
269
269
|
return paths;
|
|
270
270
|
}
|
|
@@ -272,7 +272,7 @@ function replaceRequireInCode(file, originalRequire, newRequire) {
|
|
|
272
272
|
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
|
273
273
|
// Escape special characters to prevent the regex from breaking...
|
|
274
274
|
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
275
|
-
file.code = file.code.replace(new RegExp(`(^|\\s|;|=|\\()require\\("${escapedRequire}"\\)
|
|
275
|
+
file.code = file.code.replace(new RegExp(`(^|\\s|;|=|\\()require\\s*\\(?["|']${escapedRequire}["|']\\)?`), `$1require("${requirePath}")`);
|
|
276
276
|
}
|
|
277
277
|
function replaceRequireInSourceMap(file, originalRequire, newRequire) {
|
|
278
278
|
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
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/",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"javascript-stringify": "^2.0.1",
|
|
66
66
|
"jest": "^28.1.3",
|
|
67
67
|
"jest-circus": "^29.0.1",
|
|
68
|
-
"lua-types": "^2.13.0
|
|
68
|
+
"lua-types": "^2.13.0",
|
|
69
69
|
"lua-wasm-bindings": "^0.3.1",
|
|
70
70
|
"prettier": "^2.3.2",
|
|
71
71
|
"ts-jest": "^28.0.8",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayConcat(self, ...)
|
|
2
|
-
local items = {...}
|
|
3
|
-
local result = {}
|
|
4
|
-
local len = 0
|
|
5
|
-
for i = 1, #self do
|
|
6
|
-
len = len + 1
|
|
7
|
-
result[len] = self[i]
|
|
8
|
-
end
|
|
9
|
-
for i = 1, #items do
|
|
10
|
-
local item = items[i]
|
|
11
|
-
if __TS__ArrayIsArray(item) then
|
|
12
|
-
for j = 1, #item do
|
|
13
|
-
len = len + 1
|
|
14
|
-
result[len] = item[j]
|
|
15
|
-
end
|
|
16
|
-
else
|
|
17
|
-
len = len + 1
|
|
18
|
-
result[len] = item
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
return result
|
|
22
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayEntries(array)
|
|
2
|
-
local key = 0
|
|
3
|
-
return {
|
|
4
|
-
[Symbol.iterator] = function(self)
|
|
5
|
-
return self
|
|
6
|
-
end,
|
|
7
|
-
next = function(self)
|
|
8
|
-
local result = {done = array[key + 1] == nil, value = {key, array[key + 1]}}
|
|
9
|
-
key = key + 1
|
|
10
|
-
return result
|
|
11
|
-
end
|
|
12
|
-
}
|
|
13
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayFlat(self, depth)
|
|
2
|
-
if depth == nil then
|
|
3
|
-
depth = 1
|
|
4
|
-
end
|
|
5
|
-
local result = {}
|
|
6
|
-
local len = 0
|
|
7
|
-
for i = 1, #self do
|
|
8
|
-
local value = self[i]
|
|
9
|
-
if depth > 0 and __TS__ArrayIsArray(value) then
|
|
10
|
-
local toAdd
|
|
11
|
-
if depth == 1 then
|
|
12
|
-
toAdd = value
|
|
13
|
-
else
|
|
14
|
-
toAdd = __TS__ArrayFlat(value, depth - 1)
|
|
15
|
-
end
|
|
16
|
-
for j = 1, #toAdd do
|
|
17
|
-
local val = toAdd[j]
|
|
18
|
-
len = len + 1
|
|
19
|
-
result[len] = val
|
|
20
|
-
end
|
|
21
|
-
else
|
|
22
|
-
len = len + 1
|
|
23
|
-
result[len] = value
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
return result
|
|
27
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayFlatMap(self, callback, thisArg)
|
|
2
|
-
local result = {}
|
|
3
|
-
local len = 0
|
|
4
|
-
for i = 1, #self do
|
|
5
|
-
local value = callback(thisArg, self[i], i - 1, self)
|
|
6
|
-
if __TS__ArrayIsArray(value) then
|
|
7
|
-
for j = 1, #value do
|
|
8
|
-
len = len + 1
|
|
9
|
-
result[len] = value[j]
|
|
10
|
-
end
|
|
11
|
-
else
|
|
12
|
-
len = len + 1
|
|
13
|
-
result[len] = value
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
return result
|
|
17
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
local __TS__ArrayFrom
|
|
2
|
-
do
|
|
3
|
-
local function arrayLikeStep(self, index)
|
|
4
|
-
index = index + 1
|
|
5
|
-
if index > self.length then
|
|
6
|
-
return
|
|
7
|
-
end
|
|
8
|
-
return index, self[index]
|
|
9
|
-
end
|
|
10
|
-
local function arrayLikeIterator(arr)
|
|
11
|
-
if type(arr.length) == "number" then
|
|
12
|
-
return arrayLikeStep, arr, 0
|
|
13
|
-
end
|
|
14
|
-
return __TS__Iterator(arr)
|
|
15
|
-
end
|
|
16
|
-
function __TS__ArrayFrom(arrayLike, mapFn, thisArg)
|
|
17
|
-
local result = {}
|
|
18
|
-
if mapFn == nil then
|
|
19
|
-
for ____, v in arrayLikeIterator(arrayLike) do
|
|
20
|
-
result[#result + 1] = v
|
|
21
|
-
end
|
|
22
|
-
else
|
|
23
|
-
for i, v in arrayLikeIterator(arrayLike) do
|
|
24
|
-
result[#result + 1] = mapFn(thisArg, v, i - 1)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
return result
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayIncludes(self, searchElement, fromIndex)
|
|
2
|
-
if fromIndex == nil then
|
|
3
|
-
fromIndex = 0
|
|
4
|
-
end
|
|
5
|
-
local len = #self
|
|
6
|
-
local k = fromIndex
|
|
7
|
-
if fromIndex < 0 then
|
|
8
|
-
k = len + fromIndex
|
|
9
|
-
end
|
|
10
|
-
if k < 0 then
|
|
11
|
-
k = 0
|
|
12
|
-
end
|
|
13
|
-
for i = k + 1, len do
|
|
14
|
-
if self[i] == searchElement then
|
|
15
|
-
return true
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
return false
|
|
19
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayIndexOf(self, searchElement, fromIndex)
|
|
2
|
-
if fromIndex == nil then
|
|
3
|
-
fromIndex = 0
|
|
4
|
-
end
|
|
5
|
-
local len = #self
|
|
6
|
-
if len == 0 then
|
|
7
|
-
return -1
|
|
8
|
-
end
|
|
9
|
-
if fromIndex >= len then
|
|
10
|
-
return -1
|
|
11
|
-
end
|
|
12
|
-
if fromIndex < 0 then
|
|
13
|
-
fromIndex = len + fromIndex
|
|
14
|
-
if fromIndex < 0 then
|
|
15
|
-
fromIndex = 0
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
for i = fromIndex + 1, len do
|
|
19
|
-
if self[i] == searchElement then
|
|
20
|
-
return i - 1
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
return -1
|
|
24
|
-
end
|
package/dist/lualib/ArrayMap.lua
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayReduce(self, callbackFn, ...)
|
|
2
|
-
local len = #self
|
|
3
|
-
local k = 0
|
|
4
|
-
local accumulator = nil
|
|
5
|
-
if select("#", ...) ~= 0 then
|
|
6
|
-
accumulator = ...
|
|
7
|
-
elseif len > 0 then
|
|
8
|
-
accumulator = self[1]
|
|
9
|
-
k = 1
|
|
10
|
-
else
|
|
11
|
-
error("Reduce of empty array with no initial value", 0)
|
|
12
|
-
end
|
|
13
|
-
for i = k + 1, len do
|
|
14
|
-
accumulator = callbackFn(
|
|
15
|
-
nil,
|
|
16
|
-
accumulator,
|
|
17
|
-
self[i],
|
|
18
|
-
i - 1,
|
|
19
|
-
self
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
return accumulator
|
|
23
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
local function __TS__ArrayReduceRight(self, callbackFn, ...)
|
|
2
|
-
local len = #self
|
|
3
|
-
local k = len - 1
|
|
4
|
-
local accumulator = nil
|
|
5
|
-
if select("#", ...) ~= 0 then
|
|
6
|
-
accumulator = ...
|
|
7
|
-
elseif len > 0 then
|
|
8
|
-
accumulator = self[k + 1]
|
|
9
|
-
k = k - 1
|
|
10
|
-
else
|
|
11
|
-
error("Reduce of empty array with no initial value", 0)
|
|
12
|
-
end
|
|
13
|
-
for i = k + 1, 1, -1 do
|
|
14
|
-
accumulator = callbackFn(
|
|
15
|
-
nil,
|
|
16
|
-
accumulator,
|
|
17
|
-
self[i],
|
|
18
|
-
i - 1,
|
|
19
|
-
self
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
return accumulator
|
|
23
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
local function __TS__ArraySetLength(self, length)
|
|
2
|
-
if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
|
|
3
|
-
error(
|
|
4
|
-
"invalid array length: " .. tostring(length),
|
|
5
|
-
0
|
|
6
|
-
)
|
|
7
|
-
end
|
|
8
|
-
for i = length + 1, #self do
|
|
9
|
-
self[i] = nil
|
|
10
|
-
end
|
|
11
|
-
return length
|
|
12
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
local function __TS__ArraySlice(self, first, last)
|
|
2
|
-
local len = #self
|
|
3
|
-
local ____first_0 = first
|
|
4
|
-
if ____first_0 == nil then
|
|
5
|
-
____first_0 = 0
|
|
6
|
-
end
|
|
7
|
-
first = ____first_0
|
|
8
|
-
if first < 0 then
|
|
9
|
-
first = len + first
|
|
10
|
-
if first < 0 then
|
|
11
|
-
first = 0
|
|
12
|
-
end
|
|
13
|
-
else
|
|
14
|
-
if first > len then
|
|
15
|
-
first = len
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
local ____last_1 = last
|
|
19
|
-
if ____last_1 == nil then
|
|
20
|
-
____last_1 = len
|
|
21
|
-
end
|
|
22
|
-
last = ____last_1
|
|
23
|
-
if last < 0 then
|
|
24
|
-
last = len + last
|
|
25
|
-
if last < 0 then
|
|
26
|
-
last = 0
|
|
27
|
-
end
|
|
28
|
-
else
|
|
29
|
-
if last > len then
|
|
30
|
-
last = len
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
local out = {}
|
|
34
|
-
first = first + 1
|
|
35
|
-
last = last + 1
|
|
36
|
-
local n = 1
|
|
37
|
-
while first < last do
|
|
38
|
-
out[n] = self[first]
|
|
39
|
-
first = first + 1
|
|
40
|
-
n = n + 1
|
|
41
|
-
end
|
|
42
|
-
return out
|
|
43
|
-
end
|