typescript-to-lua 1.0.1 → 1.3.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/CHANGELOG.md +46 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.d.ts +1 -0
- package/dist/LuaAST.js +14 -6
- package/dist/LuaLib.d.ts +4 -3
- package/dist/LuaLib.js +6 -5
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +81 -29
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +7 -1
- package/dist/lualib/ArrayReduceRight.lua +7 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArraySplice.lua +5 -5
- package/dist/lualib/Await.lua +43 -19
- package/dist/lualib/CloneDescriptor.lua +7 -7
- package/dist/lualib/Decorate.lua +1 -1
- package/dist/lualib/DelegatedYield.lua +1 -3
- package/dist/lualib/Delete.lua +6 -6
- package/dist/lualib/Error.lua +47 -44
- package/dist/lualib/Generator.lua +1 -5
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Map.lua +130 -134
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberToString.lua +3 -5
- package/dist/lualib/ObjectDefineProperty.lua +40 -8
- package/dist/lualib/ParseFloat.lua +9 -5
- package/dist/lualib/ParseInt.lua +15 -3
- package/dist/lualib/Promise.lua +44 -26
- package/dist/lualib/Set.lua +119 -123
- package/dist/lualib/SetDescriptor.lua +7 -1
- package/dist/lualib/SourceMapTraceBack.lua +19 -9
- package/dist/lualib/SparseArrayNew.lua +5 -0
- package/dist/lualib/SparseArrayPush.lua +9 -0
- package/dist/lualib/SparseArraySpread.lua +4 -0
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +2 -2
- package/dist/lualib/StringPadEnd.lua +2 -2
- package/dist/lualib/StringPadStart.lua +2 -2
- package/dist/lualib/StringReplace.lua +12 -11
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSlice.lua +2 -2
- package/dist/lualib/StringSplit.lua +3 -3
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +2 -2
- package/dist/lualib/Symbol.lua +3 -5
- package/dist/lualib/WeakMap.lua +40 -42
- package/dist/lualib/WeakSet.lua +36 -38
- package/dist/lualib/lualib_bundle.lua +876 -745
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +14 -12
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.d.ts +1 -1
- package/dist/transformation/builtins/index.js +69 -36
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.d.ts +2 -1
- package/dist/transformation/builtins/object.js +12 -13
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -31
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.d.ts +12 -0
- package/dist/transformation/context/context.js +105 -6
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -3
- package/dist/transformation/utils/annotations.js +0 -2
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +9 -0
- package/dist/transformation/utils/diagnostics.js +8 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/language-extensions.d.ts +2 -0
- package/dist/transformation/utils/language-extensions.js +7 -1
- package/dist/transformation/utils/lua-ast.d.ts +0 -1
- package/dist/transformation/utils/lua-ast.js +25 -35
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/preceding-statements.d.ts +3 -0
- package/dist/transformation/utils/preceding-statements.js +11 -0
- package/dist/transformation/utils/safe-names.d.ts +4 -2
- package/dist/transformation/utils/safe-names.js +13 -7
- package/dist/transformation/utils/scope.d.ts +9 -1
- package/dist/transformation/utils/scope.js +78 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +16 -1
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/utils/typescript/types.d.ts +3 -1
- package/dist/transformation/utils/typescript/types.js +40 -13
- package/dist/transformation/visitors/access.d.ts +3 -0
- package/dist/transformation/visitors/access.js +74 -47
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
- package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
- package/dist/transformation/visitors/binary-expression/compound.js +69 -71
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
- package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
- package/dist/transformation/visitors/binary-expression/index.js +84 -42
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +2 -2
- package/dist/transformation/visitors/call.d.ts +3 -2
- package/dist/transformation/visitors/call.js +130 -143
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +43 -39
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +14 -16
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +36 -43
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +35 -33
- package/dist/transformation/visitors/expression-list.d.ts +7 -0
- package/dist/transformation/visitors/expression-list.js +120 -0
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.d.ts +2 -0
- package/dist/transformation/visitors/function.js +80 -33
- package/dist/transformation/visitors/identifier.js +26 -22
- package/dist/transformation/visitors/index.js +2 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -3
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +87 -57
- package/dist/transformation/visitors/loops/do-while.js +35 -9
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +17 -13
- package/dist/transformation/visitors/loops/for.js +28 -8
- package/dist/transformation/visitors/loops/utils.d.ts +1 -0
- package/dist/transformation/visitors/loops/utils.js +26 -10
- package/dist/transformation/visitors/modules/export.js +14 -15
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
- package/dist/transformation/visitors/optional-chaining.js +172 -0
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +12 -9
- package/dist/transformation/visitors/spread.js +23 -16
- package/dist/transformation/visitors/switch.js +63 -20
- package/dist/transformation/visitors/template.js +10 -7
- package/dist/transformation/visitors/typeof.js +4 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +55 -32
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +20 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +52 -10
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +20 -13
- package/dist/transpilation/transformers.js +45 -25
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +5 -3
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/language-extensions/index.d.ts +11 -1
- package/package.json +15 -12
- package/dist/lualib/OptionalChainAccess.lua +0 -6
- package/dist/lualib/OptionalFunctionCall.lua +0 -6
- package/dist/lualib/OptionalMethodCall.lua +0 -11
- package/dist/transformation/utils/transform.d.ts +0 -8
- package/dist/transformation/utils/transform.js +0 -14
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function __TS__ArrayIsArray(value)
|
|
2
|
-
return
|
|
2
|
+
return type(value) == "table" and (value[1] ~= nil or next(value, nil) == nil)
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
function __TS__ArrayConcat(arr1, ...)
|
|
@@ -199,7 +199,13 @@ function __TS__ArrayReduce(arr, callbackFn, ...)
|
|
|
199
199
|
error("Reduce of empty array with no initial value", 0)
|
|
200
200
|
end
|
|
201
201
|
for i = k, len - 1 do
|
|
202
|
-
accumulator = callbackFn(
|
|
202
|
+
accumulator = callbackFn(
|
|
203
|
+
_G,
|
|
204
|
+
accumulator,
|
|
205
|
+
arr[i + 1],
|
|
206
|
+
i,
|
|
207
|
+
arr
|
|
208
|
+
)
|
|
203
209
|
end
|
|
204
210
|
return accumulator
|
|
205
211
|
end
|
|
@@ -217,7 +223,13 @@ function __TS__ArrayReduceRight(arr, callbackFn, ...)
|
|
|
217
223
|
error("Reduce of empty array with no initial value", 0)
|
|
218
224
|
end
|
|
219
225
|
for i = k, 0, -1 do
|
|
220
|
-
accumulator = callbackFn(
|
|
226
|
+
accumulator = callbackFn(
|
|
227
|
+
_G,
|
|
228
|
+
accumulator,
|
|
229
|
+
arr[i + 1],
|
|
230
|
+
i,
|
|
231
|
+
arr
|
|
232
|
+
)
|
|
221
233
|
end
|
|
222
234
|
return accumulator
|
|
223
235
|
end
|
|
@@ -342,7 +354,7 @@ function __TS__ArraySplice(list, ...)
|
|
|
342
354
|
if itemCount < actualDeleteCount then
|
|
343
355
|
do
|
|
344
356
|
local k = actualStart
|
|
345
|
-
while k <
|
|
357
|
+
while k < len - actualDeleteCount do
|
|
346
358
|
local from = k + actualDeleteCount
|
|
347
359
|
local to = k + itemCount
|
|
348
360
|
if list[from + 1] then
|
|
@@ -355,7 +367,7 @@ function __TS__ArraySplice(list, ...)
|
|
|
355
367
|
end
|
|
356
368
|
do
|
|
357
369
|
local k = len
|
|
358
|
-
while k >
|
|
370
|
+
while k > len - actualDeleteCount + itemCount do
|
|
359
371
|
list[k] = nil
|
|
360
372
|
k = k - 1
|
|
361
373
|
end
|
|
@@ -364,8 +376,8 @@ function __TS__ArraySplice(list, ...)
|
|
|
364
376
|
do
|
|
365
377
|
local k = len - actualDeleteCount
|
|
366
378
|
while k > actualStart do
|
|
367
|
-
local from =
|
|
368
|
-
local to =
|
|
379
|
+
local from = k + actualDeleteCount - 1
|
|
380
|
+
local to = k + itemCount - 1
|
|
369
381
|
if list[from + 1] then
|
|
370
382
|
list[to + 1] = list[from + 1]
|
|
371
383
|
else
|
|
@@ -382,7 +394,7 @@ function __TS__ArraySplice(list, ...)
|
|
|
382
394
|
end
|
|
383
395
|
do
|
|
384
396
|
local k = #list - 1
|
|
385
|
-
while k >=
|
|
397
|
+
while k >= len - actualDeleteCount + itemCount do
|
|
386
398
|
list[k + 1] = nil
|
|
387
399
|
k = k - 1
|
|
388
400
|
end
|
|
@@ -408,7 +420,7 @@ function __TS__ArrayFlat(array, depth)
|
|
|
408
420
|
end
|
|
409
421
|
local result = {}
|
|
410
422
|
for ____, value in ipairs(array) do
|
|
411
|
-
if
|
|
423
|
+
if depth > 0 and __TS__ArrayIsArray(value) then
|
|
412
424
|
result = __TS__ArrayConcat(
|
|
413
425
|
result,
|
|
414
426
|
__TS__ArrayFlat(value, depth - 1)
|
|
@@ -426,7 +438,7 @@ function __TS__ArrayFlatMap(array, callback)
|
|
|
426
438
|
local i = 0
|
|
427
439
|
while i < #array do
|
|
428
440
|
local value = callback(_G, array[i + 1], i, array)
|
|
429
|
-
if
|
|
441
|
+
if type(value) == "table" and __TS__ArrayIsArray(value) then
|
|
430
442
|
result = __TS__ArrayConcat(result, value)
|
|
431
443
|
else
|
|
432
444
|
result[#result + 1] = value
|
|
@@ -438,7 +450,7 @@ function __TS__ArrayFlatMap(array, callback)
|
|
|
438
450
|
end
|
|
439
451
|
|
|
440
452
|
function __TS__ArraySetLength(arr, length)
|
|
441
|
-
if
|
|
453
|
+
if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
|
|
442
454
|
error(
|
|
443
455
|
"invalid array length: " .. tostring(length),
|
|
444
456
|
0
|
|
@@ -454,11 +466,9 @@ function __TS__ArraySetLength(arr, length)
|
|
|
454
466
|
return length
|
|
455
467
|
end
|
|
456
468
|
|
|
457
|
-
____symbolMetatable = {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
end
|
|
461
|
-
}
|
|
469
|
+
____symbolMetatable = {__tostring = function(self)
|
|
470
|
+
return ("Symbol(" .. (self.description or "")) .. ")"
|
|
471
|
+
end}
|
|
462
472
|
function __TS__Symbol(description)
|
|
463
473
|
return setmetatable({description = description}, ____symbolMetatable)
|
|
464
474
|
end
|
|
@@ -474,7 +484,7 @@ function __TS__InstanceOf(obj, classTbl)
|
|
|
474
484
|
error("Right-hand side of 'instanceof' is not an object", 0)
|
|
475
485
|
end
|
|
476
486
|
if classTbl[Symbol.hasInstance] ~= nil then
|
|
477
|
-
return not
|
|
487
|
+
return not not classTbl[Symbol.hasInstance](classTbl, obj)
|
|
478
488
|
end
|
|
479
489
|
if type(obj) == "table" then
|
|
480
490
|
local luaClass = obj.constructor
|
|
@@ -494,55 +504,276 @@ function __TS__New(target, ...)
|
|
|
494
504
|
return instance
|
|
495
505
|
end
|
|
496
506
|
|
|
507
|
+
function __TS__Class(self)
|
|
508
|
+
local c = {prototype = {}}
|
|
509
|
+
c.prototype.__index = c.prototype
|
|
510
|
+
c.prototype.constructor = c
|
|
511
|
+
return c
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
__TS__Unpack = table.unpack or unpack
|
|
515
|
+
|
|
516
|
+
function __TS__FunctionBind(fn, thisArg, ...)
|
|
517
|
+
local boundArgs = {...}
|
|
518
|
+
return function(____, ...)
|
|
519
|
+
local args = {...}
|
|
520
|
+
do
|
|
521
|
+
local i = 0
|
|
522
|
+
while i < #boundArgs do
|
|
523
|
+
table.insert(args, i + 1, boundArgs[i + 1])
|
|
524
|
+
i = i + 1
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
return fn(
|
|
528
|
+
thisArg,
|
|
529
|
+
__TS__Unpack(args)
|
|
530
|
+
)
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
__TS__PromiseState = __TS__PromiseState or ({})
|
|
535
|
+
__TS__PromiseState.Pending = 0
|
|
536
|
+
__TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
|
|
537
|
+
__TS__PromiseState.Fulfilled = 1
|
|
538
|
+
__TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
|
|
539
|
+
__TS__PromiseState.Rejected = 2
|
|
540
|
+
__TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
|
|
541
|
+
function __TS__PromiseDeferred(self)
|
|
542
|
+
local resolve
|
|
543
|
+
local reject
|
|
544
|
+
local promise = __TS__New(
|
|
545
|
+
__TS__Promise,
|
|
546
|
+
function(____, res, rej)
|
|
547
|
+
resolve = res
|
|
548
|
+
reject = rej
|
|
549
|
+
end
|
|
550
|
+
)
|
|
551
|
+
return {promise = promise, resolve = resolve, reject = reject}
|
|
552
|
+
end
|
|
553
|
+
function __TS__IsPromiseLike(self, thing)
|
|
554
|
+
return __TS__InstanceOf(thing, __TS__Promise)
|
|
555
|
+
end
|
|
556
|
+
__TS__Promise = __TS__Class()
|
|
557
|
+
__TS__Promise.name = "__TS__Promise"
|
|
558
|
+
function __TS__Promise.prototype.____constructor(self, executor)
|
|
559
|
+
self.state = __TS__PromiseState.Pending
|
|
560
|
+
self.fulfilledCallbacks = {}
|
|
561
|
+
self.rejectedCallbacks = {}
|
|
562
|
+
self.finallyCallbacks = {}
|
|
563
|
+
do
|
|
564
|
+
local function ____catch(e)
|
|
565
|
+
self:reject(e)
|
|
566
|
+
end
|
|
567
|
+
local ____try, ____hasReturned = pcall(function()
|
|
568
|
+
executor(
|
|
569
|
+
_G,
|
|
570
|
+
__TS__FunctionBind(self.resolve, self),
|
|
571
|
+
__TS__FunctionBind(self.reject, self)
|
|
572
|
+
)
|
|
573
|
+
end)
|
|
574
|
+
if not ____try then
|
|
575
|
+
____catch(____hasReturned)
|
|
576
|
+
end
|
|
577
|
+
end
|
|
578
|
+
end
|
|
579
|
+
function __TS__Promise.resolve(data)
|
|
580
|
+
local promise = __TS__New(
|
|
581
|
+
__TS__Promise,
|
|
582
|
+
function()
|
|
583
|
+
end
|
|
584
|
+
)
|
|
585
|
+
promise.state = __TS__PromiseState.Fulfilled
|
|
586
|
+
promise.value = data
|
|
587
|
+
return promise
|
|
588
|
+
end
|
|
589
|
+
function __TS__Promise.reject(reason)
|
|
590
|
+
local promise = __TS__New(
|
|
591
|
+
__TS__Promise,
|
|
592
|
+
function()
|
|
593
|
+
end
|
|
594
|
+
)
|
|
595
|
+
promise.state = __TS__PromiseState.Rejected
|
|
596
|
+
promise.rejectionReason = reason
|
|
597
|
+
return promise
|
|
598
|
+
end
|
|
599
|
+
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
600
|
+
local ____TS__PromiseDeferred_result_0 = __TS__PromiseDeferred(_G)
|
|
601
|
+
local promise = ____TS__PromiseDeferred_result_0.promise
|
|
602
|
+
local resolve = ____TS__PromiseDeferred_result_0.resolve
|
|
603
|
+
local reject = ____TS__PromiseDeferred_result_0.reject
|
|
604
|
+
local isFulfilled = self.state == __TS__PromiseState.Fulfilled
|
|
605
|
+
local isRejected = self.state == __TS__PromiseState.Rejected
|
|
606
|
+
if onFulfilled then
|
|
607
|
+
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
608
|
+
__TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
|
|
609
|
+
if isFulfilled then
|
|
610
|
+
internalCallback(_G, self.value)
|
|
611
|
+
end
|
|
612
|
+
else
|
|
613
|
+
__TS__ArrayPush(
|
|
614
|
+
self.fulfilledCallbacks,
|
|
615
|
+
function() return resolve(_G, nil) end
|
|
616
|
+
)
|
|
617
|
+
end
|
|
618
|
+
if onRejected then
|
|
619
|
+
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
620
|
+
__TS__ArrayPush(self.rejectedCallbacks, internalCallback)
|
|
621
|
+
if isRejected then
|
|
622
|
+
internalCallback(_G, self.rejectionReason)
|
|
623
|
+
end
|
|
624
|
+
end
|
|
625
|
+
if isFulfilled then
|
|
626
|
+
resolve(_G, self.value)
|
|
627
|
+
end
|
|
628
|
+
if isRejected then
|
|
629
|
+
reject(_G, self.rejectionReason)
|
|
630
|
+
end
|
|
631
|
+
return promise
|
|
632
|
+
end
|
|
633
|
+
function __TS__Promise.prototype.catch(self, onRejected)
|
|
634
|
+
return self["then"](self, nil, onRejected)
|
|
635
|
+
end
|
|
636
|
+
function __TS__Promise.prototype.finally(self, onFinally)
|
|
637
|
+
if onFinally then
|
|
638
|
+
__TS__ArrayPush(self.finallyCallbacks, onFinally)
|
|
639
|
+
if self.state ~= __TS__PromiseState.Pending then
|
|
640
|
+
onFinally(_G)
|
|
641
|
+
end
|
|
642
|
+
end
|
|
643
|
+
return self
|
|
644
|
+
end
|
|
645
|
+
function __TS__Promise.prototype.resolve(self, data)
|
|
646
|
+
if __TS__InstanceOf(data, __TS__Promise) then
|
|
647
|
+
data["then"](
|
|
648
|
+
data,
|
|
649
|
+
function(____, v) return self:resolve(v) end,
|
|
650
|
+
function(____, err) return self:reject(err) end
|
|
651
|
+
)
|
|
652
|
+
return
|
|
653
|
+
end
|
|
654
|
+
if self.state == __TS__PromiseState.Pending then
|
|
655
|
+
self.state = __TS__PromiseState.Fulfilled
|
|
656
|
+
self.value = data
|
|
657
|
+
for ____, callback in ipairs(self.fulfilledCallbacks) do
|
|
658
|
+
callback(_G, data)
|
|
659
|
+
end
|
|
660
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
661
|
+
callback(_G)
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
end
|
|
665
|
+
function __TS__Promise.prototype.reject(self, reason)
|
|
666
|
+
if self.state == __TS__PromiseState.Pending then
|
|
667
|
+
self.state = __TS__PromiseState.Rejected
|
|
668
|
+
self.rejectionReason = reason
|
|
669
|
+
for ____, callback in ipairs(self.rejectedCallbacks) do
|
|
670
|
+
callback(_G, reason)
|
|
671
|
+
end
|
|
672
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
673
|
+
callback(_G)
|
|
674
|
+
end
|
|
675
|
+
end
|
|
676
|
+
end
|
|
677
|
+
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
678
|
+
return function(____, value)
|
|
679
|
+
do
|
|
680
|
+
local function ____catch(e)
|
|
681
|
+
reject(_G, e)
|
|
682
|
+
end
|
|
683
|
+
local ____try, ____hasReturned = pcall(function()
|
|
684
|
+
self:handleCallbackData(
|
|
685
|
+
f(_G, value),
|
|
686
|
+
resolve,
|
|
687
|
+
reject
|
|
688
|
+
)
|
|
689
|
+
end)
|
|
690
|
+
if not ____try then
|
|
691
|
+
____catch(____hasReturned)
|
|
692
|
+
end
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
|
|
697
|
+
if __TS__IsPromiseLike(_G, data) then
|
|
698
|
+
local nextpromise = data
|
|
699
|
+
if nextpromise.state == __TS__PromiseState.Fulfilled then
|
|
700
|
+
resolve(_G, nextpromise.value)
|
|
701
|
+
elseif nextpromise.state == __TS__PromiseState.Rejected then
|
|
702
|
+
reject(_G, nextpromise.rejectionReason)
|
|
703
|
+
else
|
|
704
|
+
data["then"](data, resolve, reject)
|
|
705
|
+
end
|
|
706
|
+
else
|
|
707
|
+
resolve(_G, data)
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
|
|
497
711
|
function __TS__AsyncAwaiter(generator)
|
|
498
712
|
return __TS__New(
|
|
499
713
|
__TS__Promise,
|
|
500
714
|
function(____, resolve, reject)
|
|
501
|
-
local
|
|
715
|
+
local adopt, fulfilled, rejected, step, asyncCoroutine
|
|
502
716
|
function adopt(self, value)
|
|
503
|
-
|
|
717
|
+
local ____temp_0
|
|
718
|
+
if __TS__InstanceOf(value, __TS__Promise) then
|
|
719
|
+
____temp_0 = value
|
|
720
|
+
else
|
|
721
|
+
____temp_0 = __TS__Promise.resolve(value)
|
|
722
|
+
end
|
|
723
|
+
return ____temp_0
|
|
504
724
|
end
|
|
505
725
|
function fulfilled(self, value)
|
|
506
|
-
local success, resultOrError = coroutine.resume(asyncCoroutine, value)
|
|
726
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
|
|
507
727
|
if success then
|
|
508
|
-
step(_G, resultOrError)
|
|
728
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
729
|
+
else
|
|
730
|
+
reject(_G, errorOrErrorHandler)
|
|
731
|
+
end
|
|
732
|
+
end
|
|
733
|
+
function rejected(self, handler)
|
|
734
|
+
if handler then
|
|
735
|
+
return function(____, value)
|
|
736
|
+
local success, hasReturnedOrError, returnedValue = pcall(handler, value)
|
|
737
|
+
if success then
|
|
738
|
+
if hasReturnedOrError then
|
|
739
|
+
resolve(_G, returnedValue)
|
|
740
|
+
else
|
|
741
|
+
step(_G, hasReturnedOrError, handler)
|
|
742
|
+
end
|
|
743
|
+
else
|
|
744
|
+
reject(_G, hasReturnedOrError)
|
|
745
|
+
end
|
|
746
|
+
end
|
|
509
747
|
else
|
|
510
|
-
|
|
748
|
+
return function(____, value)
|
|
749
|
+
reject(_G, value)
|
|
750
|
+
end
|
|
511
751
|
end
|
|
512
752
|
end
|
|
513
|
-
function step(self, result)
|
|
753
|
+
function step(self, result, errorHandler)
|
|
514
754
|
if coroutine.status(asyncCoroutine) == "dead" then
|
|
515
755
|
resolve(_G, result)
|
|
516
756
|
else
|
|
517
|
-
(
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
)
|
|
524
|
-
end)()
|
|
757
|
+
local ____self_1 = adopt(_G, result)
|
|
758
|
+
____self_1["then"](
|
|
759
|
+
____self_1,
|
|
760
|
+
fulfilled,
|
|
761
|
+
rejected(_G, errorHandler)
|
|
762
|
+
)
|
|
525
763
|
end
|
|
526
764
|
end
|
|
527
765
|
asyncCoroutine = coroutine.create(generator)
|
|
528
|
-
local success, resultOrError = coroutine.resume(asyncCoroutine)
|
|
766
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
|
|
529
767
|
if success then
|
|
530
|
-
step(_G, resultOrError)
|
|
768
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
531
769
|
else
|
|
532
|
-
reject(_G,
|
|
770
|
+
reject(_G, errorOrErrorHandler)
|
|
533
771
|
end
|
|
534
772
|
end
|
|
535
773
|
)
|
|
536
774
|
end
|
|
537
|
-
function __TS__Await(thing)
|
|
538
|
-
return coroutine.yield(thing)
|
|
539
|
-
end
|
|
540
|
-
|
|
541
|
-
function __TS__Class(self)
|
|
542
|
-
local c = {prototype = {}}
|
|
543
|
-
c.prototype.__index = c.prototype
|
|
544
|
-
c.prototype.constructor = c
|
|
545
|
-
return c
|
|
775
|
+
function __TS__Await(errorHandler, thing)
|
|
776
|
+
return coroutine.yield(errorHandler, thing)
|
|
546
777
|
end
|
|
547
778
|
|
|
548
779
|
function __TS__ClassExtends(target, base)
|
|
@@ -571,21 +802,21 @@ function __TS__ClassExtends(target, base)
|
|
|
571
802
|
end
|
|
572
803
|
|
|
573
804
|
function __TS__CloneDescriptor(____bindingPattern0)
|
|
805
|
+
local value
|
|
806
|
+
local writable
|
|
807
|
+
local set
|
|
808
|
+
local get
|
|
809
|
+
local configurable
|
|
574
810
|
local enumerable
|
|
575
811
|
enumerable = ____bindingPattern0.enumerable
|
|
576
|
-
local configurable
|
|
577
812
|
configurable = ____bindingPattern0.configurable
|
|
578
|
-
local get
|
|
579
813
|
get = ____bindingPattern0.get
|
|
580
|
-
local set
|
|
581
814
|
set = ____bindingPattern0.set
|
|
582
|
-
local writable
|
|
583
815
|
writable = ____bindingPattern0.writable
|
|
584
|
-
local value
|
|
585
816
|
value = ____bindingPattern0.value
|
|
586
817
|
local descriptor = {enumerable = enumerable == true, configurable = configurable == true}
|
|
587
|
-
local hasGetterOrSetter =
|
|
588
|
-
local hasValueOrWritableAttribute =
|
|
818
|
+
local hasGetterOrSetter = get ~= nil or set ~= nil
|
|
819
|
+
local hasValueOrWritableAttribute = writable ~= nil or value ~= nil
|
|
589
820
|
if hasGetterOrSetter and hasValueOrWritableAttribute then
|
|
590
821
|
error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.", 0)
|
|
591
822
|
end
|
|
@@ -663,7 +894,13 @@ function __TS__SetDescriptor(target, key, desc, isPrototype)
|
|
|
663
894
|
if isPrototype == nil then
|
|
664
895
|
isPrototype = false
|
|
665
896
|
end
|
|
666
|
-
local
|
|
897
|
+
local ____isPrototype_0
|
|
898
|
+
if isPrototype then
|
|
899
|
+
____isPrototype_0 = target
|
|
900
|
+
else
|
|
901
|
+
____isPrototype_0 = getmetatable(target)
|
|
902
|
+
end
|
|
903
|
+
local metatable = ____isPrototype_0
|
|
667
904
|
if not metatable then
|
|
668
905
|
metatable = {}
|
|
669
906
|
setmetatable(target, metatable)
|
|
@@ -708,7 +945,7 @@ function __TS__Decorate(decorators, target, key, desc)
|
|
|
708
945
|
local value = rawget(target, key)
|
|
709
946
|
local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
|
|
710
947
|
local desc = decorator(_G, target, key, descriptor) or descriptor
|
|
711
|
-
local isSimpleValue =
|
|
948
|
+
local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
|
|
712
949
|
if isSimpleValue then
|
|
713
950
|
rawset(target, key, desc.value)
|
|
714
951
|
else
|
|
@@ -743,28 +980,107 @@ function __TS__ObjectGetOwnPropertyDescriptors(object)
|
|
|
743
980
|
return rawget(metatable, "_descriptors") or ({})
|
|
744
981
|
end
|
|
745
982
|
|
|
983
|
+
function __TS__GetErrorStack(self, constructor)
|
|
984
|
+
local level = 1
|
|
985
|
+
while true do
|
|
986
|
+
local info = debug.getinfo(level, "f")
|
|
987
|
+
level = level + 1
|
|
988
|
+
if not info then
|
|
989
|
+
level = 1
|
|
990
|
+
break
|
|
991
|
+
elseif info.func == constructor then
|
|
992
|
+
break
|
|
993
|
+
end
|
|
994
|
+
end
|
|
995
|
+
return debug.traceback(nil, level)
|
|
996
|
+
end
|
|
997
|
+
function __TS__WrapErrorToString(self, getDescription)
|
|
998
|
+
return function(self)
|
|
999
|
+
local description = getDescription(self)
|
|
1000
|
+
local caller = debug.getinfo(3, "f")
|
|
1001
|
+
if _VERSION == "Lua 5.1" or caller and caller.func ~= error then
|
|
1002
|
+
return description
|
|
1003
|
+
else
|
|
1004
|
+
return (tostring(description) .. "\n") .. self.stack
|
|
1005
|
+
end
|
|
1006
|
+
end
|
|
1007
|
+
end
|
|
1008
|
+
function __TS__InitErrorClass(self, Type, name)
|
|
1009
|
+
Type.name = name
|
|
1010
|
+
return setmetatable(
|
|
1011
|
+
Type,
|
|
1012
|
+
{__call = function(____, _self, message) return __TS__New(Type, message) end}
|
|
1013
|
+
)
|
|
1014
|
+
end
|
|
1015
|
+
local ____TS__InitErrorClass_3 = __TS__InitErrorClass
|
|
1016
|
+
local ____G_2 = _G
|
|
1017
|
+
____class_0 = __TS__Class()
|
|
1018
|
+
____class_0.name = ""
|
|
1019
|
+
function ____class_0.prototype.____constructor(self, message)
|
|
1020
|
+
if message == nil then
|
|
1021
|
+
message = ""
|
|
1022
|
+
end
|
|
1023
|
+
self.message = message
|
|
1024
|
+
self.name = "Error"
|
|
1025
|
+
self.stack = __TS__GetErrorStack(_G, self.constructor.new)
|
|
1026
|
+
local metatable = getmetatable(self)
|
|
1027
|
+
if not metatable.__errorToStringPatched then
|
|
1028
|
+
metatable.__errorToStringPatched = true
|
|
1029
|
+
metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
|
|
1030
|
+
end
|
|
1031
|
+
end
|
|
1032
|
+
function ____class_0.prototype.__tostring(self)
|
|
1033
|
+
local ____temp_1
|
|
1034
|
+
if self.message ~= "" then
|
|
1035
|
+
____temp_1 = (self.name .. ": ") .. self.message
|
|
1036
|
+
else
|
|
1037
|
+
____temp_1 = self.name
|
|
1038
|
+
end
|
|
1039
|
+
return ____temp_1
|
|
1040
|
+
end
|
|
1041
|
+
Error = ____TS__InitErrorClass_3(____G_2, ____class_0, "Error")
|
|
1042
|
+
for ____, errorName in ipairs({
|
|
1043
|
+
"RangeError",
|
|
1044
|
+
"ReferenceError",
|
|
1045
|
+
"SyntaxError",
|
|
1046
|
+
"TypeError",
|
|
1047
|
+
"URIError"
|
|
1048
|
+
}) do
|
|
1049
|
+
local ____G_7 = _G
|
|
1050
|
+
local ____TS__InitErrorClass_6 = __TS__InitErrorClass
|
|
1051
|
+
local ____G_5 = _G
|
|
1052
|
+
local ____class_4 = __TS__Class()
|
|
1053
|
+
____class_4.name = ____class_4.name
|
|
1054
|
+
__TS__ClassExtends(____class_4, Error)
|
|
1055
|
+
function ____class_4.prototype.____constructor(self, ...)
|
|
1056
|
+
Error.prototype.____constructor(self, ...)
|
|
1057
|
+
self.name = errorName
|
|
1058
|
+
end
|
|
1059
|
+
____G_7[errorName] = ____TS__InitErrorClass_6(____G_5, ____class_4, errorName)
|
|
1060
|
+
end
|
|
1061
|
+
|
|
746
1062
|
function __TS__Delete(target, key)
|
|
747
1063
|
local descriptors = __TS__ObjectGetOwnPropertyDescriptors(target)
|
|
748
1064
|
local descriptor = descriptors[key]
|
|
749
1065
|
if descriptor then
|
|
750
1066
|
if not descriptor.configurable then
|
|
751
1067
|
error(
|
|
752
|
-
(
|
|
1068
|
+
__TS__New(
|
|
1069
|
+
TypeError,
|
|
1070
|
+
((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. "."
|
|
1071
|
+
),
|
|
753
1072
|
0
|
|
754
1073
|
)
|
|
755
1074
|
end
|
|
756
1075
|
descriptors[key] = nil
|
|
757
1076
|
return true
|
|
758
1077
|
end
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return true
|
|
762
|
-
end
|
|
763
|
-
return false
|
|
1078
|
+
target[key] = nil
|
|
1079
|
+
return true
|
|
764
1080
|
end
|
|
765
1081
|
|
|
766
1082
|
function __TS__StringAccess(self, index)
|
|
767
|
-
if
|
|
1083
|
+
if index >= 0 and index < #self then
|
|
768
1084
|
return string.sub(self, index + 1, index + 1)
|
|
769
1085
|
end
|
|
770
1086
|
end
|
|
@@ -772,9 +1088,7 @@ end
|
|
|
772
1088
|
function __TS__DelegatedYield(iterable)
|
|
773
1089
|
if type(iterable) == "string" then
|
|
774
1090
|
for index = 0, #iterable - 1 do
|
|
775
|
-
coroutine.yield(
|
|
776
|
-
__TS__StringAccess(iterable, index)
|
|
777
|
-
)
|
|
1091
|
+
coroutine.yield(__TS__StringAccess(iterable, index))
|
|
778
1092
|
end
|
|
779
1093
|
elseif iterable.____coroutine ~= nil then
|
|
780
1094
|
local co = iterable.____coroutine
|
|
@@ -806,102 +1120,6 @@ function __TS__DelegatedYield(iterable)
|
|
|
806
1120
|
end
|
|
807
1121
|
end
|
|
808
1122
|
|
|
809
|
-
function __TS__GetErrorStack(self, constructor)
|
|
810
|
-
local level = 1
|
|
811
|
-
while true do
|
|
812
|
-
local info = debug.getinfo(level, "f")
|
|
813
|
-
level = level + 1
|
|
814
|
-
if not info then
|
|
815
|
-
level = 1
|
|
816
|
-
break
|
|
817
|
-
elseif info.func == constructor then
|
|
818
|
-
break
|
|
819
|
-
end
|
|
820
|
-
end
|
|
821
|
-
return debug.traceback(nil, level)
|
|
822
|
-
end
|
|
823
|
-
function __TS__WrapErrorToString(self, getDescription)
|
|
824
|
-
return function(self)
|
|
825
|
-
local description = getDescription(self)
|
|
826
|
-
local caller = debug.getinfo(3, "f")
|
|
827
|
-
if (_VERSION == "Lua 5.1") or (caller and (caller.func ~= error)) then
|
|
828
|
-
return description
|
|
829
|
-
else
|
|
830
|
-
return (tostring(description) .. "\n") .. self.stack
|
|
831
|
-
end
|
|
832
|
-
end
|
|
833
|
-
end
|
|
834
|
-
function __TS__InitErrorClass(self, Type, name)
|
|
835
|
-
Type.name = name
|
|
836
|
-
return setmetatable(
|
|
837
|
-
Type,
|
|
838
|
-
{
|
|
839
|
-
__call = function(____, _self, message) return __TS__New(Type, message) end
|
|
840
|
-
}
|
|
841
|
-
)
|
|
842
|
-
end
|
|
843
|
-
Error = __TS__InitErrorClass(
|
|
844
|
-
_G,
|
|
845
|
-
(function()
|
|
846
|
-
local ____ = __TS__Class()
|
|
847
|
-
____.name = ""
|
|
848
|
-
function ____.prototype.____constructor(self, message)
|
|
849
|
-
if message == nil then
|
|
850
|
-
message = ""
|
|
851
|
-
end
|
|
852
|
-
self.message = message
|
|
853
|
-
self.name = "Error"
|
|
854
|
-
self.stack = __TS__GetErrorStack(_G, self.constructor.new)
|
|
855
|
-
local metatable = getmetatable(self)
|
|
856
|
-
if not metatable.__errorToStringPatched then
|
|
857
|
-
metatable.__errorToStringPatched = true
|
|
858
|
-
metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
|
|
859
|
-
end
|
|
860
|
-
end
|
|
861
|
-
function ____.prototype.__tostring(self)
|
|
862
|
-
return (((self.message ~= "") and (function() return (self.name .. ": ") .. self.message end)) or (function() return self.name end))()
|
|
863
|
-
end
|
|
864
|
-
return ____
|
|
865
|
-
end)(),
|
|
866
|
-
"Error"
|
|
867
|
-
)
|
|
868
|
-
for ____, errorName in ipairs({"RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"}) do
|
|
869
|
-
_G[errorName] = __TS__InitErrorClass(
|
|
870
|
-
_G,
|
|
871
|
-
(function()
|
|
872
|
-
local ____ = __TS__Class()
|
|
873
|
-
____.name = ____.name
|
|
874
|
-
__TS__ClassExtends(____, Error)
|
|
875
|
-
function ____.prototype.____constructor(self, ...)
|
|
876
|
-
Error.prototype.____constructor(self, ...)
|
|
877
|
-
self.name = errorName
|
|
878
|
-
end
|
|
879
|
-
return ____
|
|
880
|
-
end)(),
|
|
881
|
-
errorName
|
|
882
|
-
)
|
|
883
|
-
end
|
|
884
|
-
|
|
885
|
-
__TS__Unpack = table.unpack or unpack
|
|
886
|
-
|
|
887
|
-
function __TS__FunctionBind(fn, thisArg, ...)
|
|
888
|
-
local boundArgs = {...}
|
|
889
|
-
return function(____, ...)
|
|
890
|
-
local args = {...}
|
|
891
|
-
do
|
|
892
|
-
local i = 0
|
|
893
|
-
while i < #boundArgs do
|
|
894
|
-
table.insert(args, i + 1, boundArgs[i + 1])
|
|
895
|
-
i = i + 1
|
|
896
|
-
end
|
|
897
|
-
end
|
|
898
|
-
return fn(
|
|
899
|
-
thisArg,
|
|
900
|
-
__TS__Unpack(args)
|
|
901
|
-
)
|
|
902
|
-
end
|
|
903
|
-
end
|
|
904
|
-
|
|
905
1123
|
function __TS__GeneratorIterator(self)
|
|
906
1124
|
return self
|
|
907
1125
|
end
|
|
@@ -924,11 +1142,7 @@ function __TS__Generator(fn)
|
|
|
924
1142
|
local args = {...}
|
|
925
1143
|
local argsLength = select("#", ...)
|
|
926
1144
|
return {
|
|
927
|
-
____coroutine = coroutine.create(
|
|
928
|
-
function() return fn(
|
|
929
|
-
(unpack or table.unpack)(args, 1, argsLength)
|
|
930
|
-
) end
|
|
931
|
-
),
|
|
1145
|
+
____coroutine = coroutine.create(function() return fn((unpack or table.unpack)(args, 1, argsLength)) end),
|
|
932
1146
|
[Symbol.iterator] = __TS__GeneratorIterator,
|
|
933
1147
|
next = __TS__GeneratorNext
|
|
934
1148
|
}
|
|
@@ -937,7 +1151,7 @@ end
|
|
|
937
1151
|
|
|
938
1152
|
function __TS__InstanceOfObject(value)
|
|
939
1153
|
local valueType = type(value)
|
|
940
|
-
return
|
|
1154
|
+
return valueType == "table" or valueType == "function"
|
|
941
1155
|
end
|
|
942
1156
|
|
|
943
1157
|
function __TS__IteratorGeneratorStep(self)
|
|
@@ -978,150 +1192,146 @@ function __TS__Iterator(iterable)
|
|
|
978
1192
|
end
|
|
979
1193
|
end
|
|
980
1194
|
|
|
981
|
-
Map = (
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
return
|
|
992
|
-
end
|
|
993
|
-
local iterable = entries
|
|
994
|
-
if iterable[Symbol.iterator] then
|
|
995
|
-
local iterator = iterable[Symbol.iterator](iterable)
|
|
996
|
-
while true do
|
|
997
|
-
local result = iterator:next()
|
|
998
|
-
if result.done then
|
|
999
|
-
break
|
|
1000
|
-
end
|
|
1001
|
-
local value = result.value
|
|
1002
|
-
self:set(value[1], value[2])
|
|
1003
|
-
end
|
|
1004
|
-
else
|
|
1005
|
-
local array = entries
|
|
1006
|
-
for ____, kvp in ipairs(array) do
|
|
1007
|
-
self:set(kvp[1], kvp[2])
|
|
1008
|
-
end
|
|
1009
|
-
end
|
|
1195
|
+
Map = __TS__Class()
|
|
1196
|
+
Map.name = "Map"
|
|
1197
|
+
function Map.prototype.____constructor(self, entries)
|
|
1198
|
+
self[Symbol.toStringTag] = "Map"
|
|
1199
|
+
self.items = {}
|
|
1200
|
+
self.size = 0
|
|
1201
|
+
self.nextKey = {}
|
|
1202
|
+
self.previousKey = {}
|
|
1203
|
+
if entries == nil then
|
|
1204
|
+
return
|
|
1010
1205
|
end
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
end
|
|
1019
|
-
function Map.prototype.delete(self, key)
|
|
1020
|
-
local contains = self:has(key)
|
|
1021
|
-
if contains then
|
|
1022
|
-
self.size = self.size - 1
|
|
1023
|
-
local next = self.nextKey[key]
|
|
1024
|
-
local previous = self.previousKey[key]
|
|
1025
|
-
if next and previous then
|
|
1026
|
-
self.nextKey[previous] = next
|
|
1027
|
-
self.previousKey[next] = previous
|
|
1028
|
-
elseif next then
|
|
1029
|
-
self.firstKey = next
|
|
1030
|
-
self.previousKey[next] = nil
|
|
1031
|
-
elseif previous then
|
|
1032
|
-
self.lastKey = previous
|
|
1033
|
-
self.nextKey[previous] = nil
|
|
1034
|
-
else
|
|
1035
|
-
self.firstKey = nil
|
|
1036
|
-
self.lastKey = nil
|
|
1206
|
+
local iterable = entries
|
|
1207
|
+
if iterable[Symbol.iterator] then
|
|
1208
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
1209
|
+
while true do
|
|
1210
|
+
local result = iterator:next()
|
|
1211
|
+
if result.done then
|
|
1212
|
+
break
|
|
1037
1213
|
end
|
|
1038
|
-
|
|
1039
|
-
self
|
|
1214
|
+
local value = result.value
|
|
1215
|
+
self:set(value[1], value[2])
|
|
1040
1216
|
end
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1217
|
+
else
|
|
1218
|
+
local array = entries
|
|
1219
|
+
for ____, kvp in ipairs(array) do
|
|
1220
|
+
self:set(kvp[1], kvp[2])
|
|
1221
|
+
end
|
|
1222
|
+
end
|
|
1223
|
+
end
|
|
1224
|
+
function Map.prototype.clear(self)
|
|
1225
|
+
self.items = {}
|
|
1226
|
+
self.nextKey = {}
|
|
1227
|
+
self.previousKey = {}
|
|
1228
|
+
self.firstKey = nil
|
|
1229
|
+
self.lastKey = nil
|
|
1230
|
+
self.size = 0
|
|
1231
|
+
end
|
|
1232
|
+
function Map.prototype.delete(self, key)
|
|
1233
|
+
local contains = self:has(key)
|
|
1234
|
+
if contains then
|
|
1235
|
+
self.size = self.size - 1
|
|
1236
|
+
local next = self.nextKey[key]
|
|
1237
|
+
local previous = self.previousKey[key]
|
|
1238
|
+
if next and previous then
|
|
1239
|
+
self.nextKey[previous] = next
|
|
1240
|
+
self.previousKey[next] = previous
|
|
1241
|
+
elseif next then
|
|
1242
|
+
self.firstKey = next
|
|
1243
|
+
self.previousKey[next] = nil
|
|
1244
|
+
elseif previous then
|
|
1245
|
+
self.lastKey = previous
|
|
1246
|
+
self.nextKey[previous] = nil
|
|
1247
|
+
else
|
|
1248
|
+
self.firstKey = nil
|
|
1249
|
+
self.lastKey = nil
|
|
1049
1250
|
end
|
|
1251
|
+
self.nextKey[key] = nil
|
|
1252
|
+
self.previousKey[key] = nil
|
|
1050
1253
|
end
|
|
1051
|
-
|
|
1052
|
-
|
|
1254
|
+
self.items[key] = nil
|
|
1255
|
+
return contains
|
|
1256
|
+
end
|
|
1257
|
+
function Map.prototype.forEach(self, callback)
|
|
1258
|
+
for ____, key in __TS__Iterator(self:keys()) do
|
|
1259
|
+
callback(_G, self.items[key], key, self)
|
|
1053
1260
|
end
|
|
1054
|
-
|
|
1055
|
-
|
|
1261
|
+
end
|
|
1262
|
+
function Map.prototype.get(self, key)
|
|
1263
|
+
return self.items[key]
|
|
1264
|
+
end
|
|
1265
|
+
function Map.prototype.has(self, key)
|
|
1266
|
+
return self.nextKey[key] ~= nil or self.lastKey == key
|
|
1267
|
+
end
|
|
1268
|
+
function Map.prototype.set(self, key, value)
|
|
1269
|
+
local isNewValue = not self:has(key)
|
|
1270
|
+
if isNewValue then
|
|
1271
|
+
self.size = self.size + 1
|
|
1056
1272
|
end
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1273
|
+
self.items[key] = value
|
|
1274
|
+
if self.firstKey == nil then
|
|
1275
|
+
self.firstKey = key
|
|
1276
|
+
self.lastKey = key
|
|
1277
|
+
elseif isNewValue then
|
|
1278
|
+
self.nextKey[self.lastKey] = key
|
|
1279
|
+
self.previousKey[key] = self.lastKey
|
|
1280
|
+
self.lastKey = key
|
|
1281
|
+
end
|
|
1282
|
+
return self
|
|
1283
|
+
end
|
|
1284
|
+
Map.prototype[Symbol.iterator] = function(self)
|
|
1285
|
+
return self:entries()
|
|
1286
|
+
end
|
|
1287
|
+
function Map.prototype.entries(self)
|
|
1288
|
+
local ____temp_0 = self
|
|
1289
|
+
local items = ____temp_0.items
|
|
1290
|
+
local nextKey = ____temp_0.nextKey
|
|
1291
|
+
local key = self.firstKey
|
|
1292
|
+
return {
|
|
1293
|
+
[Symbol.iterator] = function(self)
|
|
1294
|
+
return self
|
|
1295
|
+
end,
|
|
1296
|
+
next = function(self)
|
|
1297
|
+
local result = {done = not key, value = {key, items[key]}}
|
|
1298
|
+
key = nextKey[key]
|
|
1299
|
+
return result
|
|
1061
1300
|
end
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
self
|
|
1301
|
+
}
|
|
1302
|
+
end
|
|
1303
|
+
function Map.prototype.keys(self)
|
|
1304
|
+
local nextKey = self.nextKey
|
|
1305
|
+
local key = self.firstKey
|
|
1306
|
+
return {
|
|
1307
|
+
[Symbol.iterator] = function(self)
|
|
1308
|
+
return self
|
|
1309
|
+
end,
|
|
1310
|
+
next = function(self)
|
|
1311
|
+
local result = {done = not key, value = key}
|
|
1312
|
+
key = nextKey[key]
|
|
1313
|
+
return result
|
|
1070
1314
|
end
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
end
|
|
1092
|
-
function Map.prototype.keys(self)
|
|
1093
|
-
local nextKey = self.nextKey
|
|
1094
|
-
local key = self.firstKey
|
|
1095
|
-
return {
|
|
1096
|
-
[Symbol.iterator] = function(self)
|
|
1097
|
-
return self
|
|
1098
|
-
end,
|
|
1099
|
-
next = function(self)
|
|
1100
|
-
local result = {done = not key, value = key}
|
|
1101
|
-
key = nextKey[key]
|
|
1102
|
-
return result
|
|
1103
|
-
end
|
|
1104
|
-
}
|
|
1105
|
-
end
|
|
1106
|
-
function Map.prototype.values(self)
|
|
1107
|
-
local ____ = self
|
|
1108
|
-
local items = ____.items
|
|
1109
|
-
local nextKey = ____.nextKey
|
|
1110
|
-
local key = self.firstKey
|
|
1111
|
-
return {
|
|
1112
|
-
[Symbol.iterator] = function(self)
|
|
1113
|
-
return self
|
|
1114
|
-
end,
|
|
1115
|
-
next = function(self)
|
|
1116
|
-
local result = {done = not key, value = items[key]}
|
|
1117
|
-
key = nextKey[key]
|
|
1118
|
-
return result
|
|
1119
|
-
end
|
|
1120
|
-
}
|
|
1121
|
-
end
|
|
1122
|
-
Map[Symbol.species] = Map
|
|
1123
|
-
return Map
|
|
1124
|
-
end)()
|
|
1315
|
+
}
|
|
1316
|
+
end
|
|
1317
|
+
function Map.prototype.values(self)
|
|
1318
|
+
local ____temp_1 = self
|
|
1319
|
+
local items = ____temp_1.items
|
|
1320
|
+
local nextKey = ____temp_1.nextKey
|
|
1321
|
+
local key = self.firstKey
|
|
1322
|
+
return {
|
|
1323
|
+
[Symbol.iterator] = function(self)
|
|
1324
|
+
return self
|
|
1325
|
+
end,
|
|
1326
|
+
next = function(self)
|
|
1327
|
+
local result = {done = not key, value = items[key]}
|
|
1328
|
+
key = nextKey[key]
|
|
1329
|
+
return result
|
|
1330
|
+
end
|
|
1331
|
+
}
|
|
1332
|
+
end
|
|
1333
|
+
Map[Symbol.species] = Map
|
|
1334
|
+
Map = Map
|
|
1125
1335
|
|
|
1126
1336
|
__TS__MathAtan2 = math.atan2 or math.atan
|
|
1127
1337
|
|
|
@@ -1146,14 +1356,14 @@ function __TS__Number(value)
|
|
|
1146
1356
|
end
|
|
1147
1357
|
return 0 / 0
|
|
1148
1358
|
elseif valueType == "boolean" then
|
|
1149
|
-
return
|
|
1359
|
+
return value and 1 or 0
|
|
1150
1360
|
else
|
|
1151
1361
|
return 0 / 0
|
|
1152
1362
|
end
|
|
1153
1363
|
end
|
|
1154
1364
|
|
|
1155
1365
|
function __TS__NumberIsFinite(value)
|
|
1156
|
-
return
|
|
1366
|
+
return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
|
|
1157
1367
|
end
|
|
1158
1368
|
|
|
1159
1369
|
function __TS__NumberIsNaN(value)
|
|
@@ -1162,16 +1372,14 @@ end
|
|
|
1162
1372
|
|
|
1163
1373
|
____radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
1164
1374
|
function __TS__NumberToString(self, radix)
|
|
1165
|
-
if
|
|
1375
|
+
if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
|
|
1166
1376
|
return tostring(self)
|
|
1167
1377
|
end
|
|
1168
1378
|
radix = math.floor(radix)
|
|
1169
|
-
if
|
|
1379
|
+
if radix < 2 or radix > 36 then
|
|
1170
1380
|
error("toString() radix argument must be between 2 and 36", 0)
|
|
1171
1381
|
end
|
|
1172
|
-
local integer, fraction = math.modf(
|
|
1173
|
-
math.abs(self)
|
|
1174
|
-
)
|
|
1382
|
+
local integer, fraction = math.modf(math.abs(self))
|
|
1175
1383
|
local result = ""
|
|
1176
1384
|
if radix == 8 then
|
|
1177
1385
|
result = string.format("%o", integer)
|
|
@@ -1205,9 +1413,15 @@ function __TS__NumberToString(self, radix)
|
|
|
1205
1413
|
end
|
|
1206
1414
|
|
|
1207
1415
|
function __TS__ObjectDefineProperty(target, key, desc)
|
|
1208
|
-
local
|
|
1416
|
+
local ____temp_0
|
|
1417
|
+
if type(key) == "number" then
|
|
1418
|
+
____temp_0 = key + 1
|
|
1419
|
+
else
|
|
1420
|
+
____temp_0 = key
|
|
1421
|
+
end
|
|
1422
|
+
local luaKey = ____temp_0
|
|
1209
1423
|
local value = rawget(target, luaKey)
|
|
1210
|
-
local hasGetterOrSetter =
|
|
1424
|
+
local hasGetterOrSetter = desc.get ~= nil or desc.set ~= nil
|
|
1211
1425
|
local descriptor
|
|
1212
1426
|
if hasGetterOrSetter then
|
|
1213
1427
|
if value ~= nil then
|
|
@@ -1219,13 +1433,39 @@ function __TS__ObjectDefineProperty(target, key, desc)
|
|
|
1219
1433
|
descriptor = desc
|
|
1220
1434
|
else
|
|
1221
1435
|
local valueExists = value ~= nil
|
|
1436
|
+
local ____desc_set_5 = desc.set
|
|
1437
|
+
local ____desc_get_6 = desc.get
|
|
1438
|
+
local ____temp_1
|
|
1439
|
+
if desc.configurable ~= nil then
|
|
1440
|
+
____temp_1 = desc.configurable
|
|
1441
|
+
else
|
|
1442
|
+
____temp_1 = valueExists
|
|
1443
|
+
end
|
|
1444
|
+
local ____temp_2
|
|
1445
|
+
if desc.enumerable ~= nil then
|
|
1446
|
+
____temp_2 = desc.enumerable
|
|
1447
|
+
else
|
|
1448
|
+
____temp_2 = valueExists
|
|
1449
|
+
end
|
|
1450
|
+
local ____temp_3
|
|
1451
|
+
if desc.writable ~= nil then
|
|
1452
|
+
____temp_3 = desc.writable
|
|
1453
|
+
else
|
|
1454
|
+
____temp_3 = valueExists
|
|
1455
|
+
end
|
|
1456
|
+
local ____temp_4
|
|
1457
|
+
if desc.value ~= nil then
|
|
1458
|
+
____temp_4 = desc.value
|
|
1459
|
+
else
|
|
1460
|
+
____temp_4 = value
|
|
1461
|
+
end
|
|
1222
1462
|
descriptor = {
|
|
1223
|
-
set =
|
|
1224
|
-
get =
|
|
1225
|
-
configurable =
|
|
1226
|
-
enumerable =
|
|
1227
|
-
writable =
|
|
1228
|
-
value =
|
|
1463
|
+
set = ____desc_set_5,
|
|
1464
|
+
get = ____desc_get_6,
|
|
1465
|
+
configurable = ____temp_1,
|
|
1466
|
+
enumerable = ____temp_2,
|
|
1467
|
+
writable = ____temp_3,
|
|
1468
|
+
value = ____temp_4
|
|
1229
1469
|
}
|
|
1230
1470
|
end
|
|
1231
1471
|
__TS__SetDescriptor(target, luaKey, descriptor)
|
|
@@ -1287,41 +1527,19 @@ function __TS__ObjectValues(obj)
|
|
|
1287
1527
|
return result
|
|
1288
1528
|
end
|
|
1289
1529
|
|
|
1290
|
-
function __TS__OptionalChainAccess(____table, key)
|
|
1291
|
-
if ____table then
|
|
1292
|
-
return ____table[key]
|
|
1293
|
-
end
|
|
1294
|
-
return nil
|
|
1295
|
-
end
|
|
1296
|
-
|
|
1297
|
-
function __TS__OptionalFunctionCall(f, ...)
|
|
1298
|
-
if f then
|
|
1299
|
-
return f(...)
|
|
1300
|
-
end
|
|
1301
|
-
return nil
|
|
1302
|
-
end
|
|
1303
|
-
|
|
1304
|
-
function __TS__OptionalMethodCall(____table, methodName, isMethodOptional, ...)
|
|
1305
|
-
if ____table then
|
|
1306
|
-
local method = ____table[methodName]
|
|
1307
|
-
if method then
|
|
1308
|
-
return method(____table, ...)
|
|
1309
|
-
elseif not isMethodOptional then
|
|
1310
|
-
error(methodName .. " is not a function", 0)
|
|
1311
|
-
end
|
|
1312
|
-
end
|
|
1313
|
-
return nil
|
|
1314
|
-
end
|
|
1315
|
-
|
|
1316
1530
|
function __TS__ParseFloat(numberString)
|
|
1317
1531
|
local infinityMatch = string.match(numberString, "^%s*(-?Infinity)")
|
|
1318
1532
|
if infinityMatch then
|
|
1319
|
-
|
|
1533
|
+
local ____temp_0
|
|
1534
|
+
if __TS__StringAccess(infinityMatch, 0) == "-" then
|
|
1535
|
+
____temp_0 = -math.huge
|
|
1536
|
+
else
|
|
1537
|
+
____temp_0 = math.huge
|
|
1538
|
+
end
|
|
1539
|
+
return ____temp_0
|
|
1320
1540
|
end
|
|
1321
|
-
local number = tonumber(
|
|
1322
|
-
|
|
1323
|
-
)
|
|
1324
|
-
return number or (0 / 0)
|
|
1541
|
+
local number = tonumber(string.match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1542
|
+
return number or 0 / 0
|
|
1325
1543
|
end
|
|
1326
1544
|
|
|
1327
1545
|
function __TS__StringSubstr(self, from, length)
|
|
@@ -1329,7 +1547,7 @@ function __TS__StringSubstr(self, from, length)
|
|
|
1329
1547
|
from = 0
|
|
1330
1548
|
end
|
|
1331
1549
|
if length ~= nil then
|
|
1332
|
-
if
|
|
1550
|
+
if length ~= length or length <= 0 then
|
|
1333
1551
|
return ""
|
|
1334
1552
|
end
|
|
1335
1553
|
length = length + from
|
|
@@ -1344,7 +1562,7 @@ function __TS__StringSubstring(self, start, ____end)
|
|
|
1344
1562
|
if ____end ~= ____end then
|
|
1345
1563
|
____end = 0
|
|
1346
1564
|
end
|
|
1347
|
-
if
|
|
1565
|
+
if ____end ~= nil and start > ____end then
|
|
1348
1566
|
start, ____end = ____end, start
|
|
1349
1567
|
end
|
|
1350
1568
|
if start >= 0 then
|
|
@@ -1352,7 +1570,7 @@ function __TS__StringSubstring(self, start, ____end)
|
|
|
1352
1570
|
else
|
|
1353
1571
|
start = 1
|
|
1354
1572
|
end
|
|
1355
|
-
if
|
|
1573
|
+
if ____end ~= nil and ____end < 0 then
|
|
1356
1574
|
____end = 0
|
|
1357
1575
|
end
|
|
1358
1576
|
return string.sub(self, start, ____end)
|
|
@@ -1365,13 +1583,25 @@ function __TS__ParseInt(numberString, base)
|
|
|
1365
1583
|
local hexMatch = string.match(numberString, "^%s*-?0[xX]")
|
|
1366
1584
|
if hexMatch then
|
|
1367
1585
|
base = 16
|
|
1368
|
-
|
|
1586
|
+
local ____string_match_result__0_0
|
|
1587
|
+
if string.match(hexMatch, "-") then
|
|
1588
|
+
____string_match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
|
|
1589
|
+
else
|
|
1590
|
+
____string_match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
|
|
1591
|
+
end
|
|
1592
|
+
numberString = ____string_match_result__0_0
|
|
1369
1593
|
end
|
|
1370
1594
|
end
|
|
1371
|
-
if
|
|
1595
|
+
if base < 2 or base > 36 then
|
|
1372
1596
|
return 0 / 0
|
|
1373
1597
|
end
|
|
1374
|
-
local
|
|
1598
|
+
local ____temp_1
|
|
1599
|
+
if base <= 10 then
|
|
1600
|
+
____temp_1 = __TS__StringSubstring(__TS__parseInt_base_pattern, 0, base)
|
|
1601
|
+
else
|
|
1602
|
+
____temp_1 = __TS__StringSubstr(__TS__parseInt_base_pattern, 0, 10 + 2 * (base - 10))
|
|
1603
|
+
end
|
|
1604
|
+
local allowedDigits = ____temp_1
|
|
1375
1605
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1376
1606
|
local number = tonumber(
|
|
1377
1607
|
string.match(numberString, pattern),
|
|
@@ -1387,165 +1617,6 @@ function __TS__ParseInt(numberString, base)
|
|
|
1387
1617
|
end
|
|
1388
1618
|
end
|
|
1389
1619
|
|
|
1390
|
-
__TS__PromiseState = __TS__PromiseState or ({})
|
|
1391
|
-
__TS__PromiseState.Pending = 0
|
|
1392
|
-
__TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
|
|
1393
|
-
__TS__PromiseState.Fulfilled = 1
|
|
1394
|
-
__TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
|
|
1395
|
-
__TS__PromiseState.Rejected = 2
|
|
1396
|
-
__TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
|
|
1397
|
-
function __TS__PromiseDeferred(self)
|
|
1398
|
-
local resolve
|
|
1399
|
-
local reject
|
|
1400
|
-
local promise = __TS__New(
|
|
1401
|
-
__TS__Promise,
|
|
1402
|
-
function(____, res, rej)
|
|
1403
|
-
resolve = res
|
|
1404
|
-
reject = rej
|
|
1405
|
-
end
|
|
1406
|
-
)
|
|
1407
|
-
return {promise = promise, resolve = resolve, reject = reject}
|
|
1408
|
-
end
|
|
1409
|
-
function __TS__IsPromiseLike(self, thing)
|
|
1410
|
-
return __TS__InstanceOf(thing, __TS__Promise)
|
|
1411
|
-
end
|
|
1412
|
-
__TS__Promise = __TS__Class()
|
|
1413
|
-
__TS__Promise.name = "__TS__Promise"
|
|
1414
|
-
function __TS__Promise.prototype.____constructor(self, executor)
|
|
1415
|
-
self.state = __TS__PromiseState.Pending
|
|
1416
|
-
self.fulfilledCallbacks = {}
|
|
1417
|
-
self.rejectedCallbacks = {}
|
|
1418
|
-
self.finallyCallbacks = {}
|
|
1419
|
-
do
|
|
1420
|
-
local ____try, e = pcall(
|
|
1421
|
-
function()
|
|
1422
|
-
executor(
|
|
1423
|
-
_G,
|
|
1424
|
-
__TS__FunctionBind(self.resolve, self),
|
|
1425
|
-
__TS__FunctionBind(self.reject, self)
|
|
1426
|
-
)
|
|
1427
|
-
end
|
|
1428
|
-
)
|
|
1429
|
-
if not ____try then
|
|
1430
|
-
self:reject(e)
|
|
1431
|
-
end
|
|
1432
|
-
end
|
|
1433
|
-
end
|
|
1434
|
-
function __TS__Promise.resolve(data)
|
|
1435
|
-
local promise = __TS__New(
|
|
1436
|
-
__TS__Promise,
|
|
1437
|
-
function()
|
|
1438
|
-
end
|
|
1439
|
-
)
|
|
1440
|
-
promise.state = __TS__PromiseState.Fulfilled
|
|
1441
|
-
promise.value = data
|
|
1442
|
-
return promise
|
|
1443
|
-
end
|
|
1444
|
-
function __TS__Promise.reject(reason)
|
|
1445
|
-
local promise = __TS__New(
|
|
1446
|
-
__TS__Promise,
|
|
1447
|
-
function()
|
|
1448
|
-
end
|
|
1449
|
-
)
|
|
1450
|
-
promise.state = __TS__PromiseState.Rejected
|
|
1451
|
-
promise.rejectionReason = reason
|
|
1452
|
-
return promise
|
|
1453
|
-
end
|
|
1454
|
-
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
1455
|
-
local ____ = __TS__PromiseDeferred(_G)
|
|
1456
|
-
local promise = ____.promise
|
|
1457
|
-
local resolve = ____.resolve
|
|
1458
|
-
local reject = ____.reject
|
|
1459
|
-
if onFulfilled then
|
|
1460
|
-
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
1461
|
-
__TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
|
|
1462
|
-
if self.state == __TS__PromiseState.Fulfilled then
|
|
1463
|
-
internalCallback(_G, self.value)
|
|
1464
|
-
end
|
|
1465
|
-
else
|
|
1466
|
-
__TS__ArrayPush(
|
|
1467
|
-
self.fulfilledCallbacks,
|
|
1468
|
-
function() return resolve(_G, nil) end
|
|
1469
|
-
)
|
|
1470
|
-
end
|
|
1471
|
-
if onRejected then
|
|
1472
|
-
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
1473
|
-
__TS__ArrayPush(self.rejectedCallbacks, internalCallback)
|
|
1474
|
-
if self.state == __TS__PromiseState.Rejected then
|
|
1475
|
-
internalCallback(_G, self.rejectionReason)
|
|
1476
|
-
end
|
|
1477
|
-
end
|
|
1478
|
-
return promise
|
|
1479
|
-
end
|
|
1480
|
-
function __TS__Promise.prototype.catch(self, onRejected)
|
|
1481
|
-
return self["then"](self, nil, onRejected)
|
|
1482
|
-
end
|
|
1483
|
-
function __TS__Promise.prototype.finally(self, onFinally)
|
|
1484
|
-
if onFinally then
|
|
1485
|
-
__TS__ArrayPush(self.finallyCallbacks, onFinally)
|
|
1486
|
-
if self.state ~= __TS__PromiseState.Pending then
|
|
1487
|
-
onFinally(_G)
|
|
1488
|
-
end
|
|
1489
|
-
end
|
|
1490
|
-
return self
|
|
1491
|
-
end
|
|
1492
|
-
function __TS__Promise.prototype.resolve(self, data)
|
|
1493
|
-
if self.state == __TS__PromiseState.Pending then
|
|
1494
|
-
self.state = __TS__PromiseState.Fulfilled
|
|
1495
|
-
self.value = data
|
|
1496
|
-
for ____, callback in ipairs(self.fulfilledCallbacks) do
|
|
1497
|
-
callback(_G, data)
|
|
1498
|
-
end
|
|
1499
|
-
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1500
|
-
callback(_G)
|
|
1501
|
-
end
|
|
1502
|
-
end
|
|
1503
|
-
end
|
|
1504
|
-
function __TS__Promise.prototype.reject(self, reason)
|
|
1505
|
-
if self.state == __TS__PromiseState.Pending then
|
|
1506
|
-
self.state = __TS__PromiseState.Rejected
|
|
1507
|
-
self.rejectionReason = reason
|
|
1508
|
-
for ____, callback in ipairs(self.rejectedCallbacks) do
|
|
1509
|
-
callback(_G, reason)
|
|
1510
|
-
end
|
|
1511
|
-
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1512
|
-
callback(_G)
|
|
1513
|
-
end
|
|
1514
|
-
end
|
|
1515
|
-
end
|
|
1516
|
-
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
1517
|
-
return function(____, value)
|
|
1518
|
-
do
|
|
1519
|
-
local ____try, e = pcall(
|
|
1520
|
-
function()
|
|
1521
|
-
self:handleCallbackData(
|
|
1522
|
-
f(_G, value),
|
|
1523
|
-
resolve,
|
|
1524
|
-
reject
|
|
1525
|
-
)
|
|
1526
|
-
end
|
|
1527
|
-
)
|
|
1528
|
-
if not ____try then
|
|
1529
|
-
reject(_G, e)
|
|
1530
|
-
end
|
|
1531
|
-
end
|
|
1532
|
-
end
|
|
1533
|
-
end
|
|
1534
|
-
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
|
|
1535
|
-
if __TS__IsPromiseLike(_G, data) then
|
|
1536
|
-
local nextpromise = data
|
|
1537
|
-
if nextpromise.state == __TS__PromiseState.Fulfilled then
|
|
1538
|
-
resolve(_G, nextpromise.value)
|
|
1539
|
-
elseif nextpromise.state == __TS__PromiseState.Rejected then
|
|
1540
|
-
reject(_G, nextpromise.rejectionReason)
|
|
1541
|
-
else
|
|
1542
|
-
data["then"](data, resolve, reject)
|
|
1543
|
-
end
|
|
1544
|
-
else
|
|
1545
|
-
resolve(_G, data)
|
|
1546
|
-
end
|
|
1547
|
-
end
|
|
1548
|
-
|
|
1549
1620
|
function __TS__PromiseAll(iterable)
|
|
1550
1621
|
local results = {}
|
|
1551
1622
|
local toResolve = {}
|
|
@@ -1711,226 +1782,239 @@ function __TS__PromiseRace(iterable)
|
|
|
1711
1782
|
)
|
|
1712
1783
|
end
|
|
1713
1784
|
|
|
1714
|
-
Set = (
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
return
|
|
1724
|
-
end
|
|
1725
|
-
local iterable = values
|
|
1726
|
-
if iterable[Symbol.iterator] then
|
|
1727
|
-
local iterator = iterable[Symbol.iterator](iterable)
|
|
1728
|
-
while true do
|
|
1729
|
-
local result = iterator:next()
|
|
1730
|
-
if result.done then
|
|
1731
|
-
break
|
|
1732
|
-
end
|
|
1733
|
-
self:add(result.value)
|
|
1734
|
-
end
|
|
1735
|
-
else
|
|
1736
|
-
local array = values
|
|
1737
|
-
for ____, value in ipairs(array) do
|
|
1738
|
-
self:add(value)
|
|
1739
|
-
end
|
|
1740
|
-
end
|
|
1741
|
-
end
|
|
1742
|
-
function Set.prototype.add(self, value)
|
|
1743
|
-
local isNewValue = not self:has(value)
|
|
1744
|
-
if isNewValue then
|
|
1745
|
-
self.size = self.size + 1
|
|
1746
|
-
end
|
|
1747
|
-
if self.firstKey == nil then
|
|
1748
|
-
self.firstKey = value
|
|
1749
|
-
self.lastKey = value
|
|
1750
|
-
elseif isNewValue then
|
|
1751
|
-
self.nextKey[self.lastKey] = value
|
|
1752
|
-
self.previousKey[value] = self.lastKey
|
|
1753
|
-
self.lastKey = value
|
|
1754
|
-
end
|
|
1755
|
-
return self
|
|
1785
|
+
Set = __TS__Class()
|
|
1786
|
+
Set.name = "Set"
|
|
1787
|
+
function Set.prototype.____constructor(self, values)
|
|
1788
|
+
self[Symbol.toStringTag] = "Set"
|
|
1789
|
+
self.size = 0
|
|
1790
|
+
self.nextKey = {}
|
|
1791
|
+
self.previousKey = {}
|
|
1792
|
+
if values == nil then
|
|
1793
|
+
return
|
|
1756
1794
|
end
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
function Set.prototype.delete(self, value)
|
|
1765
|
-
local contains = self:has(value)
|
|
1766
|
-
if contains then
|
|
1767
|
-
self.size = self.size - 1
|
|
1768
|
-
local next = self.nextKey[value]
|
|
1769
|
-
local previous = self.previousKey[value]
|
|
1770
|
-
if next and previous then
|
|
1771
|
-
self.nextKey[previous] = next
|
|
1772
|
-
self.previousKey[next] = previous
|
|
1773
|
-
elseif next then
|
|
1774
|
-
self.firstKey = next
|
|
1775
|
-
self.previousKey[next] = nil
|
|
1776
|
-
elseif previous then
|
|
1777
|
-
self.lastKey = previous
|
|
1778
|
-
self.nextKey[previous] = nil
|
|
1779
|
-
else
|
|
1780
|
-
self.firstKey = nil
|
|
1781
|
-
self.lastKey = nil
|
|
1795
|
+
local iterable = values
|
|
1796
|
+
if iterable[Symbol.iterator] then
|
|
1797
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
1798
|
+
while true do
|
|
1799
|
+
local result = iterator:next()
|
|
1800
|
+
if result.done then
|
|
1801
|
+
break
|
|
1782
1802
|
end
|
|
1783
|
-
self.
|
|
1784
|
-
self.previousKey[value] = nil
|
|
1803
|
+
self:add(result.value)
|
|
1785
1804
|
end
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
self:keys()
|
|
1791
|
-
) do
|
|
1792
|
-
callback(_G, key, key, self)
|
|
1805
|
+
else
|
|
1806
|
+
local array = values
|
|
1807
|
+
for ____, value in ipairs(array) do
|
|
1808
|
+
self:add(value)
|
|
1793
1809
|
end
|
|
1794
1810
|
end
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
end
|
|
1801
|
-
function Set.prototype.entries(self)
|
|
1802
|
-
local nextKey = self.nextKey
|
|
1803
|
-
local key = self.firstKey
|
|
1804
|
-
return {
|
|
1805
|
-
[Symbol.iterator] = function(self)
|
|
1806
|
-
return self
|
|
1807
|
-
end,
|
|
1808
|
-
next = function(self)
|
|
1809
|
-
local result = {done = not key, value = {key, key}}
|
|
1810
|
-
key = nextKey[key]
|
|
1811
|
-
return result
|
|
1812
|
-
end
|
|
1813
|
-
}
|
|
1814
|
-
end
|
|
1815
|
-
function Set.prototype.keys(self)
|
|
1816
|
-
local nextKey = self.nextKey
|
|
1817
|
-
local key = self.firstKey
|
|
1818
|
-
return {
|
|
1819
|
-
[Symbol.iterator] = function(self)
|
|
1820
|
-
return self
|
|
1821
|
-
end,
|
|
1822
|
-
next = function(self)
|
|
1823
|
-
local result = {done = not key, value = key}
|
|
1824
|
-
key = nextKey[key]
|
|
1825
|
-
return result
|
|
1826
|
-
end
|
|
1827
|
-
}
|
|
1811
|
+
end
|
|
1812
|
+
function Set.prototype.add(self, value)
|
|
1813
|
+
local isNewValue = not self:has(value)
|
|
1814
|
+
if isNewValue then
|
|
1815
|
+
self.size = self.size + 1
|
|
1828
1816
|
end
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
next = function(self)
|
|
1837
|
-
local result = {done = not key, value = key}
|
|
1838
|
-
key = nextKey[key]
|
|
1839
|
-
return result
|
|
1840
|
-
end
|
|
1841
|
-
}
|
|
1817
|
+
if self.firstKey == nil then
|
|
1818
|
+
self.firstKey = value
|
|
1819
|
+
self.lastKey = value
|
|
1820
|
+
elseif isNewValue then
|
|
1821
|
+
self.nextKey[self.lastKey] = value
|
|
1822
|
+
self.previousKey[value] = self.lastKey
|
|
1823
|
+
self.lastKey = value
|
|
1842
1824
|
end
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
local
|
|
1858
|
-
if
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
end
|
|
1825
|
+
return self
|
|
1826
|
+
end
|
|
1827
|
+
function Set.prototype.clear(self)
|
|
1828
|
+
self.nextKey = {}
|
|
1829
|
+
self.previousKey = {}
|
|
1830
|
+
self.firstKey = nil
|
|
1831
|
+
self.lastKey = nil
|
|
1832
|
+
self.size = 0
|
|
1833
|
+
end
|
|
1834
|
+
function Set.prototype.delete(self, value)
|
|
1835
|
+
local contains = self:has(value)
|
|
1836
|
+
if contains then
|
|
1837
|
+
self.size = self.size - 1
|
|
1838
|
+
local next = self.nextKey[value]
|
|
1839
|
+
local previous = self.previousKey[value]
|
|
1840
|
+
if next and previous then
|
|
1841
|
+
self.nextKey[previous] = next
|
|
1842
|
+
self.previousKey[next] = previous
|
|
1843
|
+
elseif next then
|
|
1844
|
+
self.firstKey = next
|
|
1845
|
+
self.previousKey[next] = nil
|
|
1846
|
+
elseif previous then
|
|
1847
|
+
self.lastKey = previous
|
|
1848
|
+
self.nextKey[previous] = nil
|
|
1868
1849
|
else
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
end
|
|
1850
|
+
self.firstKey = nil
|
|
1851
|
+
self.lastKey = nil
|
|
1872
1852
|
end
|
|
1853
|
+
self.nextKey[value] = nil
|
|
1854
|
+
self.previousKey[value] = nil
|
|
1873
1855
|
end
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
function WeakMap.prototype.get(self, key)
|
|
1880
|
-
return self.items[key]
|
|
1856
|
+
return contains
|
|
1857
|
+
end
|
|
1858
|
+
function Set.prototype.forEach(self, callback)
|
|
1859
|
+
for ____, key in __TS__Iterator(self:keys()) do
|
|
1860
|
+
callback(_G, key, key, self)
|
|
1881
1861
|
end
|
|
1882
|
-
|
|
1883
|
-
|
|
1862
|
+
end
|
|
1863
|
+
function Set.prototype.has(self, value)
|
|
1864
|
+
return self.nextKey[value] ~= nil or self.lastKey == value
|
|
1865
|
+
end
|
|
1866
|
+
Set.prototype[Symbol.iterator] = function(self)
|
|
1867
|
+
return self:values()
|
|
1868
|
+
end
|
|
1869
|
+
function Set.prototype.entries(self)
|
|
1870
|
+
local nextKey = self.nextKey
|
|
1871
|
+
local key = self.firstKey
|
|
1872
|
+
return {
|
|
1873
|
+
[Symbol.iterator] = function(self)
|
|
1874
|
+
return self
|
|
1875
|
+
end,
|
|
1876
|
+
next = function(self)
|
|
1877
|
+
local result = {done = not key, value = {key, key}}
|
|
1878
|
+
key = nextKey[key]
|
|
1879
|
+
return result
|
|
1880
|
+
end
|
|
1881
|
+
}
|
|
1882
|
+
end
|
|
1883
|
+
function Set.prototype.keys(self)
|
|
1884
|
+
local nextKey = self.nextKey
|
|
1885
|
+
local key = self.firstKey
|
|
1886
|
+
return {
|
|
1887
|
+
[Symbol.iterator] = function(self)
|
|
1888
|
+
return self
|
|
1889
|
+
end,
|
|
1890
|
+
next = function(self)
|
|
1891
|
+
local result = {done = not key, value = key}
|
|
1892
|
+
key = nextKey[key]
|
|
1893
|
+
return result
|
|
1894
|
+
end
|
|
1895
|
+
}
|
|
1896
|
+
end
|
|
1897
|
+
function Set.prototype.values(self)
|
|
1898
|
+
local nextKey = self.nextKey
|
|
1899
|
+
local key = self.firstKey
|
|
1900
|
+
return {
|
|
1901
|
+
[Symbol.iterator] = function(self)
|
|
1902
|
+
return self
|
|
1903
|
+
end,
|
|
1904
|
+
next = function(self)
|
|
1905
|
+
local result = {done = not key, value = key}
|
|
1906
|
+
key = nextKey[key]
|
|
1907
|
+
return result
|
|
1908
|
+
end
|
|
1909
|
+
}
|
|
1910
|
+
end
|
|
1911
|
+
Set[Symbol.species] = Set
|
|
1912
|
+
Set = Set
|
|
1913
|
+
|
|
1914
|
+
function __TS__SparseArrayNew(...)
|
|
1915
|
+
local sparseArray = {...}
|
|
1916
|
+
sparseArray.sparseLength = select("#", ...)
|
|
1917
|
+
return sparseArray
|
|
1918
|
+
end
|
|
1919
|
+
|
|
1920
|
+
function __TS__SparseArrayPush(sparseArray, ...)
|
|
1921
|
+
local args = {...}
|
|
1922
|
+
local argsLen = select("#", ...)
|
|
1923
|
+
local listLen = sparseArray.sparseLength
|
|
1924
|
+
for i = 1, argsLen do
|
|
1925
|
+
sparseArray[listLen + i] = args[i]
|
|
1884
1926
|
end
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1927
|
+
sparseArray.sparseLength = listLen + argsLen
|
|
1928
|
+
end
|
|
1929
|
+
|
|
1930
|
+
function __TS__SparseArraySpread(sparseArray)
|
|
1931
|
+
local _unpack = unpack or table.unpack
|
|
1932
|
+
return _unpack(sparseArray, 1, sparseArray.sparseLength)
|
|
1933
|
+
end
|
|
1934
|
+
|
|
1935
|
+
WeakMap = __TS__Class()
|
|
1936
|
+
WeakMap.name = "WeakMap"
|
|
1937
|
+
function WeakMap.prototype.____constructor(self, entries)
|
|
1938
|
+
self[Symbol.toStringTag] = "WeakMap"
|
|
1939
|
+
self.items = {}
|
|
1940
|
+
setmetatable(self.items, {__mode = "k"})
|
|
1941
|
+
if entries == nil then
|
|
1942
|
+
return
|
|
1888
1943
|
end
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
function WeakSet.prototype.____constructor(self, values)
|
|
1897
|
-
self[Symbol.toStringTag] = "WeakSet"
|
|
1898
|
-
self.items = {}
|
|
1899
|
-
setmetatable(self.items, {__mode = "k"})
|
|
1900
|
-
if values == nil then
|
|
1901
|
-
return
|
|
1902
|
-
end
|
|
1903
|
-
local iterable = values
|
|
1904
|
-
if iterable[Symbol.iterator] then
|
|
1905
|
-
local iterator = iterable[Symbol.iterator](iterable)
|
|
1906
|
-
while true do
|
|
1907
|
-
local result = iterator:next()
|
|
1908
|
-
if result.done then
|
|
1909
|
-
break
|
|
1910
|
-
end
|
|
1911
|
-
self.items[result.value] = true
|
|
1912
|
-
end
|
|
1913
|
-
else
|
|
1914
|
-
for ____, value in ipairs(values) do
|
|
1915
|
-
self.items[value] = true
|
|
1944
|
+
local iterable = entries
|
|
1945
|
+
if iterable[Symbol.iterator] then
|
|
1946
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
1947
|
+
while true do
|
|
1948
|
+
local result = iterator:next()
|
|
1949
|
+
if result.done then
|
|
1950
|
+
break
|
|
1916
1951
|
end
|
|
1952
|
+
local value = result.value
|
|
1953
|
+
self.items[value[1]] = value[2]
|
|
1954
|
+
end
|
|
1955
|
+
else
|
|
1956
|
+
for ____, kvp in ipairs(entries) do
|
|
1957
|
+
self.items[kvp[1]] = kvp[2]
|
|
1917
1958
|
end
|
|
1918
1959
|
end
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1960
|
+
end
|
|
1961
|
+
function WeakMap.prototype.delete(self, key)
|
|
1962
|
+
local contains = self:has(key)
|
|
1963
|
+
self.items[key] = nil
|
|
1964
|
+
return contains
|
|
1965
|
+
end
|
|
1966
|
+
function WeakMap.prototype.get(self, key)
|
|
1967
|
+
return self.items[key]
|
|
1968
|
+
end
|
|
1969
|
+
function WeakMap.prototype.has(self, key)
|
|
1970
|
+
return self.items[key] ~= nil
|
|
1971
|
+
end
|
|
1972
|
+
function WeakMap.prototype.set(self, key, value)
|
|
1973
|
+
self.items[key] = value
|
|
1974
|
+
return self
|
|
1975
|
+
end
|
|
1976
|
+
WeakMap[Symbol.species] = WeakMap
|
|
1977
|
+
WeakMap = WeakMap
|
|
1978
|
+
|
|
1979
|
+
WeakSet = __TS__Class()
|
|
1980
|
+
WeakSet.name = "WeakSet"
|
|
1981
|
+
function WeakSet.prototype.____constructor(self, values)
|
|
1982
|
+
self[Symbol.toStringTag] = "WeakSet"
|
|
1983
|
+
self.items = {}
|
|
1984
|
+
setmetatable(self.items, {__mode = "k"})
|
|
1985
|
+
if values == nil then
|
|
1986
|
+
return
|
|
1927
1987
|
end
|
|
1928
|
-
|
|
1929
|
-
|
|
1988
|
+
local iterable = values
|
|
1989
|
+
if iterable[Symbol.iterator] then
|
|
1990
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
1991
|
+
while true do
|
|
1992
|
+
local result = iterator:next()
|
|
1993
|
+
if result.done then
|
|
1994
|
+
break
|
|
1995
|
+
end
|
|
1996
|
+
self.items[result.value] = true
|
|
1997
|
+
end
|
|
1998
|
+
else
|
|
1999
|
+
for ____, value in ipairs(values) do
|
|
2000
|
+
self.items[value] = true
|
|
2001
|
+
end
|
|
1930
2002
|
end
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2003
|
+
end
|
|
2004
|
+
function WeakSet.prototype.add(self, value)
|
|
2005
|
+
self.items[value] = true
|
|
2006
|
+
return self
|
|
2007
|
+
end
|
|
2008
|
+
function WeakSet.prototype.delete(self, value)
|
|
2009
|
+
local contains = self:has(value)
|
|
2010
|
+
self.items[value] = nil
|
|
2011
|
+
return contains
|
|
2012
|
+
end
|
|
2013
|
+
function WeakSet.prototype.has(self, value)
|
|
2014
|
+
return self.items[value] == true
|
|
2015
|
+
end
|
|
2016
|
+
WeakSet[Symbol.species] = WeakSet
|
|
2017
|
+
WeakSet = WeakSet
|
|
1934
2018
|
|
|
1935
2019
|
function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
1936
2020
|
_G.__TS__sourcemap = _G.__TS__sourcemap or ({})
|
|
@@ -1939,7 +2023,7 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
1939
2023
|
_G.__TS__originalTraceback = debug.traceback
|
|
1940
2024
|
debug.traceback = function(thread, message, level)
|
|
1941
2025
|
local trace
|
|
1942
|
-
if
|
|
2026
|
+
if thread == nil and message == nil and level == nil then
|
|
1943
2027
|
trace = _G.__TS__originalTraceback()
|
|
1944
2028
|
else
|
|
1945
2029
|
trace = _G.__TS__originalTraceback(thread, message, level)
|
|
@@ -1947,16 +2031,26 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
1947
2031
|
if type(trace) ~= "string" then
|
|
1948
2032
|
return trace
|
|
1949
2033
|
end
|
|
1950
|
-
local
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
return (file .. ".ts:") .. tostring(fileSourceMap[line])
|
|
2034
|
+
local function replacer(____, file, srcFile, line)
|
|
2035
|
+
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2036
|
+
if fileSourceMap and fileSourceMap[line] then
|
|
2037
|
+
local data = fileSourceMap[line]
|
|
2038
|
+
if type(data) == "number" then
|
|
2039
|
+
return (srcFile .. ":") .. tostring(data)
|
|
1957
2040
|
end
|
|
1958
|
-
return (file .. "
|
|
2041
|
+
return (tostring(data.file) .. ":") .. tostring(data.line)
|
|
1959
2042
|
end
|
|
2043
|
+
return (file .. ":") .. line
|
|
2044
|
+
end
|
|
2045
|
+
local result = string.gsub(
|
|
2046
|
+
trace,
|
|
2047
|
+
"(%S+)%.lua:(%d+)",
|
|
2048
|
+
function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
|
|
2049
|
+
)
|
|
2050
|
+
result = string.gsub(
|
|
2051
|
+
result,
|
|
2052
|
+
"(%[string \"[^\"]+\"%]):(%d+)",
|
|
2053
|
+
function(file, line) return replacer(_G, file, "unknown", line) end
|
|
1960
2054
|
)
|
|
1961
2055
|
return result
|
|
1962
2056
|
end
|
|
@@ -1998,7 +2092,7 @@ function __TS__StringCharCodeAt(self, index)
|
|
|
1998
2092
|
if index < 0 then
|
|
1999
2093
|
return 0 / 0
|
|
2000
2094
|
end
|
|
2001
|
-
return string.byte(self, index + 1) or
|
|
2095
|
+
return string.byte(self, index + 1) or 0 / 0
|
|
2002
2096
|
end
|
|
2003
2097
|
|
|
2004
2098
|
function __TS__StringConcat(str1, ...)
|
|
@@ -2011,10 +2105,10 @@ function __TS__StringConcat(str1, ...)
|
|
|
2011
2105
|
end
|
|
2012
2106
|
|
|
2013
2107
|
function __TS__StringEndsWith(self, searchString, endPosition)
|
|
2014
|
-
if
|
|
2108
|
+
if endPosition == nil or endPosition > #self then
|
|
2015
2109
|
endPosition = #self
|
|
2016
2110
|
end
|
|
2017
|
-
return string.sub(self,
|
|
2111
|
+
return string.sub(self, endPosition - #searchString + 1, endPosition) == searchString
|
|
2018
2112
|
end
|
|
2019
2113
|
|
|
2020
2114
|
function __TS__StringIncludes(self, searchString, position)
|
|
@@ -2034,10 +2128,10 @@ function __TS__StringPadEnd(self, maxLength, fillString)
|
|
|
2034
2128
|
if maxLength ~= maxLength then
|
|
2035
2129
|
maxLength = 0
|
|
2036
2130
|
end
|
|
2037
|
-
if
|
|
2131
|
+
if maxLength == -math.huge or maxLength == math.huge then
|
|
2038
2132
|
error("Invalid string length", 0)
|
|
2039
2133
|
end
|
|
2040
|
-
if
|
|
2134
|
+
if #self >= maxLength or #fillString == 0 then
|
|
2041
2135
|
return self
|
|
2042
2136
|
end
|
|
2043
2137
|
maxLength = maxLength - #self
|
|
@@ -2061,10 +2155,10 @@ function __TS__StringPadStart(self, maxLength, fillString)
|
|
|
2061
2155
|
if maxLength ~= maxLength then
|
|
2062
2156
|
maxLength = 0
|
|
2063
2157
|
end
|
|
2064
|
-
if
|
|
2158
|
+
if maxLength == -math.huge or maxLength == math.huge then
|
|
2065
2159
|
error("Invalid string length", 0)
|
|
2066
2160
|
end
|
|
2067
|
-
if
|
|
2161
|
+
if #self >= maxLength or #fillString == 0 then
|
|
2068
2162
|
return self
|
|
2069
2163
|
end
|
|
2070
2164
|
maxLength = maxLength - #self
|
|
@@ -2082,24 +2176,61 @@ function __TS__StringPadStart(self, maxLength, fillString)
|
|
|
2082
2176
|
end
|
|
2083
2177
|
|
|
2084
2178
|
function __TS__StringReplace(source, searchValue, replaceValue)
|
|
2085
|
-
|
|
2179
|
+
local startPos, endPos = string.find(source, searchValue, nil, true)
|
|
2180
|
+
if not startPos then
|
|
2181
|
+
return source
|
|
2182
|
+
end
|
|
2183
|
+
local sub = string.sub
|
|
2184
|
+
local before = sub(source, 1, startPos - 1)
|
|
2185
|
+
local ____temp_0
|
|
2086
2186
|
if type(replaceValue) == "string" then
|
|
2087
|
-
|
|
2088
|
-
local result = string.gsub(source, searchValue, replaceValue, 1)
|
|
2089
|
-
return result
|
|
2187
|
+
____temp_0 = replaceValue
|
|
2090
2188
|
else
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2189
|
+
____temp_0 = replaceValue(_G, searchValue, startPos - 1, source)
|
|
2190
|
+
end
|
|
2191
|
+
local replacement = ____temp_0
|
|
2192
|
+
local after = sub(source, endPos + 1)
|
|
2193
|
+
return (before .. replacement) .. after
|
|
2194
|
+
end
|
|
2195
|
+
|
|
2196
|
+
function __TS__StringReplaceAll(source, searchValue, replaceValue)
|
|
2197
|
+
local replacer
|
|
2198
|
+
if type(replaceValue) == "string" then
|
|
2199
|
+
replacer = function() return replaceValue end
|
|
2200
|
+
else
|
|
2201
|
+
replacer = replaceValue
|
|
2202
|
+
end
|
|
2203
|
+
local parts = {}
|
|
2204
|
+
local partsIndex = 1
|
|
2205
|
+
local sub = string.sub
|
|
2206
|
+
if #searchValue == 0 then
|
|
2207
|
+
parts[1] = replacer(_G, "", 0, source)
|
|
2208
|
+
partsIndex = 2
|
|
2209
|
+
for i = 1, #source do
|
|
2210
|
+
parts[partsIndex] = sub(source, i, i)
|
|
2211
|
+
parts[partsIndex + 1] = replacer(_G, "", i, source)
|
|
2212
|
+
partsIndex = partsIndex + 2
|
|
2213
|
+
end
|
|
2214
|
+
else
|
|
2215
|
+
local find = string.find
|
|
2216
|
+
local currentPos = 1
|
|
2217
|
+
while true do
|
|
2218
|
+
local startPos, endPos = find(source, searchValue, currentPos, true)
|
|
2219
|
+
if not startPos then
|
|
2220
|
+
break
|
|
2221
|
+
end
|
|
2222
|
+
parts[partsIndex] = sub(source, currentPos, startPos - 1)
|
|
2223
|
+
parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
|
|
2224
|
+
partsIndex = partsIndex + 2
|
|
2225
|
+
currentPos = endPos + 1
|
|
2226
|
+
end
|
|
2227
|
+
parts[partsIndex] = sub(source, currentPos)
|
|
2098
2228
|
end
|
|
2229
|
+
return table.concat(parts)
|
|
2099
2230
|
end
|
|
2100
2231
|
|
|
2101
2232
|
function __TS__StringSlice(self, start, ____end)
|
|
2102
|
-
if
|
|
2233
|
+
if start == nil or start ~= start then
|
|
2103
2234
|
start = 0
|
|
2104
2235
|
end
|
|
2105
2236
|
if ____end ~= ____end then
|
|
@@ -2108,7 +2239,7 @@ function __TS__StringSlice(self, start, ____end)
|
|
|
2108
2239
|
if start >= 0 then
|
|
2109
2240
|
start = start + 1
|
|
2110
2241
|
end
|
|
2111
|
-
if
|
|
2242
|
+
if ____end ~= nil and ____end < 0 then
|
|
2112
2243
|
____end = ____end - 1
|
|
2113
2244
|
end
|
|
2114
2245
|
return string.sub(self, start, ____end)
|
|
@@ -2124,8 +2255,8 @@ function __TS__StringSplit(source, separator, limit)
|
|
|
2124
2255
|
local out = {}
|
|
2125
2256
|
local index = 0
|
|
2126
2257
|
local count = 0
|
|
2127
|
-
if
|
|
2128
|
-
while
|
|
2258
|
+
if separator == nil or separator == "" then
|
|
2259
|
+
while index < #source - 1 and count < limit do
|
|
2129
2260
|
out[count + 1] = __TS__StringAccess(source, index)
|
|
2130
2261
|
count = count + 1
|
|
2131
2262
|
index = index + 1
|
|
@@ -2133,7 +2264,7 @@ function __TS__StringSplit(source, separator, limit)
|
|
|
2133
2264
|
else
|
|
2134
2265
|
local separatorLength = #separator
|
|
2135
2266
|
local nextIndex = (string.find(source, separator, nil, true) or 0) - 1
|
|
2136
|
-
while
|
|
2267
|
+
while nextIndex >= 0 and count < limit do
|
|
2137
2268
|
out[count + 1] = __TS__StringSubstring(source, index, nextIndex)
|
|
2138
2269
|
count = count + 1
|
|
2139
2270
|
index = nextIndex + separatorLength
|
|
@@ -2152,7 +2283,7 @@ function __TS__StringSplit(source, separator, limit)
|
|
|
2152
2283
|
end
|
|
2153
2284
|
|
|
2154
2285
|
function __TS__StringStartsWith(self, searchString, position)
|
|
2155
|
-
if
|
|
2286
|
+
if position == nil or position < 0 then
|
|
2156
2287
|
position = 0
|
|
2157
2288
|
end
|
|
2158
2289
|
return string.sub(self, position + 1, #searchString + position) == searchString
|