-
Notifications
You must be signed in to change notification settings - Fork 1
/
lualib_bundle.lua
2478 lines (2378 loc) · 73.5 KB
/
lualib_bundle.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local function __TS__ArrayIsArray(value)
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
end
local function __TS__ArrayConcat(self, ...)
local items = {...}
local result = {}
local len = 0
for i = 1, #self do
len = len + 1
result[len] = self[i]
end
for i = 1, #items do
local item = items[i]
if __TS__ArrayIsArray(item) then
for j = 1, #item do
len = len + 1
result[len] = item[j]
end
else
len = len + 1
result[len] = item
end
end
return result
end
local __TS__Symbol, Symbol
do
local symbolMetatable = {__tostring = function(self)
return ("Symbol(" .. (self.description or "")) .. ")"
end}
function __TS__Symbol(description)
return setmetatable({description = description}, symbolMetatable)
end
Symbol = {
iterator = __TS__Symbol("Symbol.iterator"),
hasInstance = __TS__Symbol("Symbol.hasInstance"),
species = __TS__Symbol("Symbol.species"),
toStringTag = __TS__Symbol("Symbol.toStringTag")
}
end
local function __TS__ArrayEntries(array)
local key = 0
return {
[Symbol.iterator] = function(self)
return self
end,
next = function(self)
local result = {done = array[key + 1] == nil, value = {key, array[key + 1]}}
key = key + 1
return result
end
}
end
local function __TS__ArrayEvery(self, callbackfn, thisArg)
for i = 1, #self do
if not callbackfn(thisArg, self[i], i - 1, self) then
return false
end
end
return true
end
local function __TS__ArrayFilter(self, callbackfn, thisArg)
local result = {}
local len = 0
for i = 1, #self do
if callbackfn(thisArg, self[i], i - 1, self) then
len = len + 1
result[len] = self[i]
end
end
return result
end
local function __TS__ArrayForEach(self, callbackFn, thisArg)
for i = 1, #self do
callbackFn(thisArg, self[i], i - 1, self)
end
end
local function __TS__ArrayFind(self, predicate, thisArg)
for i = 1, #self do
local elem = self[i]
if predicate(thisArg, elem, i - 1, self) then
return elem
end
end
return nil
end
local function __TS__ArrayFindIndex(self, callbackFn, thisArg)
for i = 1, #self do
if callbackFn(thisArg, self[i], i - 1, self) then
return i - 1
end
end
return -1
end
local __TS__Iterator
do
local function iteratorGeneratorStep(self)
local co = self.____coroutine
local status, value = coroutine.resume(co)
if not status then
error(value, 0)
end
if coroutine.status(co) == "dead" then
return
end
return true, value
end
local function iteratorIteratorStep(self)
local result = self:next()
if result.done then
return
end
return true, result.value
end
local function iteratorStringStep(self, index)
index = index + 1
if index > #self then
return
end
return index, string.sub(self, index, index)
end
function __TS__Iterator(iterable)
if type(iterable) == "string" then
return iteratorStringStep, iterable, 0
elseif iterable.____coroutine ~= nil then
return iteratorGeneratorStep, iterable
elseif iterable[Symbol.iterator] then
local iterator = iterable[Symbol.iterator](iterable)
return iteratorIteratorStep, iterator
else
return ipairs(iterable)
end
end
end
local __TS__ArrayFrom
do
local function arrayLikeStep(self, index)
index = index + 1
if index > self.length then
return
end
return index, self[index]
end
local function arrayLikeIterator(arr)
if type(arr.length) == "number" then
return arrayLikeStep, arr, 0
end
return __TS__Iterator(arr)
end
function __TS__ArrayFrom(arrayLike, mapFn, thisArg)
local result = {}
if mapFn == nil then
for ____, v in arrayLikeIterator(arrayLike) do
result[#result + 1] = v
end
else
for i, v in arrayLikeIterator(arrayLike) do
result[#result + 1] = mapFn(thisArg, v, i - 1)
end
end
return result
end
end
local function __TS__ArrayIncludes(self, searchElement, fromIndex)
if fromIndex == nil then
fromIndex = 0
end
local len = #self
local k = fromIndex
if fromIndex < 0 then
k = len + fromIndex
end
if k < 0 then
k = 0
end
for i = k + 1, len do
if self[i] == searchElement then
return true
end
end
return false
end
local function __TS__ArrayIndexOf(self, searchElement, fromIndex)
if fromIndex == nil then
fromIndex = 0
end
local len = #self
if len == 0 then
return -1
end
if fromIndex >= len then
return -1
end
if fromIndex < 0 then
fromIndex = len + fromIndex
if fromIndex < 0 then
fromIndex = 0
end
end
for i = fromIndex + 1, len do
if self[i] == searchElement then
return i - 1
end
end
return -1
end
local function __TS__ArrayJoin(self, separator)
if separator == nil then
separator = ","
end
local parts = {}
for i = 1, #self do
parts[i] = tostring(self[i])
end
return table.concat(parts, separator)
end
local function __TS__ArrayMap(self, callbackfn, thisArg)
local result = {}
for i = 1, #self do
result[i] = callbackfn(thisArg, self[i], i - 1, self)
end
return result
end
local function __TS__ArrayPush(self, ...)
local items = {...}
local len = #self
for i = 1, #items do
len = len + 1
self[len] = items[i]
end
return len
end
local function __TS__ArrayPushArray(self, items)
local len = #self
for i = 1, #items do
len = len + 1
self[len] = items[i]
end
return len
end
local function __TS__CountVarargs(...)
return select("#", ...)
end
local function __TS__ArrayReduce(self, callbackFn, ...)
local len = #self
local k = 0
local accumulator = nil
if __TS__CountVarargs(...) ~= 0 then
accumulator = ...
elseif len > 0 then
accumulator = self[1]
k = 1
else
error("Reduce of empty array with no initial value", 0)
end
for i = k + 1, len do
accumulator = callbackFn(
nil,
accumulator,
self[i],
i - 1,
self
)
end
return accumulator
end
local function __TS__ArrayReduceRight(self, callbackFn, ...)
local len = #self
local k = len - 1
local accumulator = nil
if __TS__CountVarargs(...) ~= 0 then
accumulator = ...
elseif len > 0 then
accumulator = self[k + 1]
k = k - 1
else
error("Reduce of empty array with no initial value", 0)
end
for i = k + 1, 1, -1 do
accumulator = callbackFn(
nil,
accumulator,
self[i],
i - 1,
self
)
end
return accumulator
end
local function __TS__ArrayReverse(self)
local i = 1
local j = #self
while i < j do
local temp = self[j]
self[j] = self[i]
self[i] = temp
i = i + 1
j = j - 1
end
return self
end
local function __TS__ArrayUnshift(self, ...)
local items = {...}
local numItemsToInsert = #items
if numItemsToInsert == 0 then
return #self
end
for i = #self, 1, -1 do
self[i + numItemsToInsert] = self[i]
end
for i = 1, numItemsToInsert do
self[i] = items[i]
end
return #self
end
local function __TS__ArraySort(self, compareFn)
if compareFn ~= nil then
table.sort(
self,
function(a, b) return compareFn(nil, a, b) < 0 end
)
else
table.sort(self)
end
return self
end
local function __TS__ArraySlice(self, first, last)
local len = #self
first = first or 0
if first < 0 then
first = len + first
if first < 0 then
first = 0
end
else
if first > len then
first = len
end
end
last = last or len
if last < 0 then
last = len + last
if last < 0 then
last = 0
end
else
if last > len then
last = len
end
end
local out = {}
first = first + 1
last = last + 1
local n = 1
while first < last do
out[n] = self[first]
first = first + 1
n = n + 1
end
return out
end
local function __TS__ArraySome(self, callbackfn, thisArg)
for i = 1, #self do
if callbackfn(thisArg, self[i], i - 1, self) then
return true
end
end
return false
end
local function __TS__ArraySplice(self, ...)
local args = {...}
local len = #self
local actualArgumentCount = __TS__CountVarargs(...)
local start = args[1]
local deleteCount = args[2]
if start < 0 then
start = len + start
if start < 0 then
start = 0
end
elseif start > len then
start = len
end
local itemCount = actualArgumentCount - 2
if itemCount < 0 then
itemCount = 0
end
local actualDeleteCount
if actualArgumentCount == 0 then
actualDeleteCount = 0
elseif actualArgumentCount == 1 then
actualDeleteCount = len - start
else
actualDeleteCount = deleteCount or 0
if actualDeleteCount < 0 then
actualDeleteCount = 0
end
if actualDeleteCount > len - start then
actualDeleteCount = len - start
end
end
local out = {}
for k = 1, actualDeleteCount do
local from = start + k
if self[from] ~= nil then
out[k] = self[from]
end
end
if itemCount < actualDeleteCount then
for k = start + 1, len - actualDeleteCount do
local from = k + actualDeleteCount
local to = k + itemCount
if self[from] then
self[to] = self[from]
else
self[to] = nil
end
end
for k = len - actualDeleteCount + itemCount + 1, len do
self[k] = nil
end
elseif itemCount > actualDeleteCount then
for k = len - actualDeleteCount, start + 1, -1 do
local from = k + actualDeleteCount
local to = k + itemCount
if self[from] then
self[to] = self[from]
else
self[to] = nil
end
end
end
local j = start + 1
for i = 3, actualArgumentCount do
self[j] = args[i]
j = j + 1
end
for k = #self, len - actualDeleteCount + itemCount + 1, -1 do
self[k] = nil
end
return out
end
local function __TS__ArrayToObject(self)
local object = {}
for i = 1, #self do
object[i - 1] = self[i]
end
return object
end
local function __TS__ArrayFlat(self, depth)
if depth == nil then
depth = 1
end
local result = {}
local len = 0
for i = 1, #self do
local value = self[i]
if depth > 0 and __TS__ArrayIsArray(value) then
local toAdd
if depth == 1 then
toAdd = value
else
toAdd = __TS__ArrayFlat(value, depth - 1)
end
for j = 1, #toAdd do
local val = toAdd[j]
len = len + 1
result[len] = val
end
else
len = len + 1
result[len] = value
end
end
return result
end
local function __TS__ArrayFlatMap(self, callback, thisArg)
local result = {}
local len = 0
for i = 1, #self do
local value = callback(thisArg, self[i], i - 1, self)
if __TS__ArrayIsArray(value) then
for j = 1, #value do
len = len + 1
result[len] = value[j]
end
else
len = len + 1
result[len] = value
end
end
return result
end
local function __TS__ArraySetLength(self, length)
if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
error(
"invalid array length: " .. tostring(length),
0
)
end
for i = length + 1, #self do
self[i] = nil
end
return length
end
local function __TS__InstanceOf(obj, classTbl)
if type(classTbl) ~= "table" then
error("Right-hand side of 'instanceof' is not an object", 0)
end
if classTbl[Symbol.hasInstance] ~= nil then
return not not classTbl[Symbol.hasInstance](classTbl, obj)
end
if type(obj) == "table" then
local luaClass = obj.constructor
while luaClass ~= nil do
if luaClass == classTbl then
return true
end
luaClass = luaClass.____super
end
end
return false
end
local function __TS__New(target, ...)
local instance = setmetatable({}, target.prototype)
instance:____constructor(...)
return instance
end
local function __TS__Class(self)
local c = {prototype = {}}
c.prototype.__index = c.prototype
c.prototype.constructor = c
return c
end
local __TS__Unpack = table.unpack or unpack
local function __TS__FunctionBind(fn, ...)
local boundArgs = {...}
return function(____, ...)
local args = {...}
__TS__ArrayUnshift(
args,
__TS__Unpack(boundArgs)
)
return fn(__TS__Unpack(args))
end
end
local __TS__Promise
do
local function promiseDeferred(self)
local resolve
local reject
local promise = __TS__New(
__TS__Promise,
function(____, res, rej)
resolve = res
reject = rej
end
)
return {promise = promise, resolve = resolve, reject = reject}
end
local function isPromiseLike(self, thing)
return __TS__InstanceOf(thing, __TS__Promise)
end
__TS__Promise = __TS__Class()
__TS__Promise.name = "__TS__Promise"
function __TS__Promise.prototype.____constructor(self, executor)
self.state = 0
self.fulfilledCallbacks = {}
self.rejectedCallbacks = {}
self.finallyCallbacks = {}
do
local function ____catch(e)
self:reject(e)
end
local ____try, ____hasReturned = pcall(function()
executor(
nil,
__TS__FunctionBind(self.resolve, self),
__TS__FunctionBind(self.reject, self)
)
end)
if not ____try then
____catch(____hasReturned)
end
end
end
function __TS__Promise.resolve(data)
local promise = __TS__New(
__TS__Promise,
function()
end
)
promise.state = 1
promise.value = data
return promise
end
function __TS__Promise.reject(reason)
local promise = __TS__New(
__TS__Promise,
function()
end
)
promise.state = 2
promise.rejectionReason = reason
return promise
end
__TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
local ____promiseDeferred_result_0 = promiseDeferred(nil)
local promise = ____promiseDeferred_result_0.promise
local resolve = ____promiseDeferred_result_0.resolve
local reject = ____promiseDeferred_result_0.reject
local isFulfilled = self.state == 1
local isRejected = self.state == 2
if onFulfilled then
local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
local ____self_fulfilledCallbacks_1 = self.fulfilledCallbacks
____self_fulfilledCallbacks_1[#____self_fulfilledCallbacks_1 + 1] = internalCallback
if isFulfilled then
internalCallback(nil, self.value)
end
else
local ____self_fulfilledCallbacks_2 = self.fulfilledCallbacks
____self_fulfilledCallbacks_2[#____self_fulfilledCallbacks_2 + 1] = function(____, v) return resolve(nil, v) end
end
if onRejected then
local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
local ____self_rejectedCallbacks_3 = self.rejectedCallbacks
____self_rejectedCallbacks_3[#____self_rejectedCallbacks_3 + 1] = internalCallback
if isRejected then
internalCallback(nil, self.rejectionReason)
end
else
local ____self_rejectedCallbacks_4 = self.rejectedCallbacks
____self_rejectedCallbacks_4[#____self_rejectedCallbacks_4 + 1] = function(____, err) return reject(nil, err) end
end
if isFulfilled then
resolve(nil, self.value)
end
if isRejected then
reject(nil, self.rejectionReason)
end
return promise
end
function __TS__Promise.prototype.catch(self, onRejected)
return self["then"](self, nil, onRejected)
end
function __TS__Promise.prototype.finally(self, onFinally)
if onFinally then
local ____self_finallyCallbacks_5 = self.finallyCallbacks
____self_finallyCallbacks_5[#____self_finallyCallbacks_5 + 1] = onFinally
if self.state ~= 0 then
onFinally(nil)
end
end
return self
end
function __TS__Promise.prototype.resolve(self, data)
if __TS__InstanceOf(data, __TS__Promise) then
data["then"](
data,
function(____, v) return self:resolve(v) end,
function(____, err) return self:reject(err) end
)
return
end
if self.state == 0 then
self.state = 1
self.value = data
for ____, callback in ipairs(self.fulfilledCallbacks) do
callback(nil, data)
end
for ____, callback in ipairs(self.finallyCallbacks) do
callback(nil)
end
end
end
function __TS__Promise.prototype.reject(self, reason)
if self.state == 0 then
self.state = 2
self.rejectionReason = reason
for ____, callback in ipairs(self.rejectedCallbacks) do
callback(nil, reason)
end
for ____, callback in ipairs(self.finallyCallbacks) do
callback(nil)
end
end
end
function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
return function(____, value)
do
local function ____catch(e)
reject(nil, e)
end
local ____try, ____hasReturned = pcall(function()
self:handleCallbackData(
f(nil, value),
resolve,
reject
)
end)
if not ____try then
____catch(____hasReturned)
end
end
end
end
function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
if isPromiseLike(nil, data) then
local nextpromise = data
if nextpromise.state == 1 then
resolve(nil, nextpromise.value)
elseif nextpromise.state == 2 then
reject(nil, nextpromise.rejectionReason)
else
data["then"](data, resolve, reject)
end
else
resolve(nil, data)
end
end
end
local function __TS__AsyncAwaiter(generator)
return __TS__New(
__TS__Promise,
function(____, resolve, reject)
local adopt, fulfilled, step, resolved, asyncCoroutine
function adopt(self, value)
return __TS__InstanceOf(value, __TS__Promise) and value or __TS__Promise.resolve(value)
end
function fulfilled(self, value)
local success, resultOrError = coroutine.resume(asyncCoroutine, value)
if success then
step(nil, resultOrError)
else
reject(nil, resultOrError)
end
end
function step(self, result)
if resolved then
return
end
if coroutine.status(asyncCoroutine) == "dead" then
resolve(nil, result)
else
local ____self_0 = adopt(nil, result)
____self_0["then"](____self_0, fulfilled, reject)
end
end
resolved = false
asyncCoroutine = coroutine.create(generator)
local success, resultOrError = coroutine.resume(
asyncCoroutine,
function(____, v)
resolved = true
local ____self_1 = adopt(nil, v)
____self_1["then"](____self_1, resolve, reject)
end
)
if success then
step(nil, resultOrError)
else
reject(nil, resultOrError)
end
end
)
end
local function __TS__Await(thing)
return coroutine.yield(thing)
end
local function __TS__ClassExtends(target, base)
target.____super = base
local staticMetatable = setmetatable({__index = base}, base)
setmetatable(target, staticMetatable)
local baseMetatable = getmetatable(base)
if baseMetatable then
if type(baseMetatable.__index) == "function" then
staticMetatable.__index = baseMetatable.__index
end
if type(baseMetatable.__newindex) == "function" then
staticMetatable.__newindex = baseMetatable.__newindex
end
end
setmetatable(target.prototype, base.prototype)
if type(base.prototype.__index) == "function" then
target.prototype.__index = base.prototype.__index
end
if type(base.prototype.__newindex) == "function" then
target.prototype.__newindex = base.prototype.__newindex
end
if type(base.prototype.__tostring) == "function" then
target.prototype.__tostring = base.prototype.__tostring
end
end
local function __TS__CloneDescriptor(____bindingPattern0)
local value
local writable
local set
local get
local configurable
local enumerable
enumerable = ____bindingPattern0.enumerable
configurable = ____bindingPattern0.configurable
get = ____bindingPattern0.get
set = ____bindingPattern0.set
writable = ____bindingPattern0.writable
value = ____bindingPattern0.value
local descriptor = {enumerable = enumerable == true, configurable = configurable == true}
local hasGetterOrSetter = get ~= nil or set ~= nil
local hasValueOrWritableAttribute = writable ~= nil or value ~= nil
if hasGetterOrSetter and hasValueOrWritableAttribute then
error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.", 0)
end
if get or set then
descriptor.get = get
descriptor.set = set
else
descriptor.value = value
descriptor.writable = writable == true
end
return descriptor
end
local function __TS__ObjectAssign(target, ...)
local sources = {...}
for i = 1, #sources do
local source = sources[i]
for key in pairs(source) do
target[key] = source[key]
end
end
return target
end
local function __TS__ObjectGetOwnPropertyDescriptor(object, key)
local metatable = getmetatable(object)
if not metatable then
return
end
if not rawget(metatable, "_descriptors") then
return
end
return rawget(metatable, "_descriptors")[key]
end
local __TS__SetDescriptor
do
local function descriptorIndex(self, key)
local value = rawget(self, key)
if value ~= nil then
return value
end
local metatable = getmetatable(self)
while metatable do
local rawResult = rawget(metatable, key)
if rawResult ~= nil then
return rawResult
end
local descriptors = rawget(metatable, "_descriptors")
if descriptors then
local descriptor = descriptors[key]
if descriptor ~= nil then
if descriptor.get then
return descriptor.get(self)
end
return descriptor.value
end
end
metatable = getmetatable(metatable)
end
end
local function descriptorNewIndex(self, key, value)
local metatable = getmetatable(self)
while metatable do
local descriptors = rawget(metatable, "_descriptors")
if descriptors then
local descriptor = descriptors[key]
if descriptor ~= nil then
if descriptor.set then
descriptor.set(self, value)
else
if descriptor.writable == false then
error(
((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
0
)
end
descriptor.value = value
end
return
end
end
metatable = getmetatable(metatable)
end
rawset(self, key, value)
end
function __TS__SetDescriptor(target, key, desc, isPrototype)
if isPrototype == nil then
isPrototype = false
end
local ____isPrototype_0
if isPrototype then
____isPrototype_0 = target
else
____isPrototype_0 = getmetatable(target)
end
local metatable = ____isPrototype_0
if not metatable then
metatable = {}
setmetatable(target, metatable)
end
local value = rawget(target, key)
if value ~= nil then
rawset(target, key, nil)
end
if not rawget(metatable, "_descriptors") then
metatable._descriptors = {}
end
metatable._descriptors[key] = __TS__CloneDescriptor(desc)
metatable.__index = descriptorIndex
metatable.__newindex = descriptorNewIndex
end
end
local function __TS__Decorate(decorators, target, key, desc)
local result = target
do
local i = #decorators
while i >= 0 do
local decorator = decorators[i + 1]
if decorator ~= nil then
local oldResult = result
if key == nil then
result = decorator(nil, result)
elseif desc == true then
local value = rawget(target, key)
local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
local desc = decorator(nil, target, key, descriptor) or descriptor
local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
if isSimpleValue then
rawset(target, key, desc.value)
else
__TS__SetDescriptor(
target,
key,
__TS__ObjectAssign({}, descriptor, desc)
)
end
elseif desc == false then
result = decorator(nil, target, key, desc)
else
result = decorator(nil, target, key)
end
result = result or oldResult
end
i = i - 1
end
end
return result
end
local function __TS__DecorateParam(paramIndex, decorator)