typescript-to-lua 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LuaLib.d.ts +2 -0
- package/dist/LuaLib.js +2 -0
- package/dist/lualib/5.0/Await.lua +42 -42
- package/dist/lualib/5.0/DescriptorGet.lua +24 -0
- package/dist/lualib/5.0/DescriptorSet.lua +30 -0
- package/dist/lualib/5.0/Promise.lua +83 -109
- package/dist/lualib/5.0/SetDescriptor.lua +12 -45
- package/dist/lualib/5.0/lualib_bundle.lua +180 -181
- package/dist/lualib/5.0/lualib_module_info.json +14 -4
- package/dist/lualib/universal/Await.lua +42 -42
- package/dist/lualib/universal/DescriptorGet.lua +24 -0
- package/dist/lualib/universal/DescriptorSet.lua +30 -0
- package/dist/lualib/universal/Promise.lua +83 -109
- package/dist/lualib/universal/SetDescriptor.lua +12 -45
- package/dist/lualib/universal/lualib_bundle.lua +180 -181
- package/dist/lualib/universal/lualib_module_info.json +14 -4
- package/dist/transformation/visitors/access.js +6 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +14 -4
- package/package.json +1 -1
|
@@ -588,6 +588,12 @@ local function __TS__ArrayWith(self, index, value)
|
|
|
588
588
|
return copy
|
|
589
589
|
end
|
|
590
590
|
|
|
591
|
+
local function __TS__New(target, ...)
|
|
592
|
+
local instance = setmetatable({}, target.prototype)
|
|
593
|
+
instance:____constructor(...)
|
|
594
|
+
return instance
|
|
595
|
+
end
|
|
596
|
+
|
|
591
597
|
local function __TS__InstanceOf(obj, classTbl)
|
|
592
598
|
if type(classTbl) ~= "table" then
|
|
593
599
|
error("Right-hand side of 'instanceof' is not an object", 0)
|
|
@@ -607,12 +613,6 @@ local function __TS__InstanceOf(obj, classTbl)
|
|
|
607
613
|
return false
|
|
608
614
|
end
|
|
609
615
|
|
|
610
|
-
local function __TS__New(target, ...)
|
|
611
|
-
local instance = setmetatable({}, target.prototype)
|
|
612
|
-
instance:____constructor(...)
|
|
613
|
-
return instance
|
|
614
|
-
end
|
|
615
|
-
|
|
616
616
|
local function __TS__Class(self)
|
|
617
617
|
local c = {prototype = {}}
|
|
618
618
|
c.prototype.__index = c.prototype
|
|
@@ -620,35 +620,27 @@ local function __TS__Class(self)
|
|
|
620
620
|
return c
|
|
621
621
|
end
|
|
622
622
|
|
|
623
|
-
local function __TS__FunctionBind(fn, ...)
|
|
624
|
-
local boundArgs = {...}
|
|
625
|
-
return function(____, ...)
|
|
626
|
-
local args = {...}
|
|
627
|
-
__TS__ArrayUnshift(
|
|
628
|
-
args,
|
|
629
|
-
__TS__Unpack(boundArgs)
|
|
630
|
-
)
|
|
631
|
-
return fn(__TS__Unpack(args))
|
|
632
|
-
end
|
|
633
|
-
end
|
|
634
|
-
|
|
635
623
|
local __TS__Promise
|
|
636
624
|
do
|
|
637
|
-
local function
|
|
625
|
+
local function makeDeferredPromiseFactory()
|
|
638
626
|
local resolve
|
|
639
627
|
local reject
|
|
640
|
-
local
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
628
|
+
local function executor(____, res, rej)
|
|
629
|
+
resolve = res
|
|
630
|
+
reject = rej
|
|
631
|
+
end
|
|
632
|
+
return function()
|
|
633
|
+
local promise = __TS__New(__TS__Promise, executor)
|
|
634
|
+
return promise, resolve, reject
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
local makeDeferredPromise = makeDeferredPromiseFactory()
|
|
638
|
+
local function isPromiseLike(value)
|
|
639
|
+
return __TS__InstanceOf(value, __TS__Promise)
|
|
648
640
|
end
|
|
649
|
-
local function
|
|
650
|
-
return __TS__InstanceOf(thing, __TS__Promise)
|
|
641
|
+
local function doNothing(self)
|
|
651
642
|
end
|
|
643
|
+
local ____pcall = _G.pcall
|
|
652
644
|
__TS__Promise = __TS__Class()
|
|
653
645
|
__TS__Promise.name = "__TS__Promise"
|
|
654
646
|
function __TS__Promise.prototype.____constructor(self, executor)
|
|
@@ -656,206 +648,176 @@ do
|
|
|
656
648
|
self.fulfilledCallbacks = {}
|
|
657
649
|
self.rejectedCallbacks = {}
|
|
658
650
|
self.finallyCallbacks = {}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
end
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
__TS__FunctionBind(self.reject, self)
|
|
668
|
-
)
|
|
669
|
-
end)
|
|
670
|
-
if not ____try then
|
|
671
|
-
____catch(____hasReturned)
|
|
672
|
-
end
|
|
651
|
+
local success, ____error = ____pcall(
|
|
652
|
+
executor,
|
|
653
|
+
nil,
|
|
654
|
+
function(____, v) return self:resolve(v) end,
|
|
655
|
+
function(____, err) return self:reject(err) end
|
|
656
|
+
)
|
|
657
|
+
if not success then
|
|
658
|
+
self:reject(____error)
|
|
673
659
|
end
|
|
674
660
|
end
|
|
675
|
-
function __TS__Promise.resolve(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
)
|
|
661
|
+
function __TS__Promise.resolve(value)
|
|
662
|
+
if __TS__InstanceOf(value, __TS__Promise) then
|
|
663
|
+
return value
|
|
664
|
+
end
|
|
665
|
+
local promise = __TS__New(__TS__Promise, doNothing)
|
|
681
666
|
promise.state = 1
|
|
682
|
-
promise.value =
|
|
667
|
+
promise.value = value
|
|
683
668
|
return promise
|
|
684
669
|
end
|
|
685
670
|
function __TS__Promise.reject(reason)
|
|
686
|
-
local promise = __TS__New(
|
|
687
|
-
__TS__Promise,
|
|
688
|
-
function()
|
|
689
|
-
end
|
|
690
|
-
)
|
|
671
|
+
local promise = __TS__New(__TS__Promise, doNothing)
|
|
691
672
|
promise.state = 2
|
|
692
673
|
promise.rejectionReason = reason
|
|
693
674
|
return promise
|
|
694
675
|
end
|
|
695
676
|
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
|
|
696
|
-
local
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if isFulfilled then
|
|
707
|
-
internalCallback(nil, self.value)
|
|
708
|
-
end
|
|
709
|
-
else
|
|
710
|
-
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
|
|
711
|
-
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
|
|
712
|
-
end
|
|
713
|
-
if onRejected then
|
|
714
|
-
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
|
|
715
|
-
local ____self_rejectedCallbacks_3 = self.rejectedCallbacks
|
|
716
|
-
____self_rejectedCallbacks_3[#____self_rejectedCallbacks_3 + 1] = internalCallback
|
|
717
|
-
if isRejected then
|
|
718
|
-
internalCallback(nil, self.rejectionReason)
|
|
719
|
-
end
|
|
720
|
-
else
|
|
721
|
-
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
|
|
722
|
-
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
|
|
723
|
-
end
|
|
724
|
-
if isFulfilled then
|
|
725
|
-
resolve(nil, self.value)
|
|
677
|
+
local promise, resolve, reject = makeDeferredPromise()
|
|
678
|
+
self:addCallbacks(
|
|
679
|
+
onFulfilled and self:createPromiseResolvingCallback(onFulfilled, resolve, reject) or resolve,
|
|
680
|
+
onRejected and self:createPromiseResolvingCallback(onRejected, resolve, reject) or reject
|
|
681
|
+
)
|
|
682
|
+
return promise
|
|
683
|
+
end
|
|
684
|
+
function __TS__Promise.prototype.addCallbacks(self, fulfilledCallback, rejectedCallback)
|
|
685
|
+
if self.state == 1 then
|
|
686
|
+
return fulfilledCallback(nil, self.value)
|
|
726
687
|
end
|
|
727
|
-
if
|
|
728
|
-
|
|
688
|
+
if self.state == 2 then
|
|
689
|
+
return rejectedCallback(nil, self.rejectionReason)
|
|
729
690
|
end
|
|
730
|
-
|
|
691
|
+
local ____self_fulfilledCallbacks_0 = self.fulfilledCallbacks
|
|
692
|
+
____self_fulfilledCallbacks_0[#____self_fulfilledCallbacks_0 + 1] = fulfilledCallback
|
|
693
|
+
local ____self_rejectedCallbacks_1 = self.rejectedCallbacks
|
|
694
|
+
____self_rejectedCallbacks_1[#____self_rejectedCallbacks_1 + 1] = rejectedCallback
|
|
731
695
|
end
|
|
732
696
|
function __TS__Promise.prototype.catch(self, onRejected)
|
|
733
697
|
return self["then"](self, nil, onRejected)
|
|
734
698
|
end
|
|
735
699
|
function __TS__Promise.prototype.finally(self, onFinally)
|
|
736
700
|
if onFinally then
|
|
737
|
-
local
|
|
738
|
-
|
|
701
|
+
local ____self_finallyCallbacks_2 = self.finallyCallbacks
|
|
702
|
+
____self_finallyCallbacks_2[#____self_finallyCallbacks_2 + 1] = onFinally
|
|
739
703
|
if self.state ~= 0 then
|
|
740
704
|
onFinally(nil)
|
|
741
705
|
end
|
|
742
706
|
end
|
|
743
707
|
return self
|
|
744
708
|
end
|
|
745
|
-
function __TS__Promise.prototype.resolve(self,
|
|
746
|
-
if
|
|
747
|
-
|
|
748
|
-
data,
|
|
709
|
+
function __TS__Promise.prototype.resolve(self, value)
|
|
710
|
+
if isPromiseLike(value) then
|
|
711
|
+
return value:addCallbacks(
|
|
749
712
|
function(____, v) return self:resolve(v) end,
|
|
750
713
|
function(____, err) return self:reject(err) end
|
|
751
714
|
)
|
|
752
|
-
return
|
|
753
715
|
end
|
|
754
716
|
if self.state == 0 then
|
|
755
717
|
self.state = 1
|
|
756
|
-
self.value =
|
|
757
|
-
|
|
758
|
-
callback(nil, data)
|
|
759
|
-
end
|
|
760
|
-
for ____, callback in ipairs(self.finallyCallbacks) do
|
|
761
|
-
callback(nil)
|
|
762
|
-
end
|
|
718
|
+
self.value = value
|
|
719
|
+
return self:invokeCallbacks(self.fulfilledCallbacks, value)
|
|
763
720
|
end
|
|
764
721
|
end
|
|
765
722
|
function __TS__Promise.prototype.reject(self, reason)
|
|
766
723
|
if self.state == 0 then
|
|
767
724
|
self.state = 2
|
|
768
725
|
self.rejectionReason = reason
|
|
769
|
-
|
|
770
|
-
|
|
726
|
+
return self:invokeCallbacks(self.rejectedCallbacks, reason)
|
|
727
|
+
end
|
|
728
|
+
end
|
|
729
|
+
function __TS__Promise.prototype.invokeCallbacks(self, callbacks, value)
|
|
730
|
+
local callbacksLength = #callbacks
|
|
731
|
+
local finallyCallbacks = self.finallyCallbacks
|
|
732
|
+
local finallyCallbacksLength = #finallyCallbacks
|
|
733
|
+
if callbacksLength ~= 0 then
|
|
734
|
+
for i = 1, callbacksLength - 1 do
|
|
735
|
+
callbacks[i](callbacks, value)
|
|
771
736
|
end
|
|
772
|
-
|
|
773
|
-
|
|
737
|
+
if finallyCallbacksLength == 0 then
|
|
738
|
+
return callbacks[callbacksLength](callbacks, value)
|
|
774
739
|
end
|
|
740
|
+
callbacks[callbacksLength](callbacks, value)
|
|
741
|
+
end
|
|
742
|
+
if finallyCallbacksLength ~= 0 then
|
|
743
|
+
for i = 1, finallyCallbacksLength - 1 do
|
|
744
|
+
finallyCallbacks[i](finallyCallbacks)
|
|
745
|
+
end
|
|
746
|
+
return finallyCallbacks[finallyCallbacksLength](finallyCallbacks)
|
|
775
747
|
end
|
|
776
748
|
end
|
|
777
749
|
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
|
|
778
750
|
return function(____, value)
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
end
|
|
783
|
-
local ____try, ____hasReturned = pcall(function()
|
|
784
|
-
self:handleCallbackData(
|
|
785
|
-
f(nil, value),
|
|
786
|
-
resolve,
|
|
787
|
-
reject
|
|
788
|
-
)
|
|
789
|
-
end)
|
|
790
|
-
if not ____try then
|
|
791
|
-
____catch(____hasReturned)
|
|
792
|
-
end
|
|
751
|
+
local success, resultOrError = ____pcall(f, nil, value)
|
|
752
|
+
if not success then
|
|
753
|
+
return reject(nil, resultOrError)
|
|
793
754
|
end
|
|
755
|
+
return self:handleCallbackValue(resultOrError, resolve, reject)
|
|
794
756
|
end
|
|
795
757
|
end
|
|
796
|
-
function __TS__Promise.prototype.
|
|
797
|
-
if isPromiseLike(
|
|
798
|
-
local nextpromise =
|
|
758
|
+
function __TS__Promise.prototype.handleCallbackValue(self, value, resolve, reject)
|
|
759
|
+
if isPromiseLike(value) then
|
|
760
|
+
local nextpromise = value
|
|
799
761
|
if nextpromise.state == 1 then
|
|
800
|
-
resolve(nil, nextpromise.value)
|
|
762
|
+
return resolve(nil, nextpromise.value)
|
|
801
763
|
elseif nextpromise.state == 2 then
|
|
802
|
-
reject(nil, nextpromise.rejectionReason)
|
|
764
|
+
return reject(nil, nextpromise.rejectionReason)
|
|
803
765
|
else
|
|
804
|
-
|
|
766
|
+
return nextpromise:addCallbacks(resolve, reject)
|
|
805
767
|
end
|
|
806
768
|
else
|
|
807
|
-
resolve(nil,
|
|
769
|
+
return resolve(nil, value)
|
|
808
770
|
end
|
|
809
771
|
end
|
|
810
772
|
end
|
|
811
773
|
|
|
812
|
-
local
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
774
|
+
local __TS__AsyncAwaiter, __TS__Await
|
|
775
|
+
do
|
|
776
|
+
local cocreate = coroutine.create
|
|
777
|
+
local coresume = coroutine.resume
|
|
778
|
+
local costatus = coroutine.status
|
|
779
|
+
local coyield = coroutine.yield
|
|
780
|
+
function __TS__AsyncAwaiter(generator)
|
|
781
|
+
return __TS__New(
|
|
782
|
+
__TS__Promise,
|
|
783
|
+
function(____, resolve, reject)
|
|
784
|
+
local fulfilled, step, resolved, asyncCoroutine
|
|
785
|
+
function fulfilled(self, value)
|
|
786
|
+
local success, resultOrError = coresume(asyncCoroutine, value)
|
|
787
|
+
if success then
|
|
788
|
+
return step(resultOrError)
|
|
789
|
+
end
|
|
790
|
+
return reject(nil, resultOrError)
|
|
826
791
|
end
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
792
|
+
function step(result)
|
|
793
|
+
if resolved then
|
|
794
|
+
return
|
|
795
|
+
end
|
|
796
|
+
if costatus(asyncCoroutine) == "dead" then
|
|
797
|
+
return resolve(nil, result)
|
|
798
|
+
end
|
|
799
|
+
return __TS__Promise.resolve(result):addCallbacks(fulfilled, reject)
|
|
831
800
|
end
|
|
832
|
-
|
|
833
|
-
|
|
801
|
+
resolved = false
|
|
802
|
+
asyncCoroutine = cocreate(generator)
|
|
803
|
+
local success, resultOrError = coresume(
|
|
804
|
+
asyncCoroutine,
|
|
805
|
+
function(____, v)
|
|
806
|
+
resolved = true
|
|
807
|
+
return __TS__Promise.resolve(v):addCallbacks(resolve, reject)
|
|
808
|
+
end
|
|
809
|
+
)
|
|
810
|
+
if success then
|
|
811
|
+
return step(resultOrError)
|
|
834
812
|
else
|
|
835
|
-
|
|
836
|
-
____self_0["then"](____self_0, fulfilled, reject)
|
|
813
|
+
return reject(nil, resultOrError)
|
|
837
814
|
end
|
|
838
815
|
end
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
resolved = true
|
|
845
|
-
local ____self_1 = adopt(nil, v)
|
|
846
|
-
____self_1["then"](____self_1, resolve, reject)
|
|
847
|
-
end
|
|
848
|
-
)
|
|
849
|
-
if success then
|
|
850
|
-
step(nil, resultOrError)
|
|
851
|
-
else
|
|
852
|
-
reject(nil, resultOrError)
|
|
853
|
-
end
|
|
854
|
-
end
|
|
855
|
-
)
|
|
856
|
-
end
|
|
857
|
-
local function __TS__Await(thing)
|
|
858
|
-
return coroutine.yield(thing)
|
|
816
|
+
)
|
|
817
|
+
end
|
|
818
|
+
function __TS__Await(thing)
|
|
819
|
+
return coyield(thing)
|
|
820
|
+
end
|
|
859
821
|
end
|
|
860
822
|
|
|
861
823
|
local function __TS__ClassExtends(target, base)
|
|
@@ -953,20 +915,17 @@ local function __TS__ObjectGetOwnPropertyDescriptor(object, key)
|
|
|
953
915
|
return rawget(metatable, "_descriptors")[key]
|
|
954
916
|
end
|
|
955
917
|
|
|
956
|
-
local
|
|
918
|
+
local __TS__DescriptorGet
|
|
957
919
|
do
|
|
958
|
-
local
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
return value
|
|
962
|
-
end
|
|
963
|
-
local metatable = getmetatable(self)
|
|
920
|
+
local getmetatable = _G.getmetatable
|
|
921
|
+
local ____rawget = _G.rawget
|
|
922
|
+
function __TS__DescriptorGet(self, metatable, key)
|
|
964
923
|
while metatable do
|
|
965
|
-
local rawResult =
|
|
924
|
+
local rawResult = ____rawget(metatable, key)
|
|
966
925
|
if rawResult ~= nil then
|
|
967
926
|
return rawResult
|
|
968
927
|
end
|
|
969
|
-
local descriptors =
|
|
928
|
+
local descriptors = ____rawget(metatable, "_descriptors")
|
|
970
929
|
if descriptors then
|
|
971
930
|
local descriptor = descriptors[key]
|
|
972
931
|
if descriptor ~= nil then
|
|
@@ -979,10 +938,16 @@ do
|
|
|
979
938
|
metatable = getmetatable(metatable)
|
|
980
939
|
end
|
|
981
940
|
end
|
|
982
|
-
|
|
983
|
-
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
local __TS__DescriptorSet
|
|
944
|
+
do
|
|
945
|
+
local getmetatable = _G.getmetatable
|
|
946
|
+
local ____rawget = _G.rawget
|
|
947
|
+
local rawset = _G.rawset
|
|
948
|
+
function __TS__DescriptorSet(self, metatable, key, value)
|
|
984
949
|
while metatable do
|
|
985
|
-
local descriptors =
|
|
950
|
+
local descriptors = ____rawget(metatable, "_descriptors")
|
|
986
951
|
if descriptors then
|
|
987
952
|
local descriptor = descriptors[key]
|
|
988
953
|
if descriptor ~= nil then
|
|
@@ -1004,6 +969,26 @@ do
|
|
|
1004
969
|
end
|
|
1005
970
|
rawset(self, key, value)
|
|
1006
971
|
end
|
|
972
|
+
end
|
|
973
|
+
|
|
974
|
+
local __TS__SetDescriptor
|
|
975
|
+
do
|
|
976
|
+
local getmetatable = _G.getmetatable
|
|
977
|
+
local function descriptorIndex(self, key)
|
|
978
|
+
return __TS__DescriptorGet(
|
|
979
|
+
self,
|
|
980
|
+
getmetatable(self),
|
|
981
|
+
key
|
|
982
|
+
)
|
|
983
|
+
end
|
|
984
|
+
local function descriptorNewIndex(self, key, value)
|
|
985
|
+
return __TS__DescriptorSet(
|
|
986
|
+
self,
|
|
987
|
+
getmetatable(self),
|
|
988
|
+
key,
|
|
989
|
+
value
|
|
990
|
+
)
|
|
991
|
+
end
|
|
1007
992
|
function __TS__SetDescriptor(target, key, desc, isPrototype)
|
|
1008
993
|
if isPrototype == nil then
|
|
1009
994
|
isPrototype = false
|
|
@@ -1232,6 +1217,18 @@ local function __TS__DelegatedYield(iterable)
|
|
|
1232
1217
|
end
|
|
1233
1218
|
end
|
|
1234
1219
|
|
|
1220
|
+
local function __TS__FunctionBind(fn, ...)
|
|
1221
|
+
local boundArgs = {...}
|
|
1222
|
+
return function(____, ...)
|
|
1223
|
+
local args = {...}
|
|
1224
|
+
__TS__ArrayUnshift(
|
|
1225
|
+
args,
|
|
1226
|
+
__TS__Unpack(boundArgs)
|
|
1227
|
+
)
|
|
1228
|
+
return fn(__TS__Unpack(args))
|
|
1229
|
+
end
|
|
1230
|
+
end
|
|
1231
|
+
|
|
1235
1232
|
local __TS__Generator
|
|
1236
1233
|
do
|
|
1237
1234
|
local function generatorIterator(self)
|
|
@@ -2551,6 +2548,8 @@ return {
|
|
|
2551
2548
|
__TS__DecorateParam = __TS__DecorateParam,
|
|
2552
2549
|
__TS__Delete = __TS__Delete,
|
|
2553
2550
|
__TS__DelegatedYield = __TS__DelegatedYield,
|
|
2551
|
+
__TS__DescriptorGet = __TS__DescriptorGet,
|
|
2552
|
+
__TS__DescriptorSet = __TS__DescriptorSet,
|
|
2554
2553
|
Error = Error,
|
|
2555
2554
|
RangeError = RangeError,
|
|
2556
2555
|
ReferenceError = ReferenceError,
|
|
@@ -210,7 +210,6 @@
|
|
|
210
210
|
"__TS__Await"
|
|
211
211
|
],
|
|
212
212
|
"dependencies": [
|
|
213
|
-
"InstanceOf",
|
|
214
213
|
"Promise",
|
|
215
214
|
"New"
|
|
216
215
|
]
|
|
@@ -277,6 +276,16 @@
|
|
|
277
276
|
"Symbol"
|
|
278
277
|
]
|
|
279
278
|
},
|
|
279
|
+
"DescriptorGet": {
|
|
280
|
+
"exports": [
|
|
281
|
+
"__TS__DescriptorGet"
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
"DescriptorSet": {
|
|
285
|
+
"exports": [
|
|
286
|
+
"__TS__DescriptorSet"
|
|
287
|
+
]
|
|
288
|
+
},
|
|
280
289
|
"Error": {
|
|
281
290
|
"exports": [
|
|
282
291
|
"Error",
|
|
@@ -491,8 +500,7 @@
|
|
|
491
500
|
"Promise",
|
|
492
501
|
"New",
|
|
493
502
|
"InstanceOf",
|
|
494
|
-
"Class"
|
|
495
|
-
"FunctionBind"
|
|
503
|
+
"Class"
|
|
496
504
|
]
|
|
497
505
|
},
|
|
498
506
|
"PromiseAll": {
|
|
@@ -554,7 +562,9 @@
|
|
|
554
562
|
"__TS__SetDescriptor"
|
|
555
563
|
],
|
|
556
564
|
"dependencies": [
|
|
557
|
-
"CloneDescriptor"
|
|
565
|
+
"CloneDescriptor",
|
|
566
|
+
"DescriptorGet",
|
|
567
|
+
"DescriptorSet"
|
|
558
568
|
]
|
|
559
569
|
},
|
|
560
570
|
"SparseArrayNew": {
|
|
@@ -15,6 +15,7 @@ const expression_list_1 = require("./expression-list");
|
|
|
15
15
|
const call_extension_1 = require("./language-extensions/call-extension");
|
|
16
16
|
const multi_1 = require("./language-extensions/multi");
|
|
17
17
|
const optional_chaining_1 = require("./optional-chaining");
|
|
18
|
+
const typescript_2 = require("typescript");
|
|
18
19
|
function addOneToArrayAccessArgument(context, node, index) {
|
|
19
20
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
20
21
|
const argumentType = context.checker.getTypeAtLocation(node.argumentExpression);
|
|
@@ -128,6 +129,11 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
|
|
|
128
129
|
thisValue,
|
|
129
130
|
};
|
|
130
131
|
}
|
|
132
|
+
if (node.expression.kind === typescript_2.SyntaxKind.SuperKeyword) {
|
|
133
|
+
return {
|
|
134
|
+
expression: (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorGet, node, lua.createIdentifier("self"), table, lua.createStringLiteral(property)),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
131
137
|
return { expression: lua.createTableIndexExpression(table, lua.createStringLiteral(property), node) };
|
|
132
138
|
}
|
|
133
139
|
exports.transformPropertyAccessExpressionWithCapture = transformPropertyAccessExpressionWithCapture;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformAssignmentStatement = exports.transformAssignmentExpression = exports.transformAssignmentWithRightPrecedingStatements = exports.transformAssignment = exports.transformAssignmentLeftHandSideExpression = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
+
const typescript_1 = require("typescript");
|
|
5
6
|
const lua = require("../../../LuaAST");
|
|
6
7
|
const assignment_validation_1 = require("../../utils/assignment-validation");
|
|
7
8
|
const export_1 = require("../../utils/export");
|
|
8
9
|
const lua_ast_1 = require("../../utils/lua-ast");
|
|
9
10
|
const lualib_1 = require("../../utils/lualib");
|
|
10
|
-
const
|
|
11
|
+
const typescript_2 = require("../../utils/typescript");
|
|
11
12
|
const destructuring_assignments_1 = require("./destructuring-assignments");
|
|
12
13
|
const multi_1 = require("../language-extensions/multi");
|
|
13
14
|
const diagnostics_1 = require("../../utils/diagnostics");
|
|
@@ -54,6 +55,15 @@ lhs, right, rightHasPrecedingStatements, parent) {
|
|
|
54
55
|
const arrayLengthAssignment = lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySetLength, parent, context.transformExpression(lhs.expression), right));
|
|
55
56
|
return [arrayLengthAssignment];
|
|
56
57
|
}
|
|
58
|
+
if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
|
|
59
|
+
if (lhs.expression.kind === typescript_1.SyntaxKind.SuperKeyword) {
|
|
60
|
+
return [
|
|
61
|
+
lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DescriptorSet, parent, lua.createIdentifier("self"), context.transformExpression(lhs.expression), ts.isPropertyAccessExpression(lhs)
|
|
62
|
+
? lua.createStringLiteral(lhs.name.text)
|
|
63
|
+
: context.transformExpression(lhs.argumentExpression), right)),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
57
67
|
const symbol = lhs.parent && ts.isShorthandPropertyAssignment(lhs.parent)
|
|
58
68
|
? context.checker.getShorthandAssignmentValueSymbol(lhs.parent)
|
|
59
69
|
: context.checker.getSymbolAtLocation(lhs);
|
|
@@ -96,7 +106,7 @@ function transformAssignmentExpression(context, expression) {
|
|
|
96
106
|
// array.length = x
|
|
97
107
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySetLength, expression, context.transformExpression(expression.left.expression), context.transformExpression(expression.right));
|
|
98
108
|
}
|
|
99
|
-
if ((0,
|
|
109
|
+
if ((0, typescript_2.isDestructuringAssignment)(expression)) {
|
|
100
110
|
const { statements, result } = transformDestructuredAssignmentExpression(context, expression);
|
|
101
111
|
context.addPrecedingStatements(statements);
|
|
102
112
|
return result;
|
|
@@ -142,7 +152,7 @@ function transformAssignmentStatement(context, expression) {
|
|
|
142
152
|
const rightType = context.checker.getTypeAtLocation(expression.right);
|
|
143
153
|
const leftType = context.checker.getTypeAtLocation(expression.left);
|
|
144
154
|
(0, assignment_validation_1.validateAssignment)(context, expression.right, rightType, leftType);
|
|
145
|
-
if ((0,
|
|
155
|
+
if ((0, typescript_2.isDestructuringAssignment)(expression)) {
|
|
146
156
|
if (canBeTransformedToLuaAssignmentStatement(context, expression)) {
|
|
147
157
|
const rightType = context.checker.getTypeAtLocation(expression.right);
|
|
148
158
|
let right;
|
|
@@ -151,7 +161,7 @@ function transformAssignmentStatement(context, expression) {
|
|
|
151
161
|
}
|
|
152
162
|
else {
|
|
153
163
|
right = context.transformExpression(expression.right);
|
|
154
|
-
if (!(0, multi_1.isMultiReturnCall)(context, expression.right) && (0,
|
|
164
|
+
if (!(0, multi_1.isMultiReturnCall)(context, expression.right) && (0, typescript_2.isArrayType)(context, rightType)) {
|
|
155
165
|
right = (0, lua_ast_1.createUnpackCall)(context, right, expression.right);
|
|
156
166
|
}
|
|
157
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|