typescript-to-lua 1.4.0 → 1.4.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/CompilerOptions.d.ts +4 -1
- package/dist/LuaAST.d.ts +9 -7
- package/dist/LuaAST.js +19 -13
- package/dist/LuaLib.d.ts +2 -2
- package/dist/LuaLib.js +2 -2
- package/dist/LuaPrinter.js +10 -11
- package/dist/cli/parse.js +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/lualib/ArrayConcat.lua +16 -12
- package/dist/lualib/ArrayEvery.lua +4 -8
- package/dist/lualib/ArrayFilter.lua +6 -8
- package/dist/lualib/ArrayFind.lua +4 -7
- package/dist/lualib/ArrayFindIndex.lua +4 -9
- package/dist/lualib/ArrayFlat.lua +17 -7
- package/dist/lualib/ArrayFlatMap.lua +11 -10
- package/dist/lualib/ArrayForEach.lua +3 -7
- package/dist/lualib/ArrayFrom.lua +29 -0
- package/dist/lualib/ArrayIncludes.lua +2 -2
- package/dist/lualib/ArrayIndexOf.lua +13 -21
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayJoin.lua +4 -7
- package/dist/lualib/ArrayMap.lua +5 -9
- package/dist/lualib/ArrayPush.lua +6 -4
- package/dist/lualib/ArrayPushArray.lua +8 -0
- package/dist/lualib/ArrayReduce.lua +8 -8
- package/dist/lualib/ArrayReduceRight.lua +8 -8
- package/dist/lualib/ArrayReverse.lua +7 -7
- package/dist/lualib/ArraySetLength.lua +3 -7
- package/dist/lualib/ArraySlice.lua +26 -19
- package/dist/lualib/ArraySome.lua +4 -8
- package/dist/lualib/ArraySort.lua +4 -4
- package/dist/lualib/ArraySplice.lua +47 -58
- package/dist/lualib/ArrayToObject.lua +3 -7
- package/dist/lualib/ArrayUnshift.lua +11 -8
- package/dist/lualib/FunctionBind.lua +5 -11
- package/dist/lualib/ObjectAssign.lua +5 -7
- package/dist/lualib/ObjectEntries.lua +3 -1
- package/dist/lualib/ObjectKeys.lua +3 -1
- package/dist/lualib/ObjectValues.lua +3 -1
- package/dist/lualib/Promise.lua +8 -7
- package/dist/lualib/PromiseAny.lua +3 -3
- package/dist/lualib/PromiseRace.lua +1 -1
- package/dist/lualib/Spread.lua +5 -7
- package/dist/lualib/StringReplace.lua +17 -14
- package/dist/lualib/StringReplaceAll.lua +36 -29
- package/dist/lualib/StringSplit.lua +32 -32
- package/dist/lualib/lualib_bundle.lua +425 -421
- package/dist/lualib/lualib_module_info.json +21 -22
- package/dist/transformation/builtins/array.d.ts +2 -2
- package/dist/transformation/builtins/array.js +40 -2
- package/dist/transformation/builtins/promise.d.ts +1 -0
- package/dist/transformation/builtins/promise.js +2 -1
- package/dist/transformation/builtins/string.js +1 -1
- package/dist/transformation/utils/diagnostics.d.ts +7 -2
- package/dist/transformation/utils/diagnostics.js +4 -1
- package/dist/transformation/utils/lua-ast.d.ts +1 -0
- package/dist/transformation/utils/lua-ast.js +6 -2
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +9 -1
- package/dist/transformation/visitors/call.js +4 -0
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/class/members/accessors.js +1 -1
- package/dist/transformation/visitors/class/members/constructor.js +1 -1
- package/dist/transformation/visitors/errors.js +4 -2
- package/dist/transformation/visitors/function.js +4 -4
- package/dist/transformation/visitors/modules/import.d.ts +1 -0
- package/dist/transformation/visitors/modules/import.js +9 -1
- package/dist/transformation/visitors/spread.js +1 -7
- package/dist/transpilation/plugins.d.ts +10 -3
- package/dist/transpilation/plugins.js +6 -2
- package/dist/transpilation/resolve.js +1 -0
- package/dist/transpilation/transpile.d.ts +1 -1
- package/dist/transpilation/transpile.js +1 -6
- package/dist/transpilation/transpiler.js +19 -9
- package/dist/transpilation/utils.d.ts +2 -0
- package/package.json +1 -1
- package/dist/lualib/ArrayShift.lua +0 -3
- package/dist/lualib/StringConcat.lua +0 -8
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
local function __TS__ArrayIsArray(value)
|
|
2
|
-
return type(value) == "table" and (value[1] ~= nil or next(value
|
|
2
|
+
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
|
|
3
3
|
end
|
|
4
4
|
|
|
5
|
-
local function __TS__ArrayConcat(
|
|
6
|
-
local
|
|
7
|
-
local
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
local function __TS__ArrayConcat(self, ...)
|
|
6
|
+
local items = {...}
|
|
7
|
+
local result = {}
|
|
8
|
+
local len = 0
|
|
9
|
+
for i = 1, #self do
|
|
10
|
+
len = len + 1
|
|
11
|
+
result[len] = self[i]
|
|
12
|
+
end
|
|
13
|
+
for i = 1, #items do
|
|
14
|
+
local item = items[i]
|
|
15
|
+
if __TS__ArrayIsArray(item) then
|
|
16
|
+
for j = 1, #item do
|
|
17
|
+
len = len + 1
|
|
18
|
+
result[len] = item[j]
|
|
16
19
|
end
|
|
17
20
|
else
|
|
18
|
-
|
|
21
|
+
len = len + 1
|
|
22
|
+
result[len] = item
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
|
-
return
|
|
25
|
+
return result
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
local __TS__Symbol, Symbol
|
|
@@ -51,70 +55,123 @@ local function __TS__ArrayEntries(array)
|
|
|
51
55
|
}
|
|
52
56
|
end
|
|
53
57
|
|
|
54
|
-
local function __TS__ArrayEvery(
|
|
55
|
-
do
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if not callbackfn(nil, arr[i + 1], i, arr) then
|
|
59
|
-
return false
|
|
60
|
-
end
|
|
61
|
-
i = i + 1
|
|
58
|
+
local function __TS__ArrayEvery(self, callbackfn, thisArg)
|
|
59
|
+
for i = 1, #self do
|
|
60
|
+
if not callbackfn(thisArg, self[i], i - 1, self) then
|
|
61
|
+
return false
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
return true
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
local function __TS__ArrayFilter(
|
|
67
|
+
local function __TS__ArrayFilter(self, callbackfn, thisArg)
|
|
68
68
|
local result = {}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
end
|
|
75
|
-
i = i + 1
|
|
69
|
+
local len = 0
|
|
70
|
+
for i = 1, #self do
|
|
71
|
+
if callbackfn(thisArg, self[i], i - 1, self) then
|
|
72
|
+
len = len + 1
|
|
73
|
+
result[len] = self[i]
|
|
76
74
|
end
|
|
77
75
|
end
|
|
78
76
|
return result
|
|
79
77
|
end
|
|
80
78
|
|
|
81
|
-
local function __TS__ArrayForEach(
|
|
82
|
-
do
|
|
83
|
-
|
|
84
|
-
while i < #arr do
|
|
85
|
-
callbackFn(nil, arr[i + 1], i, arr)
|
|
86
|
-
i = i + 1
|
|
87
|
-
end
|
|
79
|
+
local function __TS__ArrayForEach(self, callbackFn, thisArg)
|
|
80
|
+
for i = 1, #self do
|
|
81
|
+
callbackFn(thisArg, self[i], i - 1, self)
|
|
88
82
|
end
|
|
89
83
|
end
|
|
90
84
|
|
|
91
|
-
local function __TS__ArrayFind(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
local elem = arr[k + 1]
|
|
96
|
-
if predicate(nil, elem, k, arr) then
|
|
85
|
+
local function __TS__ArrayFind(self, predicate, thisArg)
|
|
86
|
+
for i = 1, #self do
|
|
87
|
+
local elem = self[i]
|
|
88
|
+
if predicate(thisArg, elem, i - 1, self) then
|
|
97
89
|
return elem
|
|
98
90
|
end
|
|
99
|
-
k = k + 1
|
|
100
91
|
end
|
|
101
92
|
return nil
|
|
102
93
|
end
|
|
103
94
|
|
|
104
|
-
local function __TS__ArrayFindIndex(
|
|
105
|
-
do
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
while i < len do
|
|
109
|
-
if callbackFn(nil, arr[i + 1], i, arr) then
|
|
110
|
-
return i
|
|
111
|
-
end
|
|
112
|
-
i = i + 1
|
|
95
|
+
local function __TS__ArrayFindIndex(self, callbackFn, thisArg)
|
|
96
|
+
for i = 1, #self do
|
|
97
|
+
if callbackFn(thisArg, self[i], i - 1, self) then
|
|
98
|
+
return i - 1
|
|
113
99
|
end
|
|
114
100
|
end
|
|
115
101
|
return -1
|
|
116
102
|
end
|
|
117
103
|
|
|
104
|
+
local __TS__Iterator
|
|
105
|
+
do
|
|
106
|
+
local function iteratorGeneratorStep(self)
|
|
107
|
+
local co = self.____coroutine
|
|
108
|
+
local status, value = coroutine.resume(co)
|
|
109
|
+
if not status then
|
|
110
|
+
error(value, 0)
|
|
111
|
+
end
|
|
112
|
+
if coroutine.status(co) == "dead" then
|
|
113
|
+
return
|
|
114
|
+
end
|
|
115
|
+
return true, value
|
|
116
|
+
end
|
|
117
|
+
local function iteratorIteratorStep(self)
|
|
118
|
+
local result = self:next()
|
|
119
|
+
if result.done then
|
|
120
|
+
return
|
|
121
|
+
end
|
|
122
|
+
return true, result.value
|
|
123
|
+
end
|
|
124
|
+
local function iteratorStringStep(self, index)
|
|
125
|
+
index = index + 1
|
|
126
|
+
if index > #self then
|
|
127
|
+
return
|
|
128
|
+
end
|
|
129
|
+
return index, string.sub(self, index, index)
|
|
130
|
+
end
|
|
131
|
+
function __TS__Iterator(iterable)
|
|
132
|
+
if type(iterable) == "string" then
|
|
133
|
+
return iteratorStringStep, iterable, 0
|
|
134
|
+
elseif iterable.____coroutine ~= nil then
|
|
135
|
+
return iteratorGeneratorStep, iterable
|
|
136
|
+
elseif iterable[Symbol.iterator] then
|
|
137
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
138
|
+
return iteratorIteratorStep, iterator
|
|
139
|
+
else
|
|
140
|
+
return ipairs(iterable)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
local __TS__ArrayFrom
|
|
146
|
+
do
|
|
147
|
+
local function arrayLikeStep(self, index)
|
|
148
|
+
index = index + 1
|
|
149
|
+
if index > self.length then
|
|
150
|
+
return
|
|
151
|
+
end
|
|
152
|
+
return index, self[index]
|
|
153
|
+
end
|
|
154
|
+
local function arrayLikeIterator(arr)
|
|
155
|
+
if type(arr.length) == "number" then
|
|
156
|
+
return arrayLikeStep, arr, 0
|
|
157
|
+
end
|
|
158
|
+
return __TS__Iterator(arr)
|
|
159
|
+
end
|
|
160
|
+
function __TS__ArrayFrom(arrayLike, mapFn, thisArg)
|
|
161
|
+
local result = {}
|
|
162
|
+
if mapFn == nil then
|
|
163
|
+
for ____, v in arrayLikeIterator(arrayLike) do
|
|
164
|
+
result[#result + 1] = v
|
|
165
|
+
end
|
|
166
|
+
else
|
|
167
|
+
for i, v in arrayLikeIterator(arrayLike) do
|
|
168
|
+
result[#result + 1] = mapFn(thisArg, v, i - 1)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
return result
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
118
175
|
local function __TS__ArrayIncludes(self, searchElement, fromIndex)
|
|
119
176
|
if fromIndex == nil then
|
|
120
177
|
fromIndex = 0
|
|
@@ -127,42 +184,34 @@ local function __TS__ArrayIncludes(self, searchElement, fromIndex)
|
|
|
127
184
|
if k < 0 then
|
|
128
185
|
k = 0
|
|
129
186
|
end
|
|
130
|
-
for i = k, len do
|
|
131
|
-
if self[i
|
|
187
|
+
for i = k + 1, len do
|
|
188
|
+
if self[i] == searchElement then
|
|
132
189
|
return true
|
|
133
190
|
end
|
|
134
191
|
end
|
|
135
192
|
return false
|
|
136
193
|
end
|
|
137
194
|
|
|
138
|
-
local function __TS__ArrayIndexOf(
|
|
139
|
-
|
|
195
|
+
local function __TS__ArrayIndexOf(self, searchElement, fromIndex)
|
|
196
|
+
if fromIndex == nil then
|
|
197
|
+
fromIndex = 0
|
|
198
|
+
end
|
|
199
|
+
local len = #self
|
|
140
200
|
if len == 0 then
|
|
141
201
|
return -1
|
|
142
202
|
end
|
|
143
|
-
|
|
144
|
-
if fromIndex then
|
|
145
|
-
n = fromIndex
|
|
146
|
-
end
|
|
147
|
-
if n >= len then
|
|
203
|
+
if fromIndex >= len then
|
|
148
204
|
return -1
|
|
149
205
|
end
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
k = len + n
|
|
155
|
-
if k < 0 then
|
|
156
|
-
k = 0
|
|
206
|
+
if fromIndex < 0 then
|
|
207
|
+
fromIndex = len + fromIndex
|
|
208
|
+
if fromIndex < 0 then
|
|
209
|
+
fromIndex = 0
|
|
157
210
|
end
|
|
158
211
|
end
|
|
159
|
-
do
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if arr[i + 1] == searchElement then
|
|
163
|
-
return i
|
|
164
|
-
end
|
|
165
|
-
i = i + 1
|
|
212
|
+
for i = fromIndex + 1, len do
|
|
213
|
+
if self[i] == searchElement then
|
|
214
|
+
return i - 1
|
|
166
215
|
end
|
|
167
216
|
end
|
|
168
217
|
return -1
|
|
@@ -172,312 +221,310 @@ local function __TS__ArrayJoin(self, separator)
|
|
|
172
221
|
if separator == nil then
|
|
173
222
|
separator = ","
|
|
174
223
|
end
|
|
175
|
-
local
|
|
176
|
-
for
|
|
177
|
-
|
|
178
|
-
result = result .. separator
|
|
179
|
-
end
|
|
180
|
-
result = result .. tostring(value)
|
|
224
|
+
local parts = {}
|
|
225
|
+
for i = 1, #self do
|
|
226
|
+
parts[i] = tostring(self[i])
|
|
181
227
|
end
|
|
182
|
-
return
|
|
228
|
+
return table.concat(parts, separator)
|
|
183
229
|
end
|
|
184
230
|
|
|
185
|
-
local function __TS__ArrayMap(
|
|
186
|
-
local
|
|
187
|
-
do
|
|
188
|
-
|
|
189
|
-
while i < #arr do
|
|
190
|
-
newArray[i + 1] = callbackfn(nil, arr[i + 1], i, arr)
|
|
191
|
-
i = i + 1
|
|
192
|
-
end
|
|
231
|
+
local function __TS__ArrayMap(self, callbackfn, thisArg)
|
|
232
|
+
local result = {}
|
|
233
|
+
for i = 1, #self do
|
|
234
|
+
result[i] = callbackfn(thisArg, self[i], i - 1, self)
|
|
193
235
|
end
|
|
194
|
-
return
|
|
236
|
+
return result
|
|
195
237
|
end
|
|
196
238
|
|
|
197
|
-
local function __TS__ArrayPush(
|
|
239
|
+
local function __TS__ArrayPush(self, ...)
|
|
198
240
|
local items = {...}
|
|
199
|
-
|
|
200
|
-
|
|
241
|
+
local len = #self
|
|
242
|
+
for i = 1, #items do
|
|
243
|
+
len = len + 1
|
|
244
|
+
self[len] = items[i]
|
|
245
|
+
end
|
|
246
|
+
return len
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
local function __TS__ArrayPushArray(self, items)
|
|
250
|
+
local len = #self
|
|
251
|
+
for i = 1, #items do
|
|
252
|
+
len = len + 1
|
|
253
|
+
self[len] = items[i]
|
|
201
254
|
end
|
|
202
|
-
return
|
|
255
|
+
return len
|
|
203
256
|
end
|
|
204
257
|
|
|
205
|
-
local function __TS__ArrayReduce(
|
|
206
|
-
local len = #
|
|
258
|
+
local function __TS__ArrayReduce(self, callbackFn, ...)
|
|
259
|
+
local len = #self
|
|
207
260
|
local k = 0
|
|
208
261
|
local accumulator = nil
|
|
209
262
|
if select("#", ...) ~= 0 then
|
|
210
|
-
accumulator =
|
|
263
|
+
accumulator = ...
|
|
211
264
|
elseif len > 0 then
|
|
212
|
-
accumulator =
|
|
265
|
+
accumulator = self[1]
|
|
213
266
|
k = 1
|
|
214
267
|
else
|
|
215
268
|
error("Reduce of empty array with no initial value", 0)
|
|
216
269
|
end
|
|
217
|
-
for i = k, len
|
|
270
|
+
for i = k + 1, len do
|
|
218
271
|
accumulator = callbackFn(
|
|
219
272
|
nil,
|
|
220
273
|
accumulator,
|
|
221
|
-
|
|
222
|
-
i,
|
|
223
|
-
|
|
274
|
+
self[i],
|
|
275
|
+
i - 1,
|
|
276
|
+
self
|
|
224
277
|
)
|
|
225
278
|
end
|
|
226
279
|
return accumulator
|
|
227
280
|
end
|
|
228
281
|
|
|
229
|
-
local function __TS__ArrayReduceRight(
|
|
230
|
-
local len = #
|
|
282
|
+
local function __TS__ArrayReduceRight(self, callbackFn, ...)
|
|
283
|
+
local len = #self
|
|
231
284
|
local k = len - 1
|
|
232
285
|
local accumulator = nil
|
|
233
286
|
if select("#", ...) ~= 0 then
|
|
234
|
-
accumulator =
|
|
287
|
+
accumulator = ...
|
|
235
288
|
elseif len > 0 then
|
|
236
|
-
accumulator =
|
|
289
|
+
accumulator = self[k + 1]
|
|
237
290
|
k = k - 1
|
|
238
291
|
else
|
|
239
292
|
error("Reduce of empty array with no initial value", 0)
|
|
240
293
|
end
|
|
241
|
-
for i = k,
|
|
294
|
+
for i = k + 1, 1, -1 do
|
|
242
295
|
accumulator = callbackFn(
|
|
243
296
|
nil,
|
|
244
297
|
accumulator,
|
|
245
|
-
|
|
246
|
-
i,
|
|
247
|
-
|
|
298
|
+
self[i],
|
|
299
|
+
i - 1,
|
|
300
|
+
self
|
|
248
301
|
)
|
|
249
302
|
end
|
|
250
303
|
return accumulator
|
|
251
304
|
end
|
|
252
305
|
|
|
253
|
-
local function __TS__ArrayReverse(
|
|
254
|
-
local i =
|
|
255
|
-
local j = #
|
|
306
|
+
local function __TS__ArrayReverse(self)
|
|
307
|
+
local i = 1
|
|
308
|
+
local j = #self
|
|
256
309
|
while i < j do
|
|
257
|
-
local temp =
|
|
258
|
-
|
|
259
|
-
|
|
310
|
+
local temp = self[j]
|
|
311
|
+
self[j] = self[i]
|
|
312
|
+
self[i] = temp
|
|
260
313
|
i = i + 1
|
|
261
314
|
j = j - 1
|
|
262
315
|
end
|
|
263
|
-
return
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
local function __TS__ArrayShift(arr)
|
|
267
|
-
return table.remove(arr, 1)
|
|
316
|
+
return self
|
|
268
317
|
end
|
|
269
318
|
|
|
270
|
-
local function __TS__ArrayUnshift(
|
|
319
|
+
local function __TS__ArrayUnshift(self, ...)
|
|
271
320
|
local items = {...}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
321
|
+
local numItemsToInsert = #items
|
|
322
|
+
if numItemsToInsert == 0 then
|
|
323
|
+
return #self
|
|
324
|
+
end
|
|
325
|
+
for i = #self, 1, -1 do
|
|
326
|
+
self[i + numItemsToInsert] = self[i]
|
|
278
327
|
end
|
|
279
|
-
|
|
328
|
+
for i = 1, numItemsToInsert do
|
|
329
|
+
self[i] = items[i]
|
|
330
|
+
end
|
|
331
|
+
return #self
|
|
280
332
|
end
|
|
281
333
|
|
|
282
|
-
local function __TS__ArraySort(
|
|
334
|
+
local function __TS__ArraySort(self, compareFn)
|
|
283
335
|
if compareFn ~= nil then
|
|
284
336
|
table.sort(
|
|
285
|
-
|
|
337
|
+
self,
|
|
286
338
|
function(a, b) return compareFn(nil, a, b) < 0 end
|
|
287
339
|
)
|
|
288
340
|
else
|
|
289
|
-
table.sort(
|
|
341
|
+
table.sort(self)
|
|
290
342
|
end
|
|
291
|
-
return
|
|
343
|
+
return self
|
|
292
344
|
end
|
|
293
345
|
|
|
294
|
-
local function __TS__ArraySlice(
|
|
295
|
-
local len = #
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
346
|
+
local function __TS__ArraySlice(self, first, last)
|
|
347
|
+
local len = #self
|
|
348
|
+
first = first or 0
|
|
349
|
+
if first < 0 then
|
|
350
|
+
first = len + first
|
|
351
|
+
if first < 0 then
|
|
352
|
+
first = 0
|
|
353
|
+
end
|
|
300
354
|
else
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if last == nil then
|
|
305
|
-
relativeEnd = len
|
|
355
|
+
if first > len then
|
|
356
|
+
first = len
|
|
357
|
+
end
|
|
306
358
|
end
|
|
307
|
-
|
|
308
|
-
if
|
|
309
|
-
|
|
359
|
+
last = last or len
|
|
360
|
+
if last < 0 then
|
|
361
|
+
last = len + last
|
|
362
|
+
if last < 0 then
|
|
363
|
+
last = 0
|
|
364
|
+
end
|
|
310
365
|
else
|
|
311
|
-
|
|
366
|
+
if last > len then
|
|
367
|
+
last = len
|
|
368
|
+
end
|
|
312
369
|
end
|
|
313
370
|
local out = {}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
371
|
+
first = first + 1
|
|
372
|
+
last = last + 1
|
|
373
|
+
local n = 1
|
|
374
|
+
while first < last do
|
|
375
|
+
out[n] = self[first]
|
|
376
|
+
first = first + 1
|
|
318
377
|
n = n + 1
|
|
319
378
|
end
|
|
320
379
|
return out
|
|
321
380
|
end
|
|
322
381
|
|
|
323
|
-
local function __TS__ArraySome(
|
|
324
|
-
do
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if callbackfn(nil, arr[i + 1], i, arr) then
|
|
328
|
-
return true
|
|
329
|
-
end
|
|
330
|
-
i = i + 1
|
|
382
|
+
local function __TS__ArraySome(self, callbackfn, thisArg)
|
|
383
|
+
for i = 1, #self do
|
|
384
|
+
if callbackfn(thisArg, self[i], i - 1, self) then
|
|
385
|
+
return true
|
|
331
386
|
end
|
|
332
387
|
end
|
|
333
388
|
return false
|
|
334
389
|
end
|
|
335
390
|
|
|
336
|
-
local function __TS__ArraySplice(
|
|
337
|
-
local
|
|
391
|
+
local function __TS__ArraySplice(self, ...)
|
|
392
|
+
local args = {...}
|
|
393
|
+
local len = #self
|
|
338
394
|
local actualArgumentCount = select("#", ...)
|
|
339
|
-
local start =
|
|
340
|
-
local deleteCount =
|
|
341
|
-
local actualStart
|
|
395
|
+
local start = args[1]
|
|
396
|
+
local deleteCount = args[2]
|
|
342
397
|
if start < 0 then
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
398
|
+
start = len + start
|
|
399
|
+
if start < 0 then
|
|
400
|
+
start = 0
|
|
401
|
+
end
|
|
402
|
+
elseif start > len then
|
|
403
|
+
start = len
|
|
404
|
+
end
|
|
405
|
+
local itemCount = actualArgumentCount - 2
|
|
406
|
+
if itemCount < 0 then
|
|
407
|
+
itemCount = 0
|
|
346
408
|
end
|
|
347
|
-
local itemCount = math.max(actualArgumentCount - 2, 0)
|
|
348
409
|
local actualDeleteCount
|
|
349
410
|
if actualArgumentCount == 0 then
|
|
350
411
|
actualDeleteCount = 0
|
|
351
412
|
elseif actualArgumentCount == 1 then
|
|
352
|
-
actualDeleteCount = len -
|
|
413
|
+
actualDeleteCount = len - start
|
|
353
414
|
else
|
|
354
|
-
actualDeleteCount =
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
415
|
+
actualDeleteCount = deleteCount or 0
|
|
416
|
+
if actualDeleteCount < 0 then
|
|
417
|
+
actualDeleteCount = 0
|
|
418
|
+
end
|
|
419
|
+
if actualDeleteCount > len - start then
|
|
420
|
+
actualDeleteCount = len - start
|
|
421
|
+
end
|
|
358
422
|
end
|
|
359
423
|
local out = {}
|
|
360
|
-
do
|
|
361
|
-
local
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if list[from + 1] then
|
|
365
|
-
out[k + 1] = list[from + 1]
|
|
366
|
-
end
|
|
367
|
-
k = k + 1
|
|
424
|
+
for k = 1, actualDeleteCount do
|
|
425
|
+
local from = start + k
|
|
426
|
+
if self[from] ~= nil then
|
|
427
|
+
out[k] = self[from]
|
|
368
428
|
end
|
|
369
429
|
end
|
|
370
430
|
if itemCount < actualDeleteCount then
|
|
371
|
-
do
|
|
372
|
-
local
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
else
|
|
379
|
-
list[to + 1] = nil
|
|
380
|
-
end
|
|
381
|
-
k = k + 1
|
|
431
|
+
for k = start + 1, len - actualDeleteCount do
|
|
432
|
+
local from = k + actualDeleteCount
|
|
433
|
+
local to = k + itemCount
|
|
434
|
+
if self[from] then
|
|
435
|
+
self[to] = self[from]
|
|
436
|
+
else
|
|
437
|
+
self[to] = nil
|
|
382
438
|
end
|
|
383
439
|
end
|
|
384
|
-
do
|
|
385
|
-
|
|
386
|
-
while k > len - actualDeleteCount + itemCount do
|
|
387
|
-
list[k] = nil
|
|
388
|
-
k = k - 1
|
|
389
|
-
end
|
|
440
|
+
for k = len - actualDeleteCount + itemCount + 1, len do
|
|
441
|
+
self[k] = nil
|
|
390
442
|
end
|
|
391
443
|
elseif itemCount > actualDeleteCount then
|
|
392
|
-
do
|
|
393
|
-
local
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
else
|
|
400
|
-
list[to + 1] = nil
|
|
401
|
-
end
|
|
402
|
-
k = k - 1
|
|
444
|
+
for k = len - actualDeleteCount, start + 1, -1 do
|
|
445
|
+
local from = k + actualDeleteCount
|
|
446
|
+
local to = k + itemCount
|
|
447
|
+
if self[from] then
|
|
448
|
+
self[to] = self[from]
|
|
449
|
+
else
|
|
450
|
+
self[to] = nil
|
|
403
451
|
end
|
|
404
452
|
end
|
|
405
453
|
end
|
|
406
|
-
local j =
|
|
454
|
+
local j = start + 1
|
|
407
455
|
for i = 3, actualArgumentCount do
|
|
408
|
-
|
|
456
|
+
self[j] = args[i]
|
|
409
457
|
j = j + 1
|
|
410
458
|
end
|
|
411
|
-
do
|
|
412
|
-
|
|
413
|
-
while k >= len - actualDeleteCount + itemCount do
|
|
414
|
-
list[k + 1] = nil
|
|
415
|
-
k = k - 1
|
|
416
|
-
end
|
|
459
|
+
for k = #self, len - actualDeleteCount + itemCount + 1, -1 do
|
|
460
|
+
self[k] = nil
|
|
417
461
|
end
|
|
418
462
|
return out
|
|
419
463
|
end
|
|
420
464
|
|
|
421
|
-
local function __TS__ArrayToObject(
|
|
465
|
+
local function __TS__ArrayToObject(self)
|
|
422
466
|
local object = {}
|
|
423
|
-
do
|
|
424
|
-
|
|
425
|
-
while i < #array do
|
|
426
|
-
object[i] = array[i + 1]
|
|
427
|
-
i = i + 1
|
|
428
|
-
end
|
|
467
|
+
for i = 1, #self do
|
|
468
|
+
object[i - 1] = self[i]
|
|
429
469
|
end
|
|
430
470
|
return object
|
|
431
471
|
end
|
|
432
472
|
|
|
433
|
-
local function __TS__ArrayFlat(
|
|
473
|
+
local function __TS__ArrayFlat(self, depth)
|
|
434
474
|
if depth == nil then
|
|
435
475
|
depth = 1
|
|
436
476
|
end
|
|
437
477
|
local result = {}
|
|
438
|
-
|
|
478
|
+
local len = 0
|
|
479
|
+
for i = 1, #self do
|
|
480
|
+
local value = self[i]
|
|
439
481
|
if depth > 0 and __TS__ArrayIsArray(value) then
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
482
|
+
local toAdd
|
|
483
|
+
if depth == 1 then
|
|
484
|
+
toAdd = value
|
|
485
|
+
else
|
|
486
|
+
toAdd = __TS__ArrayFlat(value, depth - 1)
|
|
487
|
+
end
|
|
488
|
+
for j = 1, #toAdd do
|
|
489
|
+
local val = toAdd[j]
|
|
490
|
+
len = len + 1
|
|
491
|
+
result[len] = val
|
|
492
|
+
end
|
|
444
493
|
else
|
|
445
|
-
|
|
494
|
+
len = len + 1
|
|
495
|
+
result[len] = value
|
|
446
496
|
end
|
|
447
497
|
end
|
|
448
498
|
return result
|
|
449
499
|
end
|
|
450
500
|
|
|
451
|
-
local function __TS__ArrayFlatMap(
|
|
501
|
+
local function __TS__ArrayFlatMap(self, callback, thisArg)
|
|
452
502
|
local result = {}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
result[#result + 1] = value
|
|
503
|
+
local len = 0
|
|
504
|
+
for i = 1, #self do
|
|
505
|
+
local value = callback(thisArg, self[i], i - 1, self)
|
|
506
|
+
if __TS__ArrayIsArray(value) then
|
|
507
|
+
for j = 1, #value do
|
|
508
|
+
len = len + 1
|
|
509
|
+
result[len] = value[j]
|
|
461
510
|
end
|
|
462
|
-
|
|
511
|
+
else
|
|
512
|
+
len = len + 1
|
|
513
|
+
result[len] = value
|
|
463
514
|
end
|
|
464
515
|
end
|
|
465
516
|
return result
|
|
466
517
|
end
|
|
467
518
|
|
|
468
|
-
local function __TS__ArraySetLength(
|
|
519
|
+
local function __TS__ArraySetLength(self, length)
|
|
469
520
|
if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
|
|
470
521
|
error(
|
|
471
522
|
"invalid array length: " .. tostring(length),
|
|
472
523
|
0
|
|
473
524
|
)
|
|
474
525
|
end
|
|
475
|
-
do
|
|
476
|
-
|
|
477
|
-
while i >= length do
|
|
478
|
-
arr[i + 1] = nil
|
|
479
|
-
i = i - 1
|
|
480
|
-
end
|
|
526
|
+
for i = length + 1, #self do
|
|
527
|
+
self[i] = nil
|
|
481
528
|
end
|
|
482
529
|
return length
|
|
483
530
|
end
|
|
@@ -516,21 +563,15 @@ end
|
|
|
516
563
|
|
|
517
564
|
local __TS__Unpack = table.unpack or unpack
|
|
518
565
|
|
|
519
|
-
local function __TS__FunctionBind(fn,
|
|
566
|
+
local function __TS__FunctionBind(fn, ...)
|
|
520
567
|
local boundArgs = {...}
|
|
521
568
|
return function(____, ...)
|
|
522
569
|
local args = {...}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
table.insert(args, i + 1, boundArgs[i + 1])
|
|
527
|
-
i = i + 1
|
|
528
|
-
end
|
|
529
|
-
end
|
|
530
|
-
return fn(
|
|
531
|
-
thisArg,
|
|
532
|
-
__TS__Unpack(args)
|
|
570
|
+
__TS__ArrayUnshift(
|
|
571
|
+
args,
|
|
572
|
+
__TS__Unpack(boundArgs)
|
|
533
573
|
)
|
|
574
|
+
return fn(__TS__Unpack(args))
|
|
534
575
|
end
|
|
535
576
|
end
|
|
536
577
|
|
|
@@ -603,19 +644,19 @@ do
|
|
|
603
644
|
local isRejected = self.state == 2
|
|
604
645
|
if onFulfilled then
|
|
605
646
|
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
606
|
-
|
|
647
|
+
local ____self_fulfilledCallbacks_1 = self.fulfilledCallbacks
|
|
648
|
+
____self_fulfilledCallbacks_1[#____self_fulfilledCallbacks_1 + 1] = internalCallback
|
|
607
649
|
if isFulfilled then
|
|
608
650
|
internalCallback(nil, self.value)
|
|
609
651
|
end
|
|
610
652
|
else
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
function() return resolve(nil, nil) end
|
|
614
|
-
)
|
|
653
|
+
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
654
|
+
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function() return resolve(nil, nil) end
|
|
615
655
|
end
|
|
616
656
|
if onRejected then
|
|
617
657
|
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
618
|
-
|
|
658
|
+
local ____self_rejectedCallbacks_3 = self.rejectedCallbacks
|
|
659
|
+
____self_rejectedCallbacks_3[#____self_rejectedCallbacks_3 + 1] = internalCallback
|
|
619
660
|
if isRejected then
|
|
620
661
|
internalCallback(nil, self.rejectionReason)
|
|
621
662
|
end
|
|
@@ -633,7 +674,8 @@ do
|
|
|
633
674
|
end
|
|
634
675
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
635
676
|
if onFinally then
|
|
636
|
-
|
|
677
|
+
local ____self_finallyCallbacks_4 = self.finallyCallbacks
|
|
678
|
+
____self_finallyCallbacks_4[#____self_finallyCallbacks_4 + 1] = onFinally
|
|
637
679
|
if self.state ~= 0 then
|
|
638
680
|
onFinally(nil)
|
|
639
681
|
end
|
|
@@ -829,17 +871,15 @@ local function __TS__CloneDescriptor(____bindingPattern0)
|
|
|
829
871
|
return descriptor
|
|
830
872
|
end
|
|
831
873
|
|
|
832
|
-
local function __TS__ObjectAssign(
|
|
874
|
+
local function __TS__ObjectAssign(target, ...)
|
|
833
875
|
local sources = {...}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
end
|
|
837
|
-
for ____, source in ipairs(sources) do
|
|
876
|
+
for i = 1, #sources do
|
|
877
|
+
local source = sources[i]
|
|
838
878
|
for key in pairs(source) do
|
|
839
|
-
|
|
879
|
+
target[key] = source[key]
|
|
840
880
|
end
|
|
841
881
|
end
|
|
842
|
-
return
|
|
882
|
+
return target
|
|
843
883
|
end
|
|
844
884
|
|
|
845
885
|
local function __TS__ObjectGetOwnPropertyDescriptor(object, key)
|
|
@@ -1158,47 +1198,6 @@ local function __TS__InstanceOfObject(value)
|
|
|
1158
1198
|
return valueType == "table" or valueType == "function"
|
|
1159
1199
|
end
|
|
1160
1200
|
|
|
1161
|
-
local __TS__Iterator
|
|
1162
|
-
do
|
|
1163
|
-
local function iteratorGeneratorStep(self)
|
|
1164
|
-
local co = self.____coroutine
|
|
1165
|
-
local status, value = coroutine.resume(co)
|
|
1166
|
-
if not status then
|
|
1167
|
-
error(value, 0)
|
|
1168
|
-
end
|
|
1169
|
-
if coroutine.status(co) == "dead" then
|
|
1170
|
-
return
|
|
1171
|
-
end
|
|
1172
|
-
return true, value
|
|
1173
|
-
end
|
|
1174
|
-
local function iteratorIteratorStep(self)
|
|
1175
|
-
local result = self:next()
|
|
1176
|
-
if result.done then
|
|
1177
|
-
return
|
|
1178
|
-
end
|
|
1179
|
-
return true, result.value
|
|
1180
|
-
end
|
|
1181
|
-
local function iteratorStringStep(self, index)
|
|
1182
|
-
index = index + 1
|
|
1183
|
-
if index > #self then
|
|
1184
|
-
return
|
|
1185
|
-
end
|
|
1186
|
-
return index, string.sub(self, index, index)
|
|
1187
|
-
end
|
|
1188
|
-
function __TS__Iterator(iterable)
|
|
1189
|
-
if type(iterable) == "string" then
|
|
1190
|
-
return iteratorStringStep, iterable, 0
|
|
1191
|
-
elseif iterable.____coroutine ~= nil then
|
|
1192
|
-
return iteratorGeneratorStep, iterable
|
|
1193
|
-
elseif iterable[Symbol.iterator] then
|
|
1194
|
-
local iterator = iterable[Symbol.iterator](iterable)
|
|
1195
|
-
return iteratorIteratorStep, iterator
|
|
1196
|
-
else
|
|
1197
|
-
return ipairs(iterable)
|
|
1198
|
-
end
|
|
1199
|
-
end
|
|
1200
|
-
end
|
|
1201
|
-
|
|
1202
1201
|
local Map
|
|
1203
1202
|
do
|
|
1204
1203
|
Map = __TS__Class()
|
|
@@ -1495,8 +1494,10 @@ end
|
|
|
1495
1494
|
|
|
1496
1495
|
local function __TS__ObjectEntries(obj)
|
|
1497
1496
|
local result = {}
|
|
1497
|
+
local len = 0
|
|
1498
1498
|
for key in pairs(obj) do
|
|
1499
|
-
|
|
1499
|
+
len = len + 1
|
|
1500
|
+
result[len] = {key, obj[key]}
|
|
1500
1501
|
end
|
|
1501
1502
|
return result
|
|
1502
1503
|
end
|
|
@@ -1524,8 +1525,10 @@ end
|
|
|
1524
1525
|
|
|
1525
1526
|
local function __TS__ObjectKeys(obj)
|
|
1526
1527
|
local result = {}
|
|
1528
|
+
local len = 0
|
|
1527
1529
|
for key in pairs(obj) do
|
|
1528
|
-
|
|
1530
|
+
len = len + 1
|
|
1531
|
+
result[len] = key
|
|
1529
1532
|
end
|
|
1530
1533
|
return result
|
|
1531
1534
|
end
|
|
@@ -1542,8 +1545,10 @@ end
|
|
|
1542
1545
|
|
|
1543
1546
|
local function __TS__ObjectValues(obj)
|
|
1544
1547
|
local result = {}
|
|
1548
|
+
local len = 0
|
|
1545
1549
|
for key in pairs(obj) do
|
|
1546
|
-
|
|
1550
|
+
len = len + 1
|
|
1551
|
+
result[len] = obj[key]
|
|
1547
1552
|
end
|
|
1548
1553
|
return result
|
|
1549
1554
|
end
|
|
@@ -1743,9 +1748,9 @@ local function __TS__PromiseAny(iterable)
|
|
|
1743
1748
|
if item.state == 1 then
|
|
1744
1749
|
return __TS__Promise.resolve(item.value)
|
|
1745
1750
|
elseif item.state == 2 then
|
|
1746
|
-
|
|
1751
|
+
rejections[#rejections + 1] = item.rejectionReason
|
|
1747
1752
|
else
|
|
1748
|
-
|
|
1753
|
+
pending[#pending + 1] = item
|
|
1749
1754
|
end
|
|
1750
1755
|
else
|
|
1751
1756
|
return __TS__Promise.resolve(item)
|
|
@@ -1765,7 +1770,7 @@ local function __TS__PromiseAny(iterable)
|
|
|
1765
1770
|
resolve(nil, data)
|
|
1766
1771
|
end,
|
|
1767
1772
|
function(____, reason)
|
|
1768
|
-
|
|
1773
|
+
rejections[#rejections + 1] = reason
|
|
1769
1774
|
numResolved = numResolved + 1
|
|
1770
1775
|
if numResolved == #pending then
|
|
1771
1776
|
reject(nil, {name = "AggregateError", message = "All Promises rejected", errors = rejections})
|
|
@@ -1786,7 +1791,7 @@ local function __TS__PromiseRace(iterable)
|
|
|
1786
1791
|
elseif item.state == 2 then
|
|
1787
1792
|
return __TS__Promise.reject(item.rejectionReason)
|
|
1788
1793
|
else
|
|
1789
|
-
|
|
1794
|
+
pending[#pending + 1] = item
|
|
1790
1795
|
end
|
|
1791
1796
|
else
|
|
1792
1797
|
return __TS__Promise.resolve(item)
|
|
@@ -2091,16 +2096,14 @@ end
|
|
|
2091
2096
|
local function __TS__Spread(iterable)
|
|
2092
2097
|
local arr = {}
|
|
2093
2098
|
if type(iterable) == "string" then
|
|
2094
|
-
do
|
|
2095
|
-
|
|
2096
|
-
while i < #iterable do
|
|
2097
|
-
arr[#arr + 1] = __TS__StringAccess(iterable, i)
|
|
2098
|
-
i = i + 1
|
|
2099
|
-
end
|
|
2099
|
+
for i = 0, #iterable - 1 do
|
|
2100
|
+
arr[i + 1] = __TS__StringAccess(iterable, i)
|
|
2100
2101
|
end
|
|
2101
2102
|
else
|
|
2103
|
+
local len = 0
|
|
2102
2104
|
for ____, item in __TS__Iterator(iterable) do
|
|
2103
|
-
|
|
2105
|
+
len = len + 1
|
|
2106
|
+
arr[len] = item
|
|
2104
2107
|
end
|
|
2105
2108
|
end
|
|
2106
2109
|
return __TS__Unpack(arr)
|
|
@@ -2126,15 +2129,6 @@ local function __TS__StringCharCodeAt(self, index)
|
|
|
2126
2129
|
return string.byte(self, index + 1) or 0 / 0
|
|
2127
2130
|
end
|
|
2128
2131
|
|
|
2129
|
-
local function __TS__StringConcat(str1, ...)
|
|
2130
|
-
local args = {...}
|
|
2131
|
-
local out = str1
|
|
2132
|
-
for ____, arg in ipairs(args) do
|
|
2133
|
-
out = out .. arg
|
|
2134
|
-
end
|
|
2135
|
-
return out
|
|
2136
|
-
end
|
|
2137
|
-
|
|
2138
2132
|
local function __TS__StringEndsWith(self, searchString, endPosition)
|
|
2139
2133
|
if endPosition == nil or endPosition > #self then
|
|
2140
2134
|
endPosition = #self
|
|
@@ -2206,58 +2200,105 @@ local function __TS__StringPadStart(self, maxLength, fillString)
|
|
|
2206
2200
|
) .. self
|
|
2207
2201
|
end
|
|
2208
2202
|
|
|
2209
|
-
local
|
|
2210
|
-
|
|
2211
|
-
if not startPos then
|
|
2212
|
-
return source
|
|
2213
|
-
end
|
|
2203
|
+
local __TS__StringReplace
|
|
2204
|
+
do
|
|
2214
2205
|
local sub = string.sub
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2206
|
+
function __TS__StringReplace(source, searchValue, replaceValue)
|
|
2207
|
+
local startPos, endPos = string.find(source, searchValue, nil, true)
|
|
2208
|
+
if not startPos then
|
|
2209
|
+
return source
|
|
2210
|
+
end
|
|
2211
|
+
local before = sub(source, 1, startPos - 1)
|
|
2212
|
+
local ____temp_0
|
|
2213
|
+
if type(replaceValue) == "string" then
|
|
2214
|
+
____temp_0 = replaceValue
|
|
2215
|
+
else
|
|
2216
|
+
____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
|
|
2217
|
+
end
|
|
2218
|
+
local replacement = ____temp_0
|
|
2219
|
+
local after = sub(source, endPos + 1)
|
|
2220
|
+
return (before .. replacement) .. after
|
|
2221
2221
|
end
|
|
2222
|
-
local replacement = ____temp_0
|
|
2223
|
-
local after = sub(source, endPos + 1)
|
|
2224
|
-
return (before .. replacement) .. after
|
|
2225
2222
|
end
|
|
2226
2223
|
|
|
2227
|
-
local
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2224
|
+
local __TS__StringSplit
|
|
2225
|
+
do
|
|
2226
|
+
local sub = string.sub
|
|
2227
|
+
local find = string.find
|
|
2228
|
+
function __TS__StringSplit(source, separator, limit)
|
|
2229
|
+
if limit == nil then
|
|
2230
|
+
limit = 4294967295
|
|
2231
|
+
end
|
|
2232
|
+
if limit == 0 then
|
|
2233
|
+
return {}
|
|
2234
|
+
end
|
|
2235
|
+
local result = {}
|
|
2236
|
+
local resultIndex = 1
|
|
2237
|
+
if separator == nil or separator == "" then
|
|
2238
|
+
for i = 1, #source do
|
|
2239
|
+
result[resultIndex] = sub(source, i, i)
|
|
2240
|
+
resultIndex = resultIndex + 1
|
|
2241
|
+
end
|
|
2242
|
+
else
|
|
2243
|
+
local currentPos = 1
|
|
2244
|
+
while resultIndex <= limit do
|
|
2245
|
+
local startPos, endPos = find(source, separator, currentPos, true)
|
|
2246
|
+
if not startPos then
|
|
2247
|
+
break
|
|
2248
|
+
end
|
|
2249
|
+
result[resultIndex] = sub(source, currentPos, startPos - 1)
|
|
2250
|
+
resultIndex = resultIndex + 1
|
|
2251
|
+
currentPos = endPos + 1
|
|
2252
|
+
end
|
|
2253
|
+
if resultIndex <= limit then
|
|
2254
|
+
result[resultIndex] = sub(source, currentPos)
|
|
2255
|
+
end
|
|
2256
|
+
end
|
|
2257
|
+
return result
|
|
2233
2258
|
end
|
|
2234
|
-
|
|
2235
|
-
|
|
2259
|
+
end
|
|
2260
|
+
|
|
2261
|
+
local __TS__StringReplaceAll
|
|
2262
|
+
do
|
|
2236
2263
|
local sub = string.sub
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2264
|
+
local find = string.find
|
|
2265
|
+
function __TS__StringReplaceAll(source, searchValue, replaceValue)
|
|
2266
|
+
if type(replaceValue) == "string" then
|
|
2267
|
+
local concat = table.concat(
|
|
2268
|
+
__TS__StringSplit(source, searchValue),
|
|
2269
|
+
replaceValue
|
|
2270
|
+
)
|
|
2271
|
+
if #searchValue == 0 then
|
|
2272
|
+
return (replaceValue .. concat) .. replaceValue
|
|
2273
|
+
end
|
|
2274
|
+
return concat
|
|
2244
2275
|
end
|
|
2245
|
-
|
|
2246
|
-
local
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2276
|
+
local parts = {}
|
|
2277
|
+
local partsIndex = 1
|
|
2278
|
+
if #searchValue == 0 then
|
|
2279
|
+
parts[1] = replaceValue(nil, "", 0, source)
|
|
2280
|
+
partsIndex = 2
|
|
2281
|
+
for i = 1, #source do
|
|
2282
|
+
parts[partsIndex] = sub(source, i, i)
|
|
2283
|
+
parts[partsIndex + 1] = replaceValue(nil, "", i, source)
|
|
2284
|
+
partsIndex = partsIndex + 2
|
|
2252
2285
|
end
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2286
|
+
else
|
|
2287
|
+
local currentPos = 1
|
|
2288
|
+
while true do
|
|
2289
|
+
local startPos, endPos = find(source, searchValue, currentPos, true)
|
|
2290
|
+
if not startPos then
|
|
2291
|
+
break
|
|
2292
|
+
end
|
|
2293
|
+
parts[partsIndex] = sub(source, currentPos, startPos - 1)
|
|
2294
|
+
parts[partsIndex + 1] = replaceValue(nil, searchValue, startPos - 1, source)
|
|
2295
|
+
partsIndex = partsIndex + 2
|
|
2296
|
+
currentPos = endPos + 1
|
|
2297
|
+
end
|
|
2298
|
+
parts[partsIndex] = sub(source, currentPos)
|
|
2257
2299
|
end
|
|
2258
|
-
|
|
2300
|
+
return table.concat(parts)
|
|
2259
2301
|
end
|
|
2260
|
-
return table.concat(parts)
|
|
2261
2302
|
end
|
|
2262
2303
|
|
|
2263
2304
|
local function __TS__StringSlice(self, start, ____end)
|
|
@@ -2276,43 +2317,6 @@ local function __TS__StringSlice(self, start, ____end)
|
|
|
2276
2317
|
return string.sub(self, start, ____end)
|
|
2277
2318
|
end
|
|
2278
2319
|
|
|
2279
|
-
local function __TS__StringSplit(source, separator, limit)
|
|
2280
|
-
if limit == nil then
|
|
2281
|
-
limit = 4294967295
|
|
2282
|
-
end
|
|
2283
|
-
if limit == 0 then
|
|
2284
|
-
return {}
|
|
2285
|
-
end
|
|
2286
|
-
local out = {}
|
|
2287
|
-
local index = 0
|
|
2288
|
-
local count = 0
|
|
2289
|
-
if separator == nil or separator == "" then
|
|
2290
|
-
while index < #source - 1 and count < limit do
|
|
2291
|
-
out[count + 1] = __TS__StringAccess(source, index)
|
|
2292
|
-
count = count + 1
|
|
2293
|
-
index = index + 1
|
|
2294
|
-
end
|
|
2295
|
-
else
|
|
2296
|
-
local separatorLength = #separator
|
|
2297
|
-
local nextIndex = (string.find(source, separator, nil, true) or 0) - 1
|
|
2298
|
-
while nextIndex >= 0 and count < limit do
|
|
2299
|
-
out[count + 1] = __TS__StringSubstring(source, index, nextIndex)
|
|
2300
|
-
count = count + 1
|
|
2301
|
-
index = nextIndex + separatorLength
|
|
2302
|
-
nextIndex = (string.find(
|
|
2303
|
-
source,
|
|
2304
|
-
separator,
|
|
2305
|
-
math.max(index + 1, 1),
|
|
2306
|
-
true
|
|
2307
|
-
) or 0) - 1
|
|
2308
|
-
end
|
|
2309
|
-
end
|
|
2310
|
-
if count < limit then
|
|
2311
|
-
out[count + 1] = __TS__StringSubstring(source, index)
|
|
2312
|
-
end
|
|
2313
|
-
return out
|
|
2314
|
-
end
|
|
2315
|
-
|
|
2316
2320
|
local function __TS__StringStartsWith(self, searchString, position)
|
|
2317
2321
|
if position == nil or position < 0 then
|
|
2318
2322
|
position = 0
|
|
@@ -2372,16 +2376,17 @@ return {
|
|
|
2372
2376
|
__TS__ArrayForEach = __TS__ArrayForEach,
|
|
2373
2377
|
__TS__ArrayFind = __TS__ArrayFind,
|
|
2374
2378
|
__TS__ArrayFindIndex = __TS__ArrayFindIndex,
|
|
2379
|
+
__TS__ArrayFrom = __TS__ArrayFrom,
|
|
2375
2380
|
__TS__ArrayIncludes = __TS__ArrayIncludes,
|
|
2376
2381
|
__TS__ArrayIndexOf = __TS__ArrayIndexOf,
|
|
2377
2382
|
__TS__ArrayIsArray = __TS__ArrayIsArray,
|
|
2378
2383
|
__TS__ArrayJoin = __TS__ArrayJoin,
|
|
2379
2384
|
__TS__ArrayMap = __TS__ArrayMap,
|
|
2380
2385
|
__TS__ArrayPush = __TS__ArrayPush,
|
|
2386
|
+
__TS__ArrayPushArray = __TS__ArrayPushArray,
|
|
2381
2387
|
__TS__ArrayReduce = __TS__ArrayReduce,
|
|
2382
2388
|
__TS__ArrayReduceRight = __TS__ArrayReduceRight,
|
|
2383
2389
|
__TS__ArrayReverse = __TS__ArrayReverse,
|
|
2384
|
-
__TS__ArrayShift = __TS__ArrayShift,
|
|
2385
2390
|
__TS__ArrayUnshift = __TS__ArrayUnshift,
|
|
2386
2391
|
__TS__ArraySort = __TS__ArraySort,
|
|
2387
2392
|
__TS__ArraySlice = __TS__ArraySlice,
|
|
@@ -2447,7 +2452,6 @@ return {
|
|
|
2447
2452
|
__TS__StringAccess = __TS__StringAccess,
|
|
2448
2453
|
__TS__StringCharAt = __TS__StringCharAt,
|
|
2449
2454
|
__TS__StringCharCodeAt = __TS__StringCharCodeAt,
|
|
2450
|
-
__TS__StringConcat = __TS__StringConcat,
|
|
2451
2455
|
__TS__StringEndsWith = __TS__StringEndsWith,
|
|
2452
2456
|
__TS__StringIncludes = __TS__StringIncludes,
|
|
2453
2457
|
__TS__StringPadEnd = __TS__StringPadEnd,
|