typescript-to-lua 0.41.2 → 1.1.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.js +4 -4
- package/dist/LuaLib.d.ts +7 -0
- package/dist/LuaLib.js +41 -5
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/ArrayJoin.lua +2 -4
- package/dist/lualib/Await.lua +59 -0
- package/dist/lualib/Iterator.lua +1 -5
- package/dist/lualib/NumberToString.lua +4 -8
- package/dist/lualib/OptionalMethodCall.lua +3 -1
- package/dist/lualib/ParseInt.lua +1 -3
- package/dist/lualib/Promise.lua +172 -0
- package/dist/lualib/PromiseAll.lua +44 -0
- package/dist/lualib/PromiseAllSettled.lua +48 -0
- package/dist/lualib/PromiseAny.lua +41 -0
- package/dist/lualib/PromiseRace.lua +28 -0
- package/dist/lualib/SourceMapTraceBack.lua +18 -8
- package/dist/lualib/StringConcat.lua +1 -1
- package/dist/lualib/StringPadEnd.lua +7 -11
- package/dist/lualib/StringPadStart.lua +8 -12
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSubstring.lua +1 -1
- package/dist/lualib/lualib_bundle.lua +660 -239
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +35 -32
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.d.ts +7 -0
- package/dist/transformation/builtins/promise.js +46 -0
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -4
- package/dist/transformation/utils/annotations.js +1 -32
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +6 -5
- package/dist/transformation/utils/export.js +4 -4
- package/dist/transformation/utils/function-context.js +19 -13
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +25 -19
- package/dist/transformation/visitors/async-await.d.ts +6 -0
- package/dist/transformation/visitors/async-await.js +38 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +32 -31
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +22 -20
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.js +38 -38
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +34 -34
- 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 +13 -13
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -31
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +33 -21
- package/dist/transformation/visitors/identifier.js +25 -19
- package/dist/transformation/visitors/index.js +4 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +2 -1
- package/dist/transformation/visitors/language-extensions/multi.js +8 -4
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- 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 +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -13
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +41 -49
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +16 -13
- package/dist/transformation/visitors/switch.js +132 -30
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -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 +29 -30
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- 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 +28 -14
- package/dist/transpilation/transformers.d.ts +1 -0
- package/dist/transpilation/transformers.js +61 -25
- package/dist/transpilation/transpile.js +7 -7
- package/dist/transpilation/transpiler.js +13 -11
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +9 -9
- package/dist/utils.js +2 -2
- package/package.json +16 -13
- 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
|
@@ -159,11 +159,9 @@ function __TS__ArrayJoin(self, separator)
|
|
|
159
159
|
local result = ""
|
|
160
160
|
for index, value in ipairs(self) do
|
|
161
161
|
if index > 1 then
|
|
162
|
-
result =
|
|
162
|
+
result = result .. separator
|
|
163
163
|
end
|
|
164
|
-
result =
|
|
165
|
-
tostring(value)
|
|
166
|
-
)
|
|
164
|
+
result = result .. tostring(value)
|
|
167
165
|
end
|
|
168
166
|
return result
|
|
169
167
|
end
|
|
@@ -456,6 +454,106 @@ function __TS__ArraySetLength(arr, length)
|
|
|
456
454
|
return length
|
|
457
455
|
end
|
|
458
456
|
|
|
457
|
+
____symbolMetatable = {
|
|
458
|
+
__tostring = function(self)
|
|
459
|
+
return ("Symbol(" .. (self.description or "")) .. ")"
|
|
460
|
+
end
|
|
461
|
+
}
|
|
462
|
+
function __TS__Symbol(description)
|
|
463
|
+
return setmetatable({description = description}, ____symbolMetatable)
|
|
464
|
+
end
|
|
465
|
+
Symbol = {
|
|
466
|
+
iterator = __TS__Symbol("Symbol.iterator"),
|
|
467
|
+
hasInstance = __TS__Symbol("Symbol.hasInstance"),
|
|
468
|
+
species = __TS__Symbol("Symbol.species"),
|
|
469
|
+
toStringTag = __TS__Symbol("Symbol.toStringTag")
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function __TS__InstanceOf(obj, classTbl)
|
|
473
|
+
if type(classTbl) ~= "table" then
|
|
474
|
+
error("Right-hand side of 'instanceof' is not an object", 0)
|
|
475
|
+
end
|
|
476
|
+
if classTbl[Symbol.hasInstance] ~= nil then
|
|
477
|
+
return not (not classTbl[Symbol.hasInstance](classTbl, obj))
|
|
478
|
+
end
|
|
479
|
+
if type(obj) == "table" then
|
|
480
|
+
local luaClass = obj.constructor
|
|
481
|
+
while luaClass ~= nil do
|
|
482
|
+
if luaClass == classTbl then
|
|
483
|
+
return true
|
|
484
|
+
end
|
|
485
|
+
luaClass = luaClass.____super
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
return false
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
function __TS__New(target, ...)
|
|
492
|
+
local instance = setmetatable({}, target.prototype)
|
|
493
|
+
instance:____constructor(...)
|
|
494
|
+
return instance
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
function __TS__AsyncAwaiter(generator)
|
|
498
|
+
return __TS__New(
|
|
499
|
+
__TS__Promise,
|
|
500
|
+
function(____, resolve, reject)
|
|
501
|
+
local adopt, fulfilled, rejected, step, asyncCoroutine
|
|
502
|
+
function adopt(self, value)
|
|
503
|
+
return ((__TS__InstanceOf(value, __TS__Promise) and (function() return value end)) or (function() return __TS__Promise.resolve(value) end))()
|
|
504
|
+
end
|
|
505
|
+
function fulfilled(self, value)
|
|
506
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
|
|
507
|
+
if success then
|
|
508
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
509
|
+
else
|
|
510
|
+
reject(_G, resultOrError)
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
function rejected(self, handler)
|
|
514
|
+
if handler then
|
|
515
|
+
return function(____, value)
|
|
516
|
+
local success, valueOrError = pcall(handler, value)
|
|
517
|
+
if success then
|
|
518
|
+
step(_G, valueOrError, handler)
|
|
519
|
+
else
|
|
520
|
+
reject(_G, valueOrError)
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
else
|
|
524
|
+
return function(____, value)
|
|
525
|
+
reject(_G, value)
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
function step(self, result, errorHandler)
|
|
530
|
+
if coroutine.status(asyncCoroutine) == "dead" then
|
|
531
|
+
resolve(_G, result)
|
|
532
|
+
else
|
|
533
|
+
(function()
|
|
534
|
+
local ____self = adopt(_G, result)
|
|
535
|
+
return ____self["then"](
|
|
536
|
+
____self,
|
|
537
|
+
fulfilled,
|
|
538
|
+
rejected(_G, errorHandler)
|
|
539
|
+
)
|
|
540
|
+
end)()
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
asyncCoroutine = coroutine.create(generator)
|
|
544
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
|
|
545
|
+
if success then
|
|
546
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
547
|
+
else
|
|
548
|
+
reject(_G, errorOrErrorHandler)
|
|
549
|
+
end
|
|
550
|
+
end
|
|
551
|
+
)
|
|
552
|
+
end
|
|
553
|
+
function __TS__Await(errorHandler, thing)
|
|
554
|
+
return coroutine.yield(errorHandler, thing)
|
|
555
|
+
end
|
|
556
|
+
|
|
459
557
|
function __TS__Class(self)
|
|
460
558
|
local c = {prototype = {}}
|
|
461
559
|
c.prototype.__index = c.prototype
|
|
@@ -517,6 +615,101 @@ function __TS__CloneDescriptor(____bindingPattern0)
|
|
|
517
615
|
return descriptor
|
|
518
616
|
end
|
|
519
617
|
|
|
618
|
+
function __TS__ObjectGetOwnPropertyDescriptor(object, key)
|
|
619
|
+
local metatable = getmetatable(object)
|
|
620
|
+
if not metatable then
|
|
621
|
+
return
|
|
622
|
+
end
|
|
623
|
+
if not rawget(metatable, "_descriptors") then
|
|
624
|
+
return
|
|
625
|
+
end
|
|
626
|
+
return rawget(metatable, "_descriptors")[key]
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
function ____descriptorIndex(self, key)
|
|
630
|
+
local value = rawget(self, key)
|
|
631
|
+
if value ~= nil then
|
|
632
|
+
return value
|
|
633
|
+
end
|
|
634
|
+
local metatable = getmetatable(self)
|
|
635
|
+
while metatable do
|
|
636
|
+
local rawResult = rawget(metatable, key)
|
|
637
|
+
if rawResult ~= nil then
|
|
638
|
+
return rawResult
|
|
639
|
+
end
|
|
640
|
+
local descriptors = rawget(metatable, "_descriptors")
|
|
641
|
+
if descriptors then
|
|
642
|
+
local descriptor = descriptors[key]
|
|
643
|
+
if descriptor then
|
|
644
|
+
if descriptor.get then
|
|
645
|
+
return descriptor.get(self)
|
|
646
|
+
end
|
|
647
|
+
return descriptor.value
|
|
648
|
+
end
|
|
649
|
+
end
|
|
650
|
+
metatable = getmetatable(metatable)
|
|
651
|
+
end
|
|
652
|
+
end
|
|
653
|
+
function ____descriptorNewindex(self, key, value)
|
|
654
|
+
local metatable = getmetatable(self)
|
|
655
|
+
while metatable do
|
|
656
|
+
local descriptors = rawget(metatable, "_descriptors")
|
|
657
|
+
if descriptors then
|
|
658
|
+
local descriptor = descriptors[key]
|
|
659
|
+
if descriptor then
|
|
660
|
+
if descriptor.set then
|
|
661
|
+
descriptor.set(self, value)
|
|
662
|
+
else
|
|
663
|
+
if descriptor.writable == false then
|
|
664
|
+
error(
|
|
665
|
+
((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
|
|
666
|
+
0
|
|
667
|
+
)
|
|
668
|
+
end
|
|
669
|
+
descriptor.value = value
|
|
670
|
+
end
|
|
671
|
+
return
|
|
672
|
+
end
|
|
673
|
+
end
|
|
674
|
+
metatable = getmetatable(metatable)
|
|
675
|
+
end
|
|
676
|
+
rawset(self, key, value)
|
|
677
|
+
end
|
|
678
|
+
function __TS__SetDescriptor(target, key, desc, isPrototype)
|
|
679
|
+
if isPrototype == nil then
|
|
680
|
+
isPrototype = false
|
|
681
|
+
end
|
|
682
|
+
local metatable = ((isPrototype and (function() return target end)) or (function() return getmetatable(target) end))()
|
|
683
|
+
if not metatable then
|
|
684
|
+
metatable = {}
|
|
685
|
+
setmetatable(target, metatable)
|
|
686
|
+
end
|
|
687
|
+
local value = rawget(target, key)
|
|
688
|
+
if value ~= nil then
|
|
689
|
+
rawset(target, key, nil)
|
|
690
|
+
end
|
|
691
|
+
if not rawget(metatable, "_descriptors") then
|
|
692
|
+
metatable._descriptors = {}
|
|
693
|
+
end
|
|
694
|
+
local descriptor = __TS__CloneDescriptor(desc)
|
|
695
|
+
metatable._descriptors[key] = descriptor
|
|
696
|
+
metatable.__index = ____descriptorIndex
|
|
697
|
+
metatable.__newindex = ____descriptorNewindex
|
|
698
|
+
end
|
|
699
|
+
|
|
700
|
+
function __TS__ObjectAssign(to, ...)
|
|
701
|
+
local sources = {...}
|
|
702
|
+
if to == nil then
|
|
703
|
+
return to
|
|
704
|
+
end
|
|
705
|
+
for ____, source in ipairs(sources) do
|
|
706
|
+
for key in pairs(source) do
|
|
707
|
+
to[key] = source[key]
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
return to
|
|
711
|
+
end
|
|
712
|
+
|
|
520
713
|
function __TS__Decorate(decorators, target, key, desc)
|
|
521
714
|
local result = target
|
|
522
715
|
do
|
|
@@ -586,6 +779,12 @@ function __TS__Delete(target, key)
|
|
|
586
779
|
return false
|
|
587
780
|
end
|
|
588
781
|
|
|
782
|
+
function __TS__StringAccess(self, index)
|
|
783
|
+
if (index >= 0) and (index < #self) then
|
|
784
|
+
return string.sub(self, index + 1, index + 1)
|
|
785
|
+
end
|
|
786
|
+
end
|
|
787
|
+
|
|
589
788
|
function __TS__DelegatedYield(iterable)
|
|
590
789
|
if type(iterable) == "string" then
|
|
591
790
|
for index = 0, #iterable - 1 do
|
|
@@ -623,12 +822,6 @@ function __TS__DelegatedYield(iterable)
|
|
|
623
822
|
end
|
|
624
823
|
end
|
|
625
824
|
|
|
626
|
-
function __TS__New(target, ...)
|
|
627
|
-
local instance = setmetatable({}, target.prototype)
|
|
628
|
-
instance:____constructor(...)
|
|
629
|
-
return instance
|
|
630
|
-
end
|
|
631
|
-
|
|
632
825
|
function __TS__GetErrorStack(self, constructor)
|
|
633
826
|
local level = 1
|
|
634
827
|
while true do
|
|
@@ -725,21 +918,6 @@ function __TS__FunctionBind(fn, thisArg, ...)
|
|
|
725
918
|
end
|
|
726
919
|
end
|
|
727
920
|
|
|
728
|
-
____symbolMetatable = {
|
|
729
|
-
__tostring = function(self)
|
|
730
|
-
return ("Symbol(" .. (self.description or "")) .. ")"
|
|
731
|
-
end
|
|
732
|
-
}
|
|
733
|
-
function __TS__Symbol(description)
|
|
734
|
-
return setmetatable({description = description}, ____symbolMetatable)
|
|
735
|
-
end
|
|
736
|
-
Symbol = {
|
|
737
|
-
iterator = __TS__Symbol("Symbol.iterator"),
|
|
738
|
-
hasInstance = __TS__Symbol("Symbol.hasInstance"),
|
|
739
|
-
species = __TS__Symbol("Symbol.species"),
|
|
740
|
-
toStringTag = __TS__Symbol("Symbol.toStringTag")
|
|
741
|
-
}
|
|
742
|
-
|
|
743
921
|
function __TS__GeneratorIterator(self)
|
|
744
922
|
return self
|
|
745
923
|
end
|
|
@@ -773,25 +951,6 @@ function __TS__Generator(fn)
|
|
|
773
951
|
end
|
|
774
952
|
end
|
|
775
953
|
|
|
776
|
-
function __TS__InstanceOf(obj, classTbl)
|
|
777
|
-
if type(classTbl) ~= "table" then
|
|
778
|
-
error("Right-hand side of 'instanceof' is not an object", 0)
|
|
779
|
-
end
|
|
780
|
-
if classTbl[Symbol.hasInstance] ~= nil then
|
|
781
|
-
return not (not classTbl[Symbol.hasInstance](classTbl, obj))
|
|
782
|
-
end
|
|
783
|
-
if type(obj) == "table" then
|
|
784
|
-
local luaClass = obj.constructor
|
|
785
|
-
while luaClass ~= nil do
|
|
786
|
-
if luaClass == classTbl then
|
|
787
|
-
return true
|
|
788
|
-
end
|
|
789
|
-
luaClass = luaClass.____super
|
|
790
|
-
end
|
|
791
|
-
end
|
|
792
|
-
return false
|
|
793
|
-
end
|
|
794
|
-
|
|
795
954
|
function __TS__InstanceOfObject(value)
|
|
796
955
|
local valueType = type(value)
|
|
797
956
|
return (valueType == "table") or (valueType == "function")
|
|
@@ -831,11 +990,7 @@ function __TS__Iterator(iterable)
|
|
|
831
990
|
local iterator = iterable[Symbol.iterator](iterable)
|
|
832
991
|
return __TS__IteratorIteratorStep, iterator
|
|
833
992
|
else
|
|
834
|
-
return
|
|
835
|
-
{
|
|
836
|
-
ipairs(iterable)
|
|
837
|
-
}
|
|
838
|
-
)
|
|
993
|
+
return ipairs(iterable)
|
|
839
994
|
end
|
|
840
995
|
end
|
|
841
996
|
|
|
@@ -1041,118 +1196,30 @@ function __TS__NumberToString(self, radix)
|
|
|
1041
1196
|
else
|
|
1042
1197
|
repeat
|
|
1043
1198
|
do
|
|
1044
|
-
result =
|
|
1045
|
-
__TS__StringAccess(____radixChars, integer % radix)
|
|
1046
|
-
) .. tostring(result)
|
|
1199
|
+
result = __TS__StringAccess(____radixChars, integer % radix) .. result
|
|
1047
1200
|
integer = math.floor(integer / radix)
|
|
1048
1201
|
end
|
|
1049
1202
|
until not (integer ~= 0)
|
|
1050
1203
|
end
|
|
1051
1204
|
if fraction ~= 0 then
|
|
1052
|
-
result =
|
|
1205
|
+
result = result .. "."
|
|
1053
1206
|
local delta = 1e-16
|
|
1054
1207
|
repeat
|
|
1055
1208
|
do
|
|
1056
1209
|
fraction = fraction * radix
|
|
1057
1210
|
delta = delta * radix
|
|
1058
1211
|
local digit = math.floor(fraction)
|
|
1059
|
-
result =
|
|
1060
|
-
__TS__StringAccess(____radixChars, digit)
|
|
1061
|
-
)
|
|
1212
|
+
result = result .. __TS__StringAccess(____radixChars, digit)
|
|
1062
1213
|
fraction = fraction - digit
|
|
1063
1214
|
end
|
|
1064
1215
|
until not (fraction >= delta)
|
|
1065
1216
|
end
|
|
1066
1217
|
if self < 0 then
|
|
1067
|
-
result = "-" ..
|
|
1218
|
+
result = "-" .. result
|
|
1068
1219
|
end
|
|
1069
1220
|
return result
|
|
1070
1221
|
end
|
|
1071
1222
|
|
|
1072
|
-
function __TS__ObjectAssign(to, ...)
|
|
1073
|
-
local sources = {...}
|
|
1074
|
-
if to == nil then
|
|
1075
|
-
return to
|
|
1076
|
-
end
|
|
1077
|
-
for ____, source in ipairs(sources) do
|
|
1078
|
-
for key in pairs(source) do
|
|
1079
|
-
to[key] = source[key]
|
|
1080
|
-
end
|
|
1081
|
-
end
|
|
1082
|
-
return to
|
|
1083
|
-
end
|
|
1084
|
-
|
|
1085
|
-
function ____descriptorIndex(self, key)
|
|
1086
|
-
local value = rawget(self, key)
|
|
1087
|
-
if value ~= nil then
|
|
1088
|
-
return value
|
|
1089
|
-
end
|
|
1090
|
-
local metatable = getmetatable(self)
|
|
1091
|
-
while metatable do
|
|
1092
|
-
local rawResult = rawget(metatable, key)
|
|
1093
|
-
if rawResult ~= nil then
|
|
1094
|
-
return rawResult
|
|
1095
|
-
end
|
|
1096
|
-
local descriptors = rawget(metatable, "_descriptors")
|
|
1097
|
-
if descriptors then
|
|
1098
|
-
local descriptor = descriptors[key]
|
|
1099
|
-
if descriptor then
|
|
1100
|
-
if descriptor.get then
|
|
1101
|
-
return descriptor.get(self)
|
|
1102
|
-
end
|
|
1103
|
-
return descriptor.value
|
|
1104
|
-
end
|
|
1105
|
-
end
|
|
1106
|
-
metatable = getmetatable(metatable)
|
|
1107
|
-
end
|
|
1108
|
-
end
|
|
1109
|
-
function ____descriptorNewindex(self, key, value)
|
|
1110
|
-
local metatable = getmetatable(self)
|
|
1111
|
-
while metatable do
|
|
1112
|
-
local descriptors = rawget(metatable, "_descriptors")
|
|
1113
|
-
if descriptors then
|
|
1114
|
-
local descriptor = descriptors[key]
|
|
1115
|
-
if descriptor then
|
|
1116
|
-
if descriptor.set then
|
|
1117
|
-
descriptor.set(self, value)
|
|
1118
|
-
else
|
|
1119
|
-
if descriptor.writable == false then
|
|
1120
|
-
error(
|
|
1121
|
-
((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
|
|
1122
|
-
0
|
|
1123
|
-
)
|
|
1124
|
-
end
|
|
1125
|
-
descriptor.value = value
|
|
1126
|
-
end
|
|
1127
|
-
return
|
|
1128
|
-
end
|
|
1129
|
-
end
|
|
1130
|
-
metatable = getmetatable(metatable)
|
|
1131
|
-
end
|
|
1132
|
-
rawset(self, key, value)
|
|
1133
|
-
end
|
|
1134
|
-
function __TS__SetDescriptor(target, key, desc, isPrototype)
|
|
1135
|
-
if isPrototype == nil then
|
|
1136
|
-
isPrototype = false
|
|
1137
|
-
end
|
|
1138
|
-
local metatable = ((isPrototype and (function() return target end)) or (function() return getmetatable(target) end))()
|
|
1139
|
-
if not metatable then
|
|
1140
|
-
metatable = {}
|
|
1141
|
-
setmetatable(target, metatable)
|
|
1142
|
-
end
|
|
1143
|
-
local value = rawget(target, key)
|
|
1144
|
-
if value ~= nil then
|
|
1145
|
-
rawset(target, key, nil)
|
|
1146
|
-
end
|
|
1147
|
-
if not rawget(metatable, "_descriptors") then
|
|
1148
|
-
metatable._descriptors = {}
|
|
1149
|
-
end
|
|
1150
|
-
local descriptor = __TS__CloneDescriptor(desc)
|
|
1151
|
-
metatable._descriptors[key] = descriptor
|
|
1152
|
-
metatable.__index = ____descriptorIndex
|
|
1153
|
-
metatable.__newindex = ____descriptorNewindex
|
|
1154
|
-
end
|
|
1155
|
-
|
|
1156
1223
|
function __TS__ObjectDefineProperty(target, key, desc)
|
|
1157
1224
|
local luaKey = (((type(key) == "number") and (function() return key + 1 end)) or (function() return key end))()
|
|
1158
1225
|
local value = rawget(target, luaKey)
|
|
@@ -1210,17 +1277,6 @@ function __TS__ObjectFromEntries(entries)
|
|
|
1210
1277
|
return obj
|
|
1211
1278
|
end
|
|
1212
1279
|
|
|
1213
|
-
function __TS__ObjectGetOwnPropertyDescriptor(object, key)
|
|
1214
|
-
local metatable = getmetatable(object)
|
|
1215
|
-
if not metatable then
|
|
1216
|
-
return
|
|
1217
|
-
end
|
|
1218
|
-
if not rawget(metatable, "_descriptors") then
|
|
1219
|
-
return
|
|
1220
|
-
end
|
|
1221
|
-
return rawget(metatable, "_descriptors")[key]
|
|
1222
|
-
end
|
|
1223
|
-
|
|
1224
1280
|
function __TS__ObjectKeys(obj)
|
|
1225
1281
|
local result = {}
|
|
1226
1282
|
for key in pairs(obj) do
|
|
@@ -1261,11 +1317,13 @@ function __TS__OptionalFunctionCall(f, ...)
|
|
|
1261
1317
|
return nil
|
|
1262
1318
|
end
|
|
1263
1319
|
|
|
1264
|
-
function __TS__OptionalMethodCall(____table, methodName, ...)
|
|
1320
|
+
function __TS__OptionalMethodCall(____table, methodName, isMethodOptional, ...)
|
|
1265
1321
|
if ____table then
|
|
1266
1322
|
local method = ____table[methodName]
|
|
1267
1323
|
if method then
|
|
1268
1324
|
return method(____table, ...)
|
|
1325
|
+
elseif not isMethodOptional then
|
|
1326
|
+
error(methodName .. " is not a function", 0)
|
|
1269
1327
|
end
|
|
1270
1328
|
end
|
|
1271
1329
|
return nil
|
|
@@ -1282,6 +1340,40 @@ function __TS__ParseFloat(numberString)
|
|
|
1282
1340
|
return number or (0 / 0)
|
|
1283
1341
|
end
|
|
1284
1342
|
|
|
1343
|
+
function __TS__StringSubstr(self, from, length)
|
|
1344
|
+
if from ~= from then
|
|
1345
|
+
from = 0
|
|
1346
|
+
end
|
|
1347
|
+
if length ~= nil then
|
|
1348
|
+
if (length ~= length) or (length <= 0) then
|
|
1349
|
+
return ""
|
|
1350
|
+
end
|
|
1351
|
+
length = length + from
|
|
1352
|
+
end
|
|
1353
|
+
if from >= 0 then
|
|
1354
|
+
from = from + 1
|
|
1355
|
+
end
|
|
1356
|
+
return string.sub(self, from, length)
|
|
1357
|
+
end
|
|
1358
|
+
|
|
1359
|
+
function __TS__StringSubstring(self, start, ____end)
|
|
1360
|
+
if ____end ~= ____end then
|
|
1361
|
+
____end = 0
|
|
1362
|
+
end
|
|
1363
|
+
if (____end ~= nil) and (start > ____end) then
|
|
1364
|
+
start, ____end = ____end, start
|
|
1365
|
+
end
|
|
1366
|
+
if start >= 0 then
|
|
1367
|
+
start = start + 1
|
|
1368
|
+
else
|
|
1369
|
+
start = 1
|
|
1370
|
+
end
|
|
1371
|
+
if (____end ~= nil) and (____end < 0) then
|
|
1372
|
+
____end = 0
|
|
1373
|
+
end
|
|
1374
|
+
return string.sub(self, start, ____end)
|
|
1375
|
+
end
|
|
1376
|
+
|
|
1285
1377
|
__TS__parseInt_base_pattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
|
|
1286
1378
|
function __TS__ParseInt(numberString, base)
|
|
1287
1379
|
if base == nil then
|
|
@@ -1289,9 +1381,7 @@ function __TS__ParseInt(numberString, base)
|
|
|
1289
1381
|
local hexMatch = string.match(numberString, "^%s*-?0[xX]")
|
|
1290
1382
|
if hexMatch then
|
|
1291
1383
|
base = 16
|
|
1292
|
-
numberString = ((string.match(hexMatch, "-") and (function() return "-" ..
|
|
1293
|
-
__TS__StringSubstr(numberString, #hexMatch)
|
|
1294
|
-
) end)) or (function() return __TS__StringSubstr(numberString, #hexMatch) end))()
|
|
1384
|
+
numberString = ((string.match(hexMatch, "-") and (function() return "-" .. __TS__StringSubstr(numberString, #hexMatch) end)) or (function() return __TS__StringSubstr(numberString, #hexMatch) end))()
|
|
1295
1385
|
end
|
|
1296
1386
|
end
|
|
1297
1387
|
if (base < 2) or (base > 36) then
|
|
@@ -1313,6 +1403,344 @@ function __TS__ParseInt(numberString, base)
|
|
|
1313
1403
|
end
|
|
1314
1404
|
end
|
|
1315
1405
|
|
|
1406
|
+
__TS__PromiseState = __TS__PromiseState or ({})
|
|
1407
|
+
__TS__PromiseState.Pending = 0
|
|
1408
|
+
__TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
|
|
1409
|
+
__TS__PromiseState.Fulfilled = 1
|
|
1410
|
+
__TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
|
|
1411
|
+
__TS__PromiseState.Rejected = 2
|
|
1412
|
+
__TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
|
|
1413
|
+
function __TS__PromiseDeferred(self)
|
|
1414
|
+
local resolve
|
|
1415
|
+
local reject
|
|
1416
|
+
local promise = __TS__New(
|
|
1417
|
+
__TS__Promise,
|
|
1418
|
+
function(____, res, rej)
|
|
1419
|
+
resolve = res
|
|
1420
|
+
reject = rej
|
|
1421
|
+
end
|
|
1422
|
+
)
|
|
1423
|
+
return {promise = promise, resolve = resolve, reject = reject}
|
|
1424
|
+
end
|
|
1425
|
+
function __TS__IsPromiseLike(self, thing)
|
|
1426
|
+
return __TS__InstanceOf(thing, __TS__Promise)
|
|
1427
|
+
end
|
|
1428
|
+
__TS__Promise = __TS__Class()
|
|
1429
|
+
__TS__Promise.name = "__TS__Promise"
|
|
1430
|
+
function __TS__Promise.prototype.____constructor(self, executor)
|
|
1431
|
+
self.state = __TS__PromiseState.Pending
|
|
1432
|
+
self.fulfilledCallbacks = {}
|
|
1433
|
+
self.rejectedCallbacks = {}
|
|
1434
|
+
self.finallyCallbacks = {}
|
|
1435
|
+
do
|
|
1436
|
+
local function ____catch(e)
|
|
1437
|
+
self:reject(e)
|
|
1438
|
+
end
|
|
1439
|
+
local ____try, ____hasReturned = pcall(
|
|
1440
|
+
function()
|
|
1441
|
+
executor(
|
|
1442
|
+
_G,
|
|
1443
|
+
__TS__FunctionBind(self.resolve, self),
|
|
1444
|
+
__TS__FunctionBind(self.reject, self)
|
|
1445
|
+
)
|
|
1446
|
+
end
|
|
1447
|
+
)
|
|
1448
|
+
if not ____try then
|
|
1449
|
+
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
|
1450
|
+
end
|
|
1451
|
+
end
|
|
1452
|
+
end
|
|
1453
|
+
function __TS__Promise.resolve(data)
|
|
1454
|
+
local promise = __TS__New(
|
|
1455
|
+
__TS__Promise,
|
|
1456
|
+
function()
|
|
1457
|
+
end
|
|
1458
|
+
)
|
|
1459
|
+
promise.state = __TS__PromiseState.Fulfilled
|
|
1460
|
+
promise.value = data
|
|
1461
|
+
return promise
|
|
1462
|
+
end
|
|
1463
|
+
function __TS__Promise.reject(reason)
|
|
1464
|
+
local promise = __TS__New(
|
|
1465
|
+
__TS__Promise,
|
|
1466
|
+
function()
|
|
1467
|
+
end
|
|
1468
|
+
)
|
|
1469
|
+
promise.state = __TS__PromiseState.Rejected
|
|
1470
|
+
promise.rejectionReason = reason
|
|
1471
|
+
return promise
|
|
1472
|
+
end
|
|
1473
|
+
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
1474
|
+
local ____ = __TS__PromiseDeferred(_G)
|
|
1475
|
+
local promise = ____.promise
|
|
1476
|
+
local resolve = ____.resolve
|
|
1477
|
+
local reject = ____.reject
|
|
1478
|
+
local isFulfilled = self.state == __TS__PromiseState.Fulfilled
|
|
1479
|
+
local isRejected = self.state == __TS__PromiseState.Rejected
|
|
1480
|
+
if onFulfilled then
|
|
1481
|
+
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
|
|
1482
|
+
__TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
|
|
1483
|
+
if isFulfilled then
|
|
1484
|
+
internalCallback(_G, self.value)
|
|
1485
|
+
end
|
|
1486
|
+
else
|
|
1487
|
+
__TS__ArrayPush(
|
|
1488
|
+
self.fulfilledCallbacks,
|
|
1489
|
+
function() return resolve(_G, nil) end
|
|
1490
|
+
)
|
|
1491
|
+
end
|
|
1492
|
+
if onRejected then
|
|
1493
|
+
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
1494
|
+
__TS__ArrayPush(self.rejectedCallbacks, internalCallback)
|
|
1495
|
+
if isRejected then
|
|
1496
|
+
internalCallback(_G, self.rejectionReason)
|
|
1497
|
+
end
|
|
1498
|
+
end
|
|
1499
|
+
if isFulfilled then
|
|
1500
|
+
resolve(_G, self.value)
|
|
1501
|
+
end
|
|
1502
|
+
if isRejected then
|
|
1503
|
+
reject(_G, self.rejectionReason)
|
|
1504
|
+
end
|
|
1505
|
+
return promise
|
|
1506
|
+
end
|
|
1507
|
+
function __TS__Promise.prototype.catch(self, onRejected)
|
|
1508
|
+
return self["then"](self, nil, onRejected)
|
|
1509
|
+
end
|
|
1510
|
+
function __TS__Promise.prototype.finally(self, onFinally)
|
|
1511
|
+
if onFinally then
|
|
1512
|
+
__TS__ArrayPush(self.finallyCallbacks, onFinally)
|
|
1513
|
+
if self.state ~= __TS__PromiseState.Pending then
|
|
1514
|
+
onFinally(_G)
|
|
1515
|
+
end
|
|
1516
|
+
end
|
|
1517
|
+
return self
|
|
1518
|
+
end
|
|
1519
|
+
function __TS__Promise.prototype.resolve(self, data)
|
|
1520
|
+
if self.state == __TS__PromiseState.Pending then
|
|
1521
|
+
self.state = __TS__PromiseState.Fulfilled
|
|
1522
|
+
self.value = data
|
|
1523
|
+
for ____, callback in ipairs(self.fulfilledCallbacks) do
|
|
1524
|
+
callback(_G, data)
|
|
1525
|
+
end
|
|
1526
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1527
|
+
callback(_G)
|
|
1528
|
+
end
|
|
1529
|
+
end
|
|
1530
|
+
end
|
|
1531
|
+
function __TS__Promise.prototype.reject(self, reason)
|
|
1532
|
+
if self.state == __TS__PromiseState.Pending then
|
|
1533
|
+
self.state = __TS__PromiseState.Rejected
|
|
1534
|
+
self.rejectionReason = reason
|
|
1535
|
+
for ____, callback in ipairs(self.rejectedCallbacks) do
|
|
1536
|
+
callback(_G, reason)
|
|
1537
|
+
end
|
|
1538
|
+
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
1539
|
+
callback(_G)
|
|
1540
|
+
end
|
|
1541
|
+
end
|
|
1542
|
+
end
|
|
1543
|
+
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
1544
|
+
return function(____, value)
|
|
1545
|
+
do
|
|
1546
|
+
local function ____catch(e)
|
|
1547
|
+
reject(_G, e)
|
|
1548
|
+
end
|
|
1549
|
+
local ____try, ____hasReturned = pcall(
|
|
1550
|
+
function()
|
|
1551
|
+
self:handleCallbackData(
|
|
1552
|
+
f(_G, value),
|
|
1553
|
+
resolve,
|
|
1554
|
+
reject
|
|
1555
|
+
)
|
|
1556
|
+
end
|
|
1557
|
+
)
|
|
1558
|
+
if not ____try then
|
|
1559
|
+
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
|
1560
|
+
end
|
|
1561
|
+
end
|
|
1562
|
+
end
|
|
1563
|
+
end
|
|
1564
|
+
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
|
|
1565
|
+
if __TS__IsPromiseLike(_G, data) then
|
|
1566
|
+
local nextpromise = data
|
|
1567
|
+
if nextpromise.state == __TS__PromiseState.Fulfilled then
|
|
1568
|
+
resolve(_G, nextpromise.value)
|
|
1569
|
+
elseif nextpromise.state == __TS__PromiseState.Rejected then
|
|
1570
|
+
reject(_G, nextpromise.rejectionReason)
|
|
1571
|
+
else
|
|
1572
|
+
data["then"](data, resolve, reject)
|
|
1573
|
+
end
|
|
1574
|
+
else
|
|
1575
|
+
resolve(_G, data)
|
|
1576
|
+
end
|
|
1577
|
+
end
|
|
1578
|
+
|
|
1579
|
+
function __TS__PromiseAll(iterable)
|
|
1580
|
+
local results = {}
|
|
1581
|
+
local toResolve = {}
|
|
1582
|
+
local numToResolve = 0
|
|
1583
|
+
local i = 0
|
|
1584
|
+
for ____, item in __TS__Iterator(iterable) do
|
|
1585
|
+
if __TS__InstanceOf(item, __TS__Promise) then
|
|
1586
|
+
if item.state == __TS__PromiseState.Fulfilled then
|
|
1587
|
+
results[i + 1] = item.value
|
|
1588
|
+
elseif item.state == __TS__PromiseState.Rejected then
|
|
1589
|
+
return __TS__Promise.reject(item.rejectionReason)
|
|
1590
|
+
else
|
|
1591
|
+
numToResolve = numToResolve + 1
|
|
1592
|
+
toResolve[i] = item
|
|
1593
|
+
end
|
|
1594
|
+
else
|
|
1595
|
+
results[i + 1] = item
|
|
1596
|
+
end
|
|
1597
|
+
i = i + 1
|
|
1598
|
+
end
|
|
1599
|
+
if numToResolve == 0 then
|
|
1600
|
+
return __TS__Promise.resolve(results)
|
|
1601
|
+
end
|
|
1602
|
+
return __TS__New(
|
|
1603
|
+
__TS__Promise,
|
|
1604
|
+
function(____, resolve, reject)
|
|
1605
|
+
for index, promise in pairs(toResolve) do
|
|
1606
|
+
promise["then"](
|
|
1607
|
+
promise,
|
|
1608
|
+
function(____, data)
|
|
1609
|
+
results[index + 1] = data
|
|
1610
|
+
numToResolve = numToResolve - 1
|
|
1611
|
+
if numToResolve == 0 then
|
|
1612
|
+
resolve(_G, results)
|
|
1613
|
+
end
|
|
1614
|
+
end,
|
|
1615
|
+
function(____, reason)
|
|
1616
|
+
reject(_G, reason)
|
|
1617
|
+
end
|
|
1618
|
+
)
|
|
1619
|
+
end
|
|
1620
|
+
end
|
|
1621
|
+
)
|
|
1622
|
+
end
|
|
1623
|
+
|
|
1624
|
+
function __TS__PromiseAllSettled(iterable)
|
|
1625
|
+
local results = {}
|
|
1626
|
+
local toResolve = {}
|
|
1627
|
+
local numToResolve = 0
|
|
1628
|
+
local i = 0
|
|
1629
|
+
for ____, item in __TS__Iterator(iterable) do
|
|
1630
|
+
if __TS__InstanceOf(item, __TS__Promise) then
|
|
1631
|
+
if item.state == __TS__PromiseState.Fulfilled then
|
|
1632
|
+
results[i + 1] = {status = "fulfilled", value = item.value}
|
|
1633
|
+
elseif item.state == __TS__PromiseState.Rejected then
|
|
1634
|
+
results[i + 1] = {status = "rejected", reason = item.rejectionReason}
|
|
1635
|
+
else
|
|
1636
|
+
numToResolve = numToResolve + 1
|
|
1637
|
+
toResolve[i] = item
|
|
1638
|
+
end
|
|
1639
|
+
else
|
|
1640
|
+
results[i + 1] = {status = "fulfilled", value = item}
|
|
1641
|
+
end
|
|
1642
|
+
i = i + 1
|
|
1643
|
+
end
|
|
1644
|
+
if numToResolve == 0 then
|
|
1645
|
+
return __TS__Promise.resolve(results)
|
|
1646
|
+
end
|
|
1647
|
+
return __TS__New(
|
|
1648
|
+
__TS__Promise,
|
|
1649
|
+
function(____, resolve)
|
|
1650
|
+
for index, promise in pairs(toResolve) do
|
|
1651
|
+
promise["then"](
|
|
1652
|
+
promise,
|
|
1653
|
+
function(____, data)
|
|
1654
|
+
results[index + 1] = {status = "fulfilled", value = data}
|
|
1655
|
+
numToResolve = numToResolve - 1
|
|
1656
|
+
if numToResolve == 0 then
|
|
1657
|
+
resolve(_G, results)
|
|
1658
|
+
end
|
|
1659
|
+
end,
|
|
1660
|
+
function(____, reason)
|
|
1661
|
+
results[index + 1] = {status = "rejected", reason = reason}
|
|
1662
|
+
numToResolve = numToResolve - 1
|
|
1663
|
+
if numToResolve == 0 then
|
|
1664
|
+
resolve(_G, results)
|
|
1665
|
+
end
|
|
1666
|
+
end
|
|
1667
|
+
)
|
|
1668
|
+
end
|
|
1669
|
+
end
|
|
1670
|
+
)
|
|
1671
|
+
end
|
|
1672
|
+
|
|
1673
|
+
function __TS__PromiseAny(iterable)
|
|
1674
|
+
local rejections = {}
|
|
1675
|
+
local pending = {}
|
|
1676
|
+
for ____, item in __TS__Iterator(iterable) do
|
|
1677
|
+
if __TS__InstanceOf(item, __TS__Promise) then
|
|
1678
|
+
if item.state == __TS__PromiseState.Fulfilled then
|
|
1679
|
+
return __TS__Promise.resolve(item.value)
|
|
1680
|
+
elseif item.state == __TS__PromiseState.Rejected then
|
|
1681
|
+
__TS__ArrayPush(rejections, item.rejectionReason)
|
|
1682
|
+
else
|
|
1683
|
+
__TS__ArrayPush(pending, item)
|
|
1684
|
+
end
|
|
1685
|
+
else
|
|
1686
|
+
return __TS__Promise.resolve(item)
|
|
1687
|
+
end
|
|
1688
|
+
end
|
|
1689
|
+
if #pending == 0 then
|
|
1690
|
+
return __TS__Promise.reject("No promises to resolve with .any()")
|
|
1691
|
+
end
|
|
1692
|
+
local numResolved = 0
|
|
1693
|
+
return __TS__New(
|
|
1694
|
+
__TS__Promise,
|
|
1695
|
+
function(____, resolve, reject)
|
|
1696
|
+
for ____, promise in ipairs(pending) do
|
|
1697
|
+
promise["then"](
|
|
1698
|
+
promise,
|
|
1699
|
+
function(____, data)
|
|
1700
|
+
resolve(_G, data)
|
|
1701
|
+
end,
|
|
1702
|
+
function(____, reason)
|
|
1703
|
+
__TS__ArrayPush(rejections, reason)
|
|
1704
|
+
numResolved = numResolved + 1
|
|
1705
|
+
if numResolved == #pending then
|
|
1706
|
+
reject(_G, {name = "AggregateError", message = "All Promises rejected", errors = rejections})
|
|
1707
|
+
end
|
|
1708
|
+
end
|
|
1709
|
+
)
|
|
1710
|
+
end
|
|
1711
|
+
end
|
|
1712
|
+
)
|
|
1713
|
+
end
|
|
1714
|
+
|
|
1715
|
+
function __TS__PromiseRace(iterable)
|
|
1716
|
+
local pending = {}
|
|
1717
|
+
for ____, item in __TS__Iterator(iterable) do
|
|
1718
|
+
if __TS__InstanceOf(item, __TS__Promise) then
|
|
1719
|
+
if item.state == __TS__PromiseState.Fulfilled then
|
|
1720
|
+
return __TS__Promise.resolve(item.value)
|
|
1721
|
+
elseif item.state == __TS__PromiseState.Rejected then
|
|
1722
|
+
return __TS__Promise.reject(item.rejectionReason)
|
|
1723
|
+
else
|
|
1724
|
+
__TS__ArrayPush(pending, item)
|
|
1725
|
+
end
|
|
1726
|
+
else
|
|
1727
|
+
return __TS__Promise.resolve(item)
|
|
1728
|
+
end
|
|
1729
|
+
end
|
|
1730
|
+
return __TS__New(
|
|
1731
|
+
__TS__Promise,
|
|
1732
|
+
function(____, resolve, reject)
|
|
1733
|
+
for ____, promise in ipairs(pending) do
|
|
1734
|
+
promise["then"](
|
|
1735
|
+
promise,
|
|
1736
|
+
function(____, value) return resolve(_G, value) end,
|
|
1737
|
+
function(____, reason) return reject(_G, reason) end
|
|
1738
|
+
)
|
|
1739
|
+
end
|
|
1740
|
+
end
|
|
1741
|
+
)
|
|
1742
|
+
end
|
|
1743
|
+
|
|
1316
1744
|
Set = (function()
|
|
1317
1745
|
local Set = __TS__Class()
|
|
1318
1746
|
Set.name = "Set"
|
|
@@ -1549,16 +1977,26 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
1549
1977
|
if type(trace) ~= "string" then
|
|
1550
1978
|
return trace
|
|
1551
1979
|
end
|
|
1552
|
-
local
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
return (file .. ".ts:") .. tostring(fileSourceMap[line])
|
|
1980
|
+
local function replacer(____, file, srcFile, line)
|
|
1981
|
+
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
1982
|
+
if fileSourceMap and fileSourceMap[line] then
|
|
1983
|
+
local data = fileSourceMap[line]
|
|
1984
|
+
if type(data) == "number" then
|
|
1985
|
+
return (srcFile .. ":") .. tostring(data)
|
|
1559
1986
|
end
|
|
1560
|
-
return (file .. "
|
|
1987
|
+
return (tostring(data.file) .. ":") .. tostring(data.line)
|
|
1561
1988
|
end
|
|
1989
|
+
return (file .. ":") .. line
|
|
1990
|
+
end
|
|
1991
|
+
local result = string.gsub(
|
|
1992
|
+
trace,
|
|
1993
|
+
"(%S+)%.lua:(%d+)",
|
|
1994
|
+
function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
|
|
1995
|
+
)
|
|
1996
|
+
result = string.gsub(
|
|
1997
|
+
result,
|
|
1998
|
+
"(%[string \"[^\"]+\"%]):(%d+)",
|
|
1999
|
+
function(file, line) return replacer(_G, file, "unknown", line) end
|
|
1562
2000
|
)
|
|
1563
2001
|
return result
|
|
1564
2002
|
end
|
|
@@ -1583,12 +2021,6 @@ function __TS__Spread(iterable)
|
|
|
1583
2021
|
return __TS__Unpack(arr)
|
|
1584
2022
|
end
|
|
1585
2023
|
|
|
1586
|
-
function __TS__StringAccess(self, index)
|
|
1587
|
-
if (index >= 0) and (index < #self) then
|
|
1588
|
-
return string.sub(self, index + 1, index + 1)
|
|
1589
|
-
end
|
|
1590
|
-
end
|
|
1591
|
-
|
|
1592
2024
|
function __TS__StringCharAt(self, pos)
|
|
1593
2025
|
if pos ~= pos then
|
|
1594
2026
|
pos = 0
|
|
@@ -1613,7 +2045,7 @@ function __TS__StringConcat(str1, ...)
|
|
|
1613
2045
|
local args = {...}
|
|
1614
2046
|
local out = str1
|
|
1615
2047
|
for ____, arg in ipairs(args) do
|
|
1616
|
-
out =
|
|
2048
|
+
out = out .. arg
|
|
1617
2049
|
end
|
|
1618
2050
|
return out
|
|
1619
2051
|
end
|
|
@@ -1650,19 +2082,15 @@ function __TS__StringPadEnd(self, maxLength, fillString)
|
|
|
1650
2082
|
end
|
|
1651
2083
|
maxLength = maxLength - #self
|
|
1652
2084
|
if maxLength > #fillString then
|
|
1653
|
-
fillString =
|
|
1654
|
-
string.rep(
|
|
1655
|
-
fillString,
|
|
1656
|
-
math.floor(maxLength / #fillString)
|
|
1657
|
-
)
|
|
1658
|
-
)
|
|
1659
|
-
end
|
|
1660
|
-
return tostring(self) .. tostring(
|
|
1661
|
-
string.sub(
|
|
2085
|
+
fillString = fillString .. string.rep(
|
|
1662
2086
|
fillString,
|
|
1663
|
-
|
|
1664
|
-
math.floor(maxLength)
|
|
2087
|
+
math.floor(maxLength / #fillString)
|
|
1665
2088
|
)
|
|
2089
|
+
end
|
|
2090
|
+
return self .. string.sub(
|
|
2091
|
+
fillString,
|
|
2092
|
+
1,
|
|
2093
|
+
math.floor(maxLength)
|
|
1666
2094
|
)
|
|
1667
2095
|
end
|
|
1668
2096
|
|
|
@@ -1681,37 +2109,64 @@ function __TS__StringPadStart(self, maxLength, fillString)
|
|
|
1681
2109
|
end
|
|
1682
2110
|
maxLength = maxLength - #self
|
|
1683
2111
|
if maxLength > #fillString then
|
|
1684
|
-
fillString =
|
|
1685
|
-
string.rep(
|
|
1686
|
-
fillString,
|
|
1687
|
-
math.floor(maxLength / #fillString)
|
|
1688
|
-
)
|
|
1689
|
-
)
|
|
1690
|
-
end
|
|
1691
|
-
return tostring(
|
|
1692
|
-
string.sub(
|
|
2112
|
+
fillString = fillString .. string.rep(
|
|
1693
2113
|
fillString,
|
|
1694
|
-
|
|
1695
|
-
math.floor(maxLength)
|
|
2114
|
+
math.floor(maxLength / #fillString)
|
|
1696
2115
|
)
|
|
1697
|
-
|
|
2116
|
+
end
|
|
2117
|
+
return string.sub(
|
|
2118
|
+
fillString,
|
|
2119
|
+
1,
|
|
2120
|
+
math.floor(maxLength)
|
|
2121
|
+
) .. self
|
|
1698
2122
|
end
|
|
1699
2123
|
|
|
1700
2124
|
function __TS__StringReplace(source, searchValue, replaceValue)
|
|
1701
|
-
|
|
2125
|
+
local startPos, endPos = string.find(source, searchValue, nil, true)
|
|
2126
|
+
if not startPos then
|
|
2127
|
+
return source
|
|
2128
|
+
end
|
|
2129
|
+
local sub = string.sub
|
|
2130
|
+
local before = sub(source, 1, startPos - 1)
|
|
2131
|
+
local replacement = (((type(replaceValue) == "string") and (function() return replaceValue end)) or (function() return replaceValue(_G, searchValue, startPos - 1, source) end))()
|
|
2132
|
+
local after = sub(source, endPos + 1)
|
|
2133
|
+
return (before .. replacement) .. after
|
|
2134
|
+
end
|
|
2135
|
+
|
|
2136
|
+
function __TS__StringReplaceAll(source, searchValue, replaceValue)
|
|
2137
|
+
local replacer
|
|
1702
2138
|
if type(replaceValue) == "string" then
|
|
1703
|
-
|
|
1704
|
-
local result = string.gsub(source, searchValue, replaceValue, 1)
|
|
1705
|
-
return result
|
|
2139
|
+
replacer = function() return replaceValue end
|
|
1706
2140
|
else
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
2141
|
+
replacer = replaceValue
|
|
2142
|
+
end
|
|
2143
|
+
local parts = {}
|
|
2144
|
+
local partsIndex = 1
|
|
2145
|
+
local sub = string.sub
|
|
2146
|
+
if #searchValue == 0 then
|
|
2147
|
+
parts[1] = replacer(_G, "", 0, source)
|
|
2148
|
+
partsIndex = 2
|
|
2149
|
+
for i = 1, #source do
|
|
2150
|
+
parts[partsIndex] = sub(source, i, i)
|
|
2151
|
+
parts[partsIndex + 1] = replacer(_G, "", i, source)
|
|
2152
|
+
partsIndex = partsIndex + 2
|
|
2153
|
+
end
|
|
2154
|
+
else
|
|
2155
|
+
local find = string.find
|
|
2156
|
+
local currentPos = 1
|
|
2157
|
+
while true do
|
|
2158
|
+
local startPos, endPos = find(source, searchValue, currentPos, true)
|
|
2159
|
+
if not startPos then
|
|
2160
|
+
break
|
|
2161
|
+
end
|
|
2162
|
+
parts[partsIndex] = sub(source, currentPos, startPos - 1)
|
|
2163
|
+
parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
|
|
2164
|
+
partsIndex = partsIndex + 2
|
|
2165
|
+
currentPos = endPos + 1
|
|
2166
|
+
end
|
|
2167
|
+
parts[partsIndex] = sub(source, currentPos)
|
|
1714
2168
|
end
|
|
2169
|
+
return table.concat(parts)
|
|
1715
2170
|
end
|
|
1716
2171
|
|
|
1717
2172
|
function __TS__StringSlice(self, start, ____end)
|
|
@@ -1730,24 +2185,6 @@ function __TS__StringSlice(self, start, ____end)
|
|
|
1730
2185
|
return string.sub(self, start, ____end)
|
|
1731
2186
|
end
|
|
1732
2187
|
|
|
1733
|
-
function __TS__StringSubstring(self, start, ____end)
|
|
1734
|
-
if ____end ~= ____end then
|
|
1735
|
-
____end = 0
|
|
1736
|
-
end
|
|
1737
|
-
if (____end ~= nil) and (start > ____end) then
|
|
1738
|
-
start, ____end = __TS__Unpack({____end, start})
|
|
1739
|
-
end
|
|
1740
|
-
if start >= 0 then
|
|
1741
|
-
start = start + 1
|
|
1742
|
-
else
|
|
1743
|
-
start = 1
|
|
1744
|
-
end
|
|
1745
|
-
if (____end ~= nil) and (____end < 0) then
|
|
1746
|
-
____end = 0
|
|
1747
|
-
end
|
|
1748
|
-
return string.sub(self, start, ____end)
|
|
1749
|
-
end
|
|
1750
|
-
|
|
1751
2188
|
function __TS__StringSplit(source, separator, limit)
|
|
1752
2189
|
if limit == nil then
|
|
1753
2190
|
limit = 4294967295
|
|
@@ -1792,22 +2229,6 @@ function __TS__StringStartsWith(self, searchString, position)
|
|
|
1792
2229
|
return string.sub(self, position + 1, #searchString + position) == searchString
|
|
1793
2230
|
end
|
|
1794
2231
|
|
|
1795
|
-
function __TS__StringSubstr(self, from, length)
|
|
1796
|
-
if from ~= from then
|
|
1797
|
-
from = 0
|
|
1798
|
-
end
|
|
1799
|
-
if length ~= nil then
|
|
1800
|
-
if (length ~= length) or (length <= 0) then
|
|
1801
|
-
return ""
|
|
1802
|
-
end
|
|
1803
|
-
length = length + from
|
|
1804
|
-
end
|
|
1805
|
-
if from >= 0 then
|
|
1806
|
-
from = from + 1
|
|
1807
|
-
end
|
|
1808
|
-
return string.sub(self, from, length)
|
|
1809
|
-
end
|
|
1810
|
-
|
|
1811
2232
|
function __TS__StringTrim(self)
|
|
1812
2233
|
local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
|
|
1813
2234
|
return result
|