typescript-to-lua 1.3.4 → 1.4.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.
Files changed (132) hide show
  1. package/dist/CompilerOptions.d.ts +1 -1
  2. package/dist/CompilerOptions.js +0 -1
  3. package/dist/LuaLib.d.ts +12 -1
  4. package/dist/LuaLib.js +61 -65
  5. package/dist/LuaPrinter.js +9 -8
  6. package/dist/cli/parse.js +5 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +5 -1
  9. package/dist/lualib/ArrayConcat.lua +1 -1
  10. package/dist/lualib/ArrayEntries.lua +1 -1
  11. package/dist/lualib/ArrayEvery.lua +2 -2
  12. package/dist/lualib/ArrayFilter.lua +2 -2
  13. package/dist/lualib/ArrayFind.lua +2 -2
  14. package/dist/lualib/ArrayFindIndex.lua +2 -2
  15. package/dist/lualib/ArrayFlat.lua +1 -1
  16. package/dist/lualib/ArrayFlatMap.lua +2 -2
  17. package/dist/lualib/ArrayForEach.lua +2 -2
  18. package/dist/lualib/ArrayIncludes.lua +1 -1
  19. package/dist/lualib/ArrayIndexOf.lua +1 -1
  20. package/dist/lualib/ArrayIsArray.lua +1 -1
  21. package/dist/lualib/ArrayJoin.lua +1 -1
  22. package/dist/lualib/ArrayMap.lua +2 -2
  23. package/dist/lualib/ArrayPush.lua +1 -1
  24. package/dist/lualib/ArrayReduce.lua +2 -2
  25. package/dist/lualib/ArrayReduceRight.lua +2 -2
  26. package/dist/lualib/ArrayReverse.lua +1 -1
  27. package/dist/lualib/ArraySetLength.lua +1 -1
  28. package/dist/lualib/ArrayShift.lua +1 -1
  29. package/dist/lualib/ArraySlice.lua +1 -1
  30. package/dist/lualib/ArraySome.lua +2 -2
  31. package/dist/lualib/ArraySort.lua +2 -2
  32. package/dist/lualib/ArraySplice.lua +1 -1
  33. package/dist/lualib/ArrayToObject.lua +1 -1
  34. package/dist/lualib/ArrayUnshift.lua +1 -1
  35. package/dist/lualib/Await.lua +13 -13
  36. package/dist/lualib/Class.lua +1 -1
  37. package/dist/lualib/ClassExtends.lua +1 -1
  38. package/dist/lualib/CloneDescriptor.lua +1 -1
  39. package/dist/lualib/Decorate.lua +5 -5
  40. package/dist/lualib/DecorateParam.lua +2 -2
  41. package/dist/lualib/DelegatedYield.lua +1 -1
  42. package/dist/lualib/Delete.lua +1 -1
  43. package/dist/lualib/Error.lua +68 -69
  44. package/dist/lualib/FunctionBind.lua +1 -1
  45. package/dist/lualib/Generator.lua +26 -23
  46. package/dist/lualib/InstanceOf.lua +1 -1
  47. package/dist/lualib/InstanceOfObject.lua +1 -1
  48. package/dist/lualib/Iterator.lua +35 -32
  49. package/dist/lualib/Map.lua +131 -129
  50. package/dist/lualib/MathAtan2.lua +1 -1
  51. package/dist/lualib/MathSign.lua +1 -1
  52. package/dist/lualib/New.lua +1 -1
  53. package/dist/lualib/Number.lua +1 -1
  54. package/dist/lualib/NumberIsFinite.lua +1 -1
  55. package/dist/lualib/NumberIsNaN.lua +1 -1
  56. package/dist/lualib/NumberToString.lua +42 -39
  57. package/dist/lualib/ObjectAssign.lua +1 -1
  58. package/dist/lualib/ObjectDefineProperty.lua +1 -1
  59. package/dist/lualib/ObjectEntries.lua +1 -1
  60. package/dist/lualib/ObjectFromEntries.lua +1 -1
  61. package/dist/lualib/ObjectGetOwnPropertyDescriptor.lua +1 -1
  62. package/dist/lualib/ObjectGetOwnPropertyDescriptors.lua +1 -1
  63. package/dist/lualib/ObjectKeys.lua +1 -1
  64. package/dist/lualib/ObjectRest.lua +1 -1
  65. package/dist/lualib/ObjectValues.lua +1 -1
  66. package/dist/lualib/ParseFloat.lua +1 -1
  67. package/dist/lualib/ParseInt.lua +39 -36
  68. package/dist/lualib/Promise.lua +148 -152
  69. package/dist/lualib/PromiseAll.lua +5 -5
  70. package/dist/lualib/PromiseAllSettled.lua +5 -5
  71. package/dist/lualib/PromiseAny.lua +5 -5
  72. package/dist/lualib/PromiseRace.lua +5 -5
  73. package/dist/lualib/Set.lua +120 -118
  74. package/dist/lualib/SetDescriptor.lua +67 -64
  75. package/dist/lualib/SourceMapTraceBack.lua +7 -6
  76. package/dist/lualib/SparseArrayNew.lua +1 -1
  77. package/dist/lualib/SparseArrayPush.lua +1 -1
  78. package/dist/lualib/SparseArraySpread.lua +1 -1
  79. package/dist/lualib/Spread.lua +1 -1
  80. package/dist/lualib/StringAccess.lua +1 -1
  81. package/dist/lualib/StringCharAt.lua +1 -1
  82. package/dist/lualib/StringCharCodeAt.lua +1 -1
  83. package/dist/lualib/StringConcat.lua +1 -1
  84. package/dist/lualib/StringEndsWith.lua +1 -1
  85. package/dist/lualib/StringIncludes.lua +1 -1
  86. package/dist/lualib/StringPadEnd.lua +1 -1
  87. package/dist/lualib/StringPadStart.lua +1 -1
  88. package/dist/lualib/StringReplace.lua +2 -2
  89. package/dist/lualib/StringReplaceAll.lua +4 -4
  90. package/dist/lualib/StringSlice.lua +1 -1
  91. package/dist/lualib/StringSplit.lua +1 -1
  92. package/dist/lualib/StringStartsWith.lua +1 -1
  93. package/dist/lualib/StringSubstr.lua +1 -1
  94. package/dist/lualib/StringSubstring.lua +1 -1
  95. package/dist/lualib/StringTrim.lua +1 -1
  96. package/dist/lualib/StringTrimEnd.lua +1 -1
  97. package/dist/lualib/StringTrimStart.lua +1 -1
  98. package/dist/lualib/Symbol.lua +14 -11
  99. package/dist/lualib/SymbolRegistry.lua +13 -10
  100. package/dist/lualib/TypeOf.lua +1 -1
  101. package/dist/lualib/Unpack.lua +1 -1
  102. package/dist/lualib/WeakMap.lua +41 -39
  103. package/dist/lualib/WeakSet.lua +37 -35
  104. package/dist/lualib/lualib_bundle.lua +1054 -924
  105. package/dist/lualib/lualib_module_info.json +619 -0
  106. package/dist/lualib-build/plugin.d.ts +23 -0
  107. package/dist/lualib-build/plugin.js +138 -0
  108. package/dist/lualib-build/util.d.ts +19 -0
  109. package/dist/lualib-build/util.js +43 -0
  110. package/dist/transformation/builtins/function.js +2 -1
  111. package/dist/transformation/builtins/index.d.ts +1 -0
  112. package/dist/transformation/builtins/index.js +63 -16
  113. package/dist/transformation/context/index.js +5 -1
  114. package/dist/transformation/utils/diagnostics.d.ts +3 -0
  115. package/dist/transformation/utils/diagnostics.js +2 -1
  116. package/dist/transformation/utils/typescript/index.js +5 -1
  117. package/dist/transformation/utils/typescript/types.d.ts +2 -0
  118. package/dist/transformation/utils/typescript/types.js +10 -1
  119. package/dist/transformation/visitors/class/index.js +1 -5
  120. package/dist/transformation/visitors/class/new.d.ts +1 -2
  121. package/dist/transformation/visitors/class/new.js +1 -40
  122. package/dist/transformation/visitors/conditional.js +15 -14
  123. package/dist/transformation/visitors/identifier.js +5 -0
  124. package/dist/transformation/visitors/literal.js +22 -0
  125. package/dist/transformation/visitors/modules/import.js +4 -14
  126. package/dist/transpilation/bundle.js +1 -1
  127. package/dist/transpilation/index.js +5 -1
  128. package/dist/transpilation/plugins.d.ts +11 -0
  129. package/dist/transpilation/transpile.js +13 -0
  130. package/dist/transpilation/transpiler.js +6 -2
  131. package/package.json +12 -11
  132. package/CHANGELOG.md +0 -703
@@ -1,8 +1,8 @@
1
- function __TS__ArrayIsArray(value)
1
+ local function __TS__ArrayIsArray(value)
2
2
  return type(value) == "table" and (value[1] ~= nil or next(value, nil) == nil)
3
3
  end
4
4
 
5
- function __TS__ArrayConcat(arr1, ...)
5
+ local function __TS__ArrayConcat(arr1, ...)
6
6
  local args = {...}
7
7
  local out = {}
8
8
  for ____, val in ipairs(arr1) do
@@ -21,7 +21,23 @@ function __TS__ArrayConcat(arr1, ...)
21
21
  return out
22
22
  end
23
23
 
24
- function __TS__ArrayEntries(array)
24
+ local __TS__Symbol, Symbol
25
+ do
26
+ local symbolMetatable = {__tostring = function(self)
27
+ return ("Symbol(" .. (self.description or "")) .. ")"
28
+ end}
29
+ function __TS__Symbol(description)
30
+ return setmetatable({description = description}, symbolMetatable)
31
+ end
32
+ Symbol = {
33
+ iterator = __TS__Symbol("Symbol.iterator"),
34
+ hasInstance = __TS__Symbol("Symbol.hasInstance"),
35
+ species = __TS__Symbol("Symbol.species"),
36
+ toStringTag = __TS__Symbol("Symbol.toStringTag")
37
+ }
38
+ end
39
+
40
+ local function __TS__ArrayEntries(array)
25
41
  local key = 0
26
42
  return {
27
43
  [Symbol.iterator] = function(self)
@@ -35,11 +51,11 @@ function __TS__ArrayEntries(array)
35
51
  }
36
52
  end
37
53
 
38
- function __TS__ArrayEvery(arr, callbackfn)
54
+ local function __TS__ArrayEvery(arr, callbackfn)
39
55
  do
40
56
  local i = 0
41
57
  while i < #arr do
42
- if not callbackfn(_G, arr[i + 1], i, arr) then
58
+ if not callbackfn(nil, arr[i + 1], i, arr) then
43
59
  return false
44
60
  end
45
61
  i = i + 1
@@ -48,12 +64,12 @@ function __TS__ArrayEvery(arr, callbackfn)
48
64
  return true
49
65
  end
50
66
 
51
- function __TS__ArrayFilter(arr, callbackfn)
67
+ local function __TS__ArrayFilter(arr, callbackfn)
52
68
  local result = {}
53
69
  do
54
70
  local i = 0
55
71
  while i < #arr do
56
- if callbackfn(_G, arr[i + 1], i, arr) then
72
+ if callbackfn(nil, arr[i + 1], i, arr) then
57
73
  result[#result + 1] = arr[i + 1]
58
74
  end
59
75
  i = i + 1
@@ -62,22 +78,22 @@ function __TS__ArrayFilter(arr, callbackfn)
62
78
  return result
63
79
  end
64
80
 
65
- function __TS__ArrayForEach(arr, callbackFn)
81
+ local function __TS__ArrayForEach(arr, callbackFn)
66
82
  do
67
83
  local i = 0
68
84
  while i < #arr do
69
- callbackFn(_G, arr[i + 1], i, arr)
85
+ callbackFn(nil, arr[i + 1], i, arr)
70
86
  i = i + 1
71
87
  end
72
88
  end
73
89
  end
74
90
 
75
- function __TS__ArrayFind(arr, predicate)
91
+ local function __TS__ArrayFind(arr, predicate)
76
92
  local len = #arr
77
93
  local k = 0
78
94
  while k < len do
79
95
  local elem = arr[k + 1]
80
- if predicate(_G, elem, k, arr) then
96
+ if predicate(nil, elem, k, arr) then
81
97
  return elem
82
98
  end
83
99
  k = k + 1
@@ -85,12 +101,12 @@ function __TS__ArrayFind(arr, predicate)
85
101
  return nil
86
102
  end
87
103
 
88
- function __TS__ArrayFindIndex(arr, callbackFn)
104
+ local function __TS__ArrayFindIndex(arr, callbackFn)
89
105
  do
90
106
  local i = 0
91
107
  local len = #arr
92
108
  while i < len do
93
- if callbackFn(_G, arr[i + 1], i, arr) then
109
+ if callbackFn(nil, arr[i + 1], i, arr) then
94
110
  return i
95
111
  end
96
112
  i = i + 1
@@ -99,7 +115,7 @@ function __TS__ArrayFindIndex(arr, callbackFn)
99
115
  return -1
100
116
  end
101
117
 
102
- function __TS__ArrayIncludes(self, searchElement, fromIndex)
118
+ local function __TS__ArrayIncludes(self, searchElement, fromIndex)
103
119
  if fromIndex == nil then
104
120
  fromIndex = 0
105
121
  end
@@ -119,7 +135,7 @@ function __TS__ArrayIncludes(self, searchElement, fromIndex)
119
135
  return false
120
136
  end
121
137
 
122
- function __TS__ArrayIndexOf(arr, searchElement, fromIndex)
138
+ local function __TS__ArrayIndexOf(arr, searchElement, fromIndex)
123
139
  local len = #arr
124
140
  if len == 0 then
125
141
  return -1
@@ -152,7 +168,7 @@ function __TS__ArrayIndexOf(arr, searchElement, fromIndex)
152
168
  return -1
153
169
  end
154
170
 
155
- function __TS__ArrayJoin(self, separator)
171
+ local function __TS__ArrayJoin(self, separator)
156
172
  if separator == nil then
157
173
  separator = ","
158
174
  end
@@ -166,19 +182,19 @@ function __TS__ArrayJoin(self, separator)
166
182
  return result
167
183
  end
168
184
 
169
- function __TS__ArrayMap(arr, callbackfn)
185
+ local function __TS__ArrayMap(arr, callbackfn)
170
186
  local newArray = {}
171
187
  do
172
188
  local i = 0
173
189
  while i < #arr do
174
- newArray[i + 1] = callbackfn(_G, arr[i + 1], i, arr)
190
+ newArray[i + 1] = callbackfn(nil, arr[i + 1], i, arr)
175
191
  i = i + 1
176
192
  end
177
193
  end
178
194
  return newArray
179
195
  end
180
196
 
181
- function __TS__ArrayPush(arr, ...)
197
+ local function __TS__ArrayPush(arr, ...)
182
198
  local items = {...}
183
199
  for ____, item in ipairs(items) do
184
200
  arr[#arr + 1] = item
@@ -186,7 +202,7 @@ function __TS__ArrayPush(arr, ...)
186
202
  return #arr
187
203
  end
188
204
 
189
- function __TS__ArrayReduce(arr, callbackFn, ...)
205
+ local function __TS__ArrayReduce(arr, callbackFn, ...)
190
206
  local len = #arr
191
207
  local k = 0
192
208
  local accumulator = nil
@@ -200,7 +216,7 @@ function __TS__ArrayReduce(arr, callbackFn, ...)
200
216
  end
201
217
  for i = k, len - 1 do
202
218
  accumulator = callbackFn(
203
- _G,
219
+ nil,
204
220
  accumulator,
205
221
  arr[i + 1],
206
222
  i,
@@ -210,7 +226,7 @@ function __TS__ArrayReduce(arr, callbackFn, ...)
210
226
  return accumulator
211
227
  end
212
228
 
213
- function __TS__ArrayReduceRight(arr, callbackFn, ...)
229
+ local function __TS__ArrayReduceRight(arr, callbackFn, ...)
214
230
  local len = #arr
215
231
  local k = len - 1
216
232
  local accumulator = nil
@@ -224,7 +240,7 @@ function __TS__ArrayReduceRight(arr, callbackFn, ...)
224
240
  end
225
241
  for i = k, 0, -1 do
226
242
  accumulator = callbackFn(
227
- _G,
243
+ nil,
228
244
  accumulator,
229
245
  arr[i + 1],
230
246
  i,
@@ -234,7 +250,7 @@ function __TS__ArrayReduceRight(arr, callbackFn, ...)
234
250
  return accumulator
235
251
  end
236
252
 
237
- function __TS__ArrayReverse(arr)
253
+ local function __TS__ArrayReverse(arr)
238
254
  local i = 0
239
255
  local j = #arr - 1
240
256
  while i < j do
@@ -247,11 +263,11 @@ function __TS__ArrayReverse(arr)
247
263
  return arr
248
264
  end
249
265
 
250
- function __TS__ArrayShift(arr)
266
+ local function __TS__ArrayShift(arr)
251
267
  return table.remove(arr, 1)
252
268
  end
253
269
 
254
- function __TS__ArrayUnshift(arr, ...)
270
+ local function __TS__ArrayUnshift(arr, ...)
255
271
  local items = {...}
256
272
  do
257
273
  local i = #items - 1
@@ -263,11 +279,11 @@ function __TS__ArrayUnshift(arr, ...)
263
279
  return #arr
264
280
  end
265
281
 
266
- function __TS__ArraySort(arr, compareFn)
282
+ local function __TS__ArraySort(arr, compareFn)
267
283
  if compareFn ~= nil then
268
284
  table.sort(
269
285
  arr,
270
- function(a, b) return compareFn(_G, a, b) < 0 end
286
+ function(a, b) return compareFn(nil, a, b) < 0 end
271
287
  )
272
288
  else
273
289
  table.sort(arr)
@@ -275,7 +291,7 @@ function __TS__ArraySort(arr, compareFn)
275
291
  return arr
276
292
  end
277
293
 
278
- function __TS__ArraySlice(list, first, last)
294
+ local function __TS__ArraySlice(list, first, last)
279
295
  local len = #list
280
296
  local relativeStart = first or 0
281
297
  local k
@@ -304,11 +320,11 @@ function __TS__ArraySlice(list, first, last)
304
320
  return out
305
321
  end
306
322
 
307
- function __TS__ArraySome(arr, callbackfn)
323
+ local function __TS__ArraySome(arr, callbackfn)
308
324
  do
309
325
  local i = 0
310
326
  while i < #arr do
311
- if callbackfn(_G, arr[i + 1], i, arr) then
327
+ if callbackfn(nil, arr[i + 1], i, arr) then
312
328
  return true
313
329
  end
314
330
  i = i + 1
@@ -317,7 +333,7 @@ function __TS__ArraySome(arr, callbackfn)
317
333
  return false
318
334
  end
319
335
 
320
- function __TS__ArraySplice(list, ...)
336
+ local function __TS__ArraySplice(list, ...)
321
337
  local len = #list
322
338
  local actualArgumentCount = select("#", ...)
323
339
  local start = select(1, ...)
@@ -402,7 +418,7 @@ function __TS__ArraySplice(list, ...)
402
418
  return out
403
419
  end
404
420
 
405
- function __TS__ArrayToObject(array)
421
+ local function __TS__ArrayToObject(array)
406
422
  local object = {}
407
423
  do
408
424
  local i = 0
@@ -414,7 +430,7 @@ function __TS__ArrayToObject(array)
414
430
  return object
415
431
  end
416
432
 
417
- function __TS__ArrayFlat(array, depth)
433
+ local function __TS__ArrayFlat(array, depth)
418
434
  if depth == nil then
419
435
  depth = 1
420
436
  end
@@ -432,12 +448,12 @@ function __TS__ArrayFlat(array, depth)
432
448
  return result
433
449
  end
434
450
 
435
- function __TS__ArrayFlatMap(array, callback)
451
+ local function __TS__ArrayFlatMap(array, callback)
436
452
  local result = {}
437
453
  do
438
454
  local i = 0
439
455
  while i < #array do
440
- local value = callback(_G, array[i + 1], i, array)
456
+ local value = callback(nil, array[i + 1], i, array)
441
457
  if type(value) == "table" and __TS__ArrayIsArray(value) then
442
458
  result = __TS__ArrayConcat(result, value)
443
459
  else
@@ -449,7 +465,7 @@ function __TS__ArrayFlatMap(array, callback)
449
465
  return result
450
466
  end
451
467
 
452
- function __TS__ArraySetLength(arr, length)
468
+ local function __TS__ArraySetLength(arr, length)
453
469
  if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
454
470
  error(
455
471
  "invalid array length: " .. tostring(length),
@@ -466,20 +482,7 @@ function __TS__ArraySetLength(arr, length)
466
482
  return length
467
483
  end
468
484
 
469
- ____symbolMetatable = {__tostring = function(self)
470
- return ("Symbol(" .. (self.description or "")) .. ")"
471
- end}
472
- function __TS__Symbol(description)
473
- return setmetatable({description = description}, ____symbolMetatable)
474
- end
475
- Symbol = {
476
- iterator = __TS__Symbol("Symbol.iterator"),
477
- hasInstance = __TS__Symbol("Symbol.hasInstance"),
478
- species = __TS__Symbol("Symbol.species"),
479
- toStringTag = __TS__Symbol("Symbol.toStringTag")
480
- }
481
-
482
- function __TS__InstanceOf(obj, classTbl)
485
+ local function __TS__InstanceOf(obj, classTbl)
483
486
  if type(classTbl) ~= "table" then
484
487
  error("Right-hand side of 'instanceof' is not an object", 0)
485
488
  end
@@ -498,22 +501,22 @@ function __TS__InstanceOf(obj, classTbl)
498
501
  return false
499
502
  end
500
503
 
501
- function __TS__New(target, ...)
504
+ local function __TS__New(target, ...)
502
505
  local instance = setmetatable({}, target.prototype)
503
506
  instance:____constructor(...)
504
507
  return instance
505
508
  end
506
509
 
507
- function __TS__Class(self)
510
+ local function __TS__Class(self)
508
511
  local c = {prototype = {}}
509
512
  c.prototype.__index = c.prototype
510
513
  c.prototype.constructor = c
511
514
  return c
512
515
  end
513
516
 
514
- __TS__Unpack = table.unpack or unpack
517
+ local __TS__Unpack = table.unpack or unpack
515
518
 
516
- function __TS__FunctionBind(fn, thisArg, ...)
519
+ local function __TS__FunctionBind(fn, thisArg, ...)
517
520
  local boundArgs = {...}
518
521
  return function(____, ...)
519
522
  local args = {...}
@@ -531,184 +534,180 @@ function __TS__FunctionBind(fn, thisArg, ...)
531
534
  end
532
535
  end
533
536
 
534
- __TS__PromiseState = __TS__PromiseState or ({})
535
- __TS__PromiseState.Pending = 0
536
- __TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
537
- __TS__PromiseState.Fulfilled = 1
538
- __TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
539
- __TS__PromiseState.Rejected = 2
540
- __TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
541
- function __TS__PromiseDeferred(self)
542
- local resolve
543
- local reject
544
- local promise = __TS__New(
545
- __TS__Promise,
546
- function(____, res, rej)
547
- resolve = res
548
- reject = rej
549
- end
550
- )
551
- return {promise = promise, resolve = resolve, reject = reject}
552
- end
553
- function __TS__IsPromiseLike(self, thing)
554
- return __TS__InstanceOf(thing, __TS__Promise)
555
- end
556
- __TS__Promise = __TS__Class()
557
- __TS__Promise.name = "__TS__Promise"
558
- function __TS__Promise.prototype.____constructor(self, executor)
559
- self.state = __TS__PromiseState.Pending
560
- self.fulfilledCallbacks = {}
561
- self.rejectedCallbacks = {}
562
- self.finallyCallbacks = {}
563
- do
564
- local function ____catch(e)
565
- self:reject(e)
566
- end
567
- local ____try, ____hasReturned = pcall(function()
568
- executor(
569
- _G,
570
- __TS__FunctionBind(self.resolve, self),
571
- __TS__FunctionBind(self.reject, self)
572
- )
573
- end)
574
- if not ____try then
575
- ____catch(____hasReturned)
537
+ local __TS__Promise
538
+ do
539
+ local function promiseDeferred(self)
540
+ local resolve
541
+ local reject
542
+ local promise = __TS__New(
543
+ __TS__Promise,
544
+ function(____, res, rej)
545
+ resolve = res
546
+ reject = rej
547
+ end
548
+ )
549
+ return {promise = promise, resolve = resolve, reject = reject}
550
+ end
551
+ local function isPromiseLike(self, thing)
552
+ return __TS__InstanceOf(thing, __TS__Promise)
553
+ end
554
+ __TS__Promise = __TS__Class()
555
+ __TS__Promise.name = "__TS__Promise"
556
+ function __TS__Promise.prototype.____constructor(self, executor)
557
+ self.state = 0
558
+ self.fulfilledCallbacks = {}
559
+ self.rejectedCallbacks = {}
560
+ self.finallyCallbacks = {}
561
+ do
562
+ local function ____catch(e)
563
+ self:reject(e)
564
+ end
565
+ local ____try, ____hasReturned = pcall(function()
566
+ executor(
567
+ nil,
568
+ __TS__FunctionBind(self.resolve, self),
569
+ __TS__FunctionBind(self.reject, self)
570
+ )
571
+ end)
572
+ if not ____try then
573
+ ____catch(____hasReturned)
574
+ end
576
575
  end
577
576
  end
578
- end
579
- function __TS__Promise.resolve(data)
580
- local promise = __TS__New(
581
- __TS__Promise,
582
- function()
577
+ function __TS__Promise.resolve(data)
578
+ local promise = __TS__New(
579
+ __TS__Promise,
580
+ function()
581
+ end
582
+ )
583
+ promise.state = 1
584
+ promise.value = data
585
+ return promise
586
+ end
587
+ function __TS__Promise.reject(reason)
588
+ local promise = __TS__New(
589
+ __TS__Promise,
590
+ function()
591
+ end
592
+ )
593
+ promise.state = 2
594
+ promise.rejectionReason = reason
595
+ return promise
596
+ end
597
+ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
598
+ local ____promiseDeferred_result_0 = promiseDeferred(nil)
599
+ local promise = ____promiseDeferred_result_0.promise
600
+ local resolve = ____promiseDeferred_result_0.resolve
601
+ local reject = ____promiseDeferred_result_0.reject
602
+ local isFulfilled = self.state == 1
603
+ local isRejected = self.state == 2
604
+ if onFulfilled then
605
+ local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
606
+ __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
607
+ if isFulfilled then
608
+ internalCallback(nil, self.value)
609
+ end
610
+ else
611
+ __TS__ArrayPush(
612
+ self.fulfilledCallbacks,
613
+ function() return resolve(nil, nil) end
614
+ )
583
615
  end
584
- )
585
- promise.state = __TS__PromiseState.Fulfilled
586
- promise.value = data
587
- return promise
588
- end
589
- function __TS__Promise.reject(reason)
590
- local promise = __TS__New(
591
- __TS__Promise,
592
- function()
616
+ if onRejected then
617
+ local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
618
+ __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
619
+ if isRejected then
620
+ internalCallback(nil, self.rejectionReason)
621
+ end
593
622
  end
594
- )
595
- promise.state = __TS__PromiseState.Rejected
596
- promise.rejectionReason = reason
597
- return promise
598
- end
599
- __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
600
- local ____TS__PromiseDeferred_result_0 = __TS__PromiseDeferred(_G)
601
- local promise = ____TS__PromiseDeferred_result_0.promise
602
- local resolve = ____TS__PromiseDeferred_result_0.resolve
603
- local reject = ____TS__PromiseDeferred_result_0.reject
604
- local isFulfilled = self.state == __TS__PromiseState.Fulfilled
605
- local isRejected = self.state == __TS__PromiseState.Rejected
606
- if onFulfilled then
607
- local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
608
- __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
609
623
  if isFulfilled then
610
- internalCallback(_G, self.value)
624
+ resolve(nil, self.value)
611
625
  end
612
- else
613
- __TS__ArrayPush(
614
- self.fulfilledCallbacks,
615
- function() return resolve(_G, nil) end
616
- )
617
- end
618
- if onRejected then
619
- local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
620
- __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
621
626
  if isRejected then
622
- internalCallback(_G, self.rejectionReason)
627
+ reject(nil, self.rejectionReason)
623
628
  end
629
+ return promise
624
630
  end
625
- if isFulfilled then
626
- resolve(_G, self.value)
627
- end
628
- if isRejected then
629
- reject(_G, self.rejectionReason)
631
+ function __TS__Promise.prototype.catch(self, onRejected)
632
+ return self["then"](self, nil, onRejected)
630
633
  end
631
- return promise
632
- end
633
- function __TS__Promise.prototype.catch(self, onRejected)
634
- return self["then"](self, nil, onRejected)
635
- end
636
- function __TS__Promise.prototype.finally(self, onFinally)
637
- if onFinally then
638
- __TS__ArrayPush(self.finallyCallbacks, onFinally)
639
- if self.state ~= __TS__PromiseState.Pending then
640
- onFinally(_G)
634
+ function __TS__Promise.prototype.finally(self, onFinally)
635
+ if onFinally then
636
+ __TS__ArrayPush(self.finallyCallbacks, onFinally)
637
+ if self.state ~= 0 then
638
+ onFinally(nil)
639
+ end
641
640
  end
641
+ return self
642
642
  end
643
- return self
644
- end
645
- function __TS__Promise.prototype.resolve(self, data)
646
- if __TS__InstanceOf(data, __TS__Promise) then
647
- data["then"](
648
- data,
649
- function(____, v) return self:resolve(v) end,
650
- function(____, err) return self:reject(err) end
651
- )
652
- return
653
- end
654
- if self.state == __TS__PromiseState.Pending then
655
- self.state = __TS__PromiseState.Fulfilled
656
- self.value = data
657
- for ____, callback in ipairs(self.fulfilledCallbacks) do
658
- callback(_G, data)
643
+ function __TS__Promise.prototype.resolve(self, data)
644
+ if __TS__InstanceOf(data, __TS__Promise) then
645
+ data["then"](
646
+ data,
647
+ function(____, v) return self:resolve(v) end,
648
+ function(____, err) return self:reject(err) end
649
+ )
650
+ return
659
651
  end
660
- for ____, callback in ipairs(self.finallyCallbacks) do
661
- callback(_G)
652
+ if self.state == 0 then
653
+ self.state = 1
654
+ self.value = data
655
+ for ____, callback in ipairs(self.fulfilledCallbacks) do
656
+ callback(nil, data)
657
+ end
658
+ for ____, callback in ipairs(self.finallyCallbacks) do
659
+ callback(nil)
660
+ end
662
661
  end
663
662
  end
664
- end
665
- function __TS__Promise.prototype.reject(self, reason)
666
- if self.state == __TS__PromiseState.Pending then
667
- self.state = __TS__PromiseState.Rejected
668
- self.rejectionReason = reason
669
- for ____, callback in ipairs(self.rejectedCallbacks) do
670
- callback(_G, reason)
671
- end
672
- for ____, callback in ipairs(self.finallyCallbacks) do
673
- callback(_G)
663
+ function __TS__Promise.prototype.reject(self, reason)
664
+ if self.state == 0 then
665
+ self.state = 2
666
+ self.rejectionReason = reason
667
+ for ____, callback in ipairs(self.rejectedCallbacks) do
668
+ callback(nil, reason)
669
+ end
670
+ for ____, callback in ipairs(self.finallyCallbacks) do
671
+ callback(nil)
672
+ end
674
673
  end
675
674
  end
676
- end
677
- function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
678
- return function(____, value)
679
- do
680
- local function ____catch(e)
681
- reject(_G, e)
682
- end
683
- local ____try, ____hasReturned = pcall(function()
684
- self:handleCallbackData(
685
- f(_G, value),
686
- resolve,
687
- reject
688
- )
689
- end)
690
- if not ____try then
691
- ____catch(____hasReturned)
675
+ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
676
+ return function(____, value)
677
+ do
678
+ local function ____catch(e)
679
+ reject(nil, e)
680
+ end
681
+ local ____try, ____hasReturned = pcall(function()
682
+ self:handleCallbackData(
683
+ f(nil, value),
684
+ resolve,
685
+ reject
686
+ )
687
+ end)
688
+ if not ____try then
689
+ ____catch(____hasReturned)
690
+ end
692
691
  end
693
692
  end
694
693
  end
695
- end
696
- function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
697
- if __TS__IsPromiseLike(_G, data) then
698
- local nextpromise = data
699
- if nextpromise.state == __TS__PromiseState.Fulfilled then
700
- resolve(_G, nextpromise.value)
701
- elseif nextpromise.state == __TS__PromiseState.Rejected then
702
- reject(_G, nextpromise.rejectionReason)
694
+ function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
695
+ if isPromiseLike(nil, data) then
696
+ local nextpromise = data
697
+ if nextpromise.state == 1 then
698
+ resolve(nil, nextpromise.value)
699
+ elseif nextpromise.state == 2 then
700
+ reject(nil, nextpromise.rejectionReason)
701
+ else
702
+ data["then"](data, resolve, reject)
703
+ end
703
704
  else
704
- data["then"](data, resolve, reject)
705
+ resolve(nil, data)
705
706
  end
706
- else
707
- resolve(_G, data)
708
707
  end
709
708
  end
710
709
 
711
- function __TS__AsyncAwaiter(generator)
710
+ local function __TS__AsyncAwaiter(generator)
712
711
  return __TS__New(
713
712
  __TS__Promise,
714
713
  function(____, resolve, reject)
@@ -725,9 +724,9 @@ function __TS__AsyncAwaiter(generator)
725
724
  function fulfilled(self, value)
726
725
  local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
727
726
  if success then
728
- step(_G, resultOrError, errorOrErrorHandler)
727
+ step(nil, resultOrError, errorOrErrorHandler)
729
728
  else
730
- reject(_G, errorOrErrorHandler)
729
+ reject(nil, errorOrErrorHandler)
731
730
  end
732
731
  end
733
732
  function rejected(self, handler)
@@ -736,47 +735,47 @@ function __TS__AsyncAwaiter(generator)
736
735
  local success, hasReturnedOrError, returnedValue = pcall(handler, value)
737
736
  if success then
738
737
  if hasReturnedOrError then
739
- resolve(_G, returnedValue)
738
+ resolve(nil, returnedValue)
740
739
  else
741
- step(_G, hasReturnedOrError, handler)
740
+ step(nil, hasReturnedOrError, handler)
742
741
  end
743
742
  else
744
- reject(_G, hasReturnedOrError)
743
+ reject(nil, hasReturnedOrError)
745
744
  end
746
745
  end
747
746
  else
748
747
  return function(____, value)
749
- reject(_G, value)
748
+ reject(nil, value)
750
749
  end
751
750
  end
752
751
  end
753
752
  function step(self, result, errorHandler)
754
753
  if coroutine.status(asyncCoroutine) == "dead" then
755
- resolve(_G, result)
754
+ resolve(nil, result)
756
755
  else
757
- local ____self_1 = adopt(_G, result)
756
+ local ____self_1 = adopt(nil, result)
758
757
  ____self_1["then"](
759
758
  ____self_1,
760
759
  fulfilled,
761
- rejected(_G, errorHandler)
760
+ rejected(nil, errorHandler)
762
761
  )
763
762
  end
764
763
  end
765
764
  asyncCoroutine = coroutine.create(generator)
766
765
  local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
767
766
  if success then
768
- step(_G, resultOrError, errorOrErrorHandler)
767
+ step(nil, resultOrError, errorOrErrorHandler)
769
768
  else
770
- reject(_G, errorOrErrorHandler)
769
+ reject(nil, errorOrErrorHandler)
771
770
  end
772
771
  end
773
772
  )
774
773
  end
775
- function __TS__Await(errorHandler, thing)
774
+ local function __TS__Await(errorHandler, thing)
776
775
  return coroutine.yield(errorHandler, thing)
777
776
  end
778
777
 
779
- function __TS__ClassExtends(target, base)
778
+ local function __TS__ClassExtends(target, base)
780
779
  target.____super = base
781
780
  local staticMetatable = setmetatable({__index = base}, base)
782
781
  setmetatable(target, staticMetatable)
@@ -801,7 +800,7 @@ function __TS__ClassExtends(target, base)
801
800
  end
802
801
  end
803
802
 
804
- function __TS__CloneDescriptor(____bindingPattern0)
803
+ local function __TS__CloneDescriptor(____bindingPattern0)
805
804
  local value
806
805
  local writable
807
806
  local set
@@ -830,7 +829,20 @@ function __TS__CloneDescriptor(____bindingPattern0)
830
829
  return descriptor
831
830
  end
832
831
 
833
- function __TS__ObjectGetOwnPropertyDescriptor(object, key)
832
+ local function __TS__ObjectAssign(to, ...)
833
+ local sources = {...}
834
+ if to == nil then
835
+ return to
836
+ end
837
+ for ____, source in ipairs(sources) do
838
+ for key in pairs(source) do
839
+ to[key] = source[key]
840
+ end
841
+ end
842
+ return to
843
+ end
844
+
845
+ local function __TS__ObjectGetOwnPropertyDescriptor(object, key)
834
846
  local metatable = getmetatable(object)
835
847
  if not metatable then
836
848
  return
@@ -841,97 +853,87 @@ function __TS__ObjectGetOwnPropertyDescriptor(object, key)
841
853
  return rawget(metatable, "_descriptors")[key]
842
854
  end
843
855
 
844
- function ____descriptorIndex(self, key)
845
- local value = rawget(self, key)
846
- if value ~= nil then
847
- return value
848
- end
849
- local metatable = getmetatable(self)
850
- while metatable do
851
- local rawResult = rawget(metatable, key)
852
- if rawResult ~= nil then
853
- return rawResult
854
- end
855
- local descriptors = rawget(metatable, "_descriptors")
856
- if descriptors then
857
- local descriptor = descriptors[key]
858
- if descriptor then
859
- if descriptor.get then
860
- return descriptor.get(self)
856
+ local __TS__SetDescriptor
857
+ do
858
+ local function descriptorIndex(self, key)
859
+ local value = rawget(self, key)
860
+ if value ~= nil then
861
+ return value
862
+ end
863
+ local metatable = getmetatable(self)
864
+ while metatable do
865
+ local rawResult = rawget(metatable, key)
866
+ if rawResult ~= nil then
867
+ return rawResult
868
+ end
869
+ local descriptors = rawget(metatable, "_descriptors")
870
+ if descriptors then
871
+ local descriptor = descriptors[key]
872
+ if descriptor then
873
+ if descriptor.get then
874
+ return descriptor.get(self)
875
+ end
876
+ return descriptor.value
861
877
  end
862
- return descriptor.value
863
878
  end
864
- end
865
- metatable = getmetatable(metatable)
866
- end
867
- end
868
- function ____descriptorNewindex(self, key, value)
869
- local metatable = getmetatable(self)
870
- while metatable do
871
- local descriptors = rawget(metatable, "_descriptors")
872
- if descriptors then
873
- local descriptor = descriptors[key]
874
- if descriptor then
875
- if descriptor.set then
876
- descriptor.set(self, value)
877
- else
878
- if descriptor.writable == false then
879
- error(
880
- ((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
881
- 0
882
- )
879
+ metatable = getmetatable(metatable)
880
+ end
881
+ end
882
+ local function descriptorNewIndex(self, key, value)
883
+ local metatable = getmetatable(self)
884
+ while metatable do
885
+ local descriptors = rawget(metatable, "_descriptors")
886
+ if descriptors then
887
+ local descriptor = descriptors[key]
888
+ if descriptor then
889
+ if descriptor.set then
890
+ descriptor.set(self, value)
891
+ else
892
+ if descriptor.writable == false then
893
+ error(
894
+ ((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
895
+ 0
896
+ )
897
+ end
898
+ descriptor.value = value
883
899
  end
884
- descriptor.value = value
900
+ return
885
901
  end
886
- return
887
902
  end
903
+ metatable = getmetatable(metatable)
888
904
  end
889
- metatable = getmetatable(metatable)
890
- end
891
- rawset(self, key, value)
892
- end
893
- function __TS__SetDescriptor(target, key, desc, isPrototype)
894
- if isPrototype == nil then
895
- isPrototype = false
896
- end
897
- local ____isPrototype_0
898
- if isPrototype then
899
- ____isPrototype_0 = target
900
- else
901
- ____isPrototype_0 = getmetatable(target)
905
+ rawset(self, key, value)
902
906
  end
903
- local metatable = ____isPrototype_0
904
- if not metatable then
905
- metatable = {}
906
- setmetatable(target, metatable)
907
- end
908
- local value = rawget(target, key)
909
- if value ~= nil then
910
- rawset(target, key, nil)
911
- end
912
- if not rawget(metatable, "_descriptors") then
913
- metatable._descriptors = {}
914
- end
915
- local descriptor = __TS__CloneDescriptor(desc)
916
- metatable._descriptors[key] = descriptor
917
- metatable.__index = ____descriptorIndex
918
- metatable.__newindex = ____descriptorNewindex
919
- end
920
-
921
- function __TS__ObjectAssign(to, ...)
922
- local sources = {...}
923
- if to == nil then
924
- return to
925
- end
926
- for ____, source in ipairs(sources) do
927
- for key in pairs(source) do
928
- to[key] = source[key]
907
+ function __TS__SetDescriptor(target, key, desc, isPrototype)
908
+ if isPrototype == nil then
909
+ isPrototype = false
910
+ end
911
+ local ____isPrototype_0
912
+ if isPrototype then
913
+ ____isPrototype_0 = target
914
+ else
915
+ ____isPrototype_0 = getmetatable(target)
929
916
  end
917
+ local metatable = ____isPrototype_0
918
+ if not metatable then
919
+ metatable = {}
920
+ setmetatable(target, metatable)
921
+ end
922
+ local value = rawget(target, key)
923
+ if value ~= nil then
924
+ rawset(target, key, nil)
925
+ end
926
+ if not rawget(metatable, "_descriptors") then
927
+ metatable._descriptors = {}
928
+ end
929
+ local descriptor = __TS__CloneDescriptor(desc)
930
+ metatable._descriptors[key] = descriptor
931
+ metatable.__index = descriptorIndex
932
+ metatable.__newindex = descriptorNewIndex
930
933
  end
931
- return to
932
934
  end
933
935
 
934
- function __TS__Decorate(decorators, target, key, desc)
936
+ local function __TS__Decorate(decorators, target, key, desc)
935
937
  local result = target
936
938
  do
937
939
  local i = #decorators
@@ -940,11 +942,11 @@ function __TS__Decorate(decorators, target, key, desc)
940
942
  if decorator then
941
943
  local oldResult = result
942
944
  if key == nil then
943
- result = decorator(_G, result)
945
+ result = decorator(nil, result)
944
946
  elseif desc == true then
945
947
  local value = rawget(target, key)
946
948
  local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
947
- local desc = decorator(_G, target, key, descriptor) or descriptor
949
+ local desc = decorator(nil, target, key, descriptor) or descriptor
948
950
  local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
949
951
  if isSimpleValue then
950
952
  rawset(target, key, desc.value)
@@ -956,9 +958,9 @@ function __TS__Decorate(decorators, target, key, desc)
956
958
  )
957
959
  end
958
960
  elseif desc == false then
959
- result = decorator(_G, target, key, desc)
961
+ result = decorator(nil, target, key, desc)
960
962
  else
961
- result = decorator(_G, target, key)
963
+ result = decorator(nil, target, key)
962
964
  end
963
965
  result = result or oldResult
964
966
  end
@@ -968,98 +970,97 @@ function __TS__Decorate(decorators, target, key, desc)
968
970
  return result
969
971
  end
970
972
 
971
- function __TS__DecorateParam(paramIndex, decorator)
972
- return function(____, target, key) return decorator(_G, target, key, paramIndex) end
973
+ local function __TS__DecorateParam(paramIndex, decorator)
974
+ return function(____, target, key) return decorator(nil, target, key, paramIndex) end
973
975
  end
974
976
 
975
- function __TS__ObjectGetOwnPropertyDescriptors(object)
976
- local metatable = getmetatable(object)
977
- if not metatable then
978
- return {}
977
+ local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
978
+ do
979
+ local function getErrorStack(self, constructor)
980
+ local level = 1
981
+ while true do
982
+ local info = debug.getinfo(level, "f")
983
+ level = level + 1
984
+ if not info then
985
+ level = 1
986
+ break
987
+ elseif info.func == constructor then
988
+ break
989
+ end
990
+ end
991
+ return debug.traceback(nil, level)
979
992
  end
980
- return rawget(metatable, "_descriptors") or ({})
981
- end
982
-
983
- function __TS__GetErrorStack(self, constructor)
984
- local level = 1
985
- while true do
986
- local info = debug.getinfo(level, "f")
987
- level = level + 1
988
- if not info then
989
- level = 1
990
- break
991
- elseif info.func == constructor then
992
- break
993
+ local function wrapErrorToString(self, getDescription)
994
+ return function(self)
995
+ local description = getDescription(self)
996
+ local caller = debug.getinfo(3, "f")
997
+ if _VERSION == "Lua 5.1" or caller and caller.func ~= error then
998
+ return description
999
+ else
1000
+ return (tostring(description) .. "\n") .. self.stack
1001
+ end
993
1002
  end
994
1003
  end
995
- return debug.traceback(nil, level)
996
- end
997
- function __TS__WrapErrorToString(self, getDescription)
998
- return function(self)
999
- local description = getDescription(self)
1000
- local caller = debug.getinfo(3, "f")
1001
- if _VERSION == "Lua 5.1" or caller and caller.func ~= error then
1002
- return description
1004
+ local function initErrorClass(self, Type, name)
1005
+ Type.name = name
1006
+ return setmetatable(
1007
+ Type,
1008
+ {__call = function(____, _self, message) return __TS__New(Type, message) end}
1009
+ )
1010
+ end
1011
+ local ____initErrorClass_2 = initErrorClass
1012
+ local ____class_0 = __TS__Class()
1013
+ ____class_0.name = ""
1014
+ function ____class_0.prototype.____constructor(self, message)
1015
+ if message == nil then
1016
+ message = ""
1017
+ end
1018
+ self.message = message
1019
+ self.name = "Error"
1020
+ self.stack = getErrorStack(nil, self.constructor.new)
1021
+ local metatable = getmetatable(self)
1022
+ if not metatable.__errorToStringPatched then
1023
+ metatable.__errorToStringPatched = true
1024
+ metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
1025
+ end
1026
+ end
1027
+ function ____class_0.prototype.__tostring(self)
1028
+ local ____temp_1
1029
+ if self.message ~= "" then
1030
+ ____temp_1 = (self.name .. ": ") .. self.message
1003
1031
  else
1004
- return (tostring(description) .. "\n") .. self.stack
1032
+ ____temp_1 = self.name
1005
1033
  end
1034
+ return ____temp_1
1006
1035
  end
1036
+ Error = ____initErrorClass_2(nil, ____class_0, "Error")
1037
+ local function createErrorClass(self, name)
1038
+ local ____initErrorClass_4 = initErrorClass
1039
+ local ____class_3 = __TS__Class()
1040
+ ____class_3.name = ____class_3.name
1041
+ __TS__ClassExtends(____class_3, Error)
1042
+ function ____class_3.prototype.____constructor(self, ...)
1043
+ ____class_3.____super.prototype.____constructor(self, ...)
1044
+ self.name = name
1045
+ end
1046
+ return ____initErrorClass_4(nil, ____class_3, name)
1047
+ end
1048
+ RangeError = createErrorClass(nil, "RangeError")
1049
+ ReferenceError = createErrorClass(nil, "ReferenceError")
1050
+ SyntaxError = createErrorClass(nil, "SyntaxError")
1051
+ TypeError = createErrorClass(nil, "TypeError")
1052
+ URIError = createErrorClass(nil, "URIError")
1007
1053
  end
1008
- function __TS__InitErrorClass(self, Type, name)
1009
- Type.name = name
1010
- return setmetatable(
1011
- Type,
1012
- {__call = function(____, _self, message) return __TS__New(Type, message) end}
1013
- )
1054
+
1055
+ local function __TS__ObjectGetOwnPropertyDescriptors(object)
1056
+ local metatable = getmetatable(object)
1057
+ if not metatable then
1058
+ return {}
1059
+ end
1060
+ return rawget(metatable, "_descriptors") or ({})
1014
1061
  end
1015
- local ____TS__InitErrorClass_3 = __TS__InitErrorClass
1016
- local ____G_2 = _G
1017
- ____class_0 = __TS__Class()
1018
- ____class_0.name = ""
1019
- function ____class_0.prototype.____constructor(self, message)
1020
- if message == nil then
1021
- message = ""
1022
- end
1023
- self.message = message
1024
- self.name = "Error"
1025
- self.stack = __TS__GetErrorStack(_G, self.constructor.new)
1026
- local metatable = getmetatable(self)
1027
- if not metatable.__errorToStringPatched then
1028
- metatable.__errorToStringPatched = true
1029
- metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
1030
- end
1031
- end
1032
- function ____class_0.prototype.__tostring(self)
1033
- local ____temp_1
1034
- if self.message ~= "" then
1035
- ____temp_1 = (self.name .. ": ") .. self.message
1036
- else
1037
- ____temp_1 = self.name
1038
- end
1039
- return ____temp_1
1040
- end
1041
- Error = ____TS__InitErrorClass_3(____G_2, ____class_0, "Error")
1042
- for ____, errorName in ipairs({
1043
- "RangeError",
1044
- "ReferenceError",
1045
- "SyntaxError",
1046
- "TypeError",
1047
- "URIError"
1048
- }) do
1049
- local ____G_7 = _G
1050
- local ____TS__InitErrorClass_6 = __TS__InitErrorClass
1051
- local ____G_5 = _G
1052
- local ____class_4 = __TS__Class()
1053
- ____class_4.name = ____class_4.name
1054
- __TS__ClassExtends(____class_4, Error)
1055
- function ____class_4.prototype.____constructor(self, ...)
1056
- Error.prototype.____constructor(self, ...)
1057
- self.name = errorName
1058
- end
1059
- ____G_7[errorName] = ____TS__InitErrorClass_6(____G_5, ____class_4, errorName)
1060
- end
1061
-
1062
- function __TS__Delete(target, key)
1062
+
1063
+ local function __TS__Delete(target, key)
1063
1064
  local descriptors = __TS__ObjectGetOwnPropertyDescriptors(target)
1064
1065
  local descriptor = descriptors[key]
1065
1066
  if descriptor then
@@ -1079,13 +1080,13 @@ function __TS__Delete(target, key)
1079
1080
  return true
1080
1081
  end
1081
1082
 
1082
- function __TS__StringAccess(self, index)
1083
+ local function __TS__StringAccess(self, index)
1083
1084
  if index >= 0 and index < #self then
1084
1085
  return string.sub(self, index + 1, index + 1)
1085
1086
  end
1086
1087
  end
1087
1088
 
1088
- function __TS__DelegatedYield(iterable)
1089
+ local function __TS__DelegatedYield(iterable)
1089
1090
  if type(iterable) == "string" then
1090
1091
  for index = 0, #iterable - 1 do
1091
1092
  coroutine.yield(__TS__StringAccess(iterable, index))
@@ -1120,222 +1121,230 @@ function __TS__DelegatedYield(iterable)
1120
1121
  end
1121
1122
  end
1122
1123
 
1123
- function __TS__GeneratorIterator(self)
1124
- return self
1125
- end
1126
- function __TS__GeneratorNext(self, ...)
1127
- local co = self.____coroutine
1128
- if coroutine.status(co) == "dead" then
1129
- return {done = true}
1130
- end
1131
- local status, value = coroutine.resume(co, ...)
1132
- if not status then
1133
- error(value, 0)
1124
+ local __TS__Generator
1125
+ do
1126
+ local function generatorIterator(self)
1127
+ return self
1134
1128
  end
1135
- return {
1136
- value = value,
1137
- done = coroutine.status(co) == "dead"
1138
- }
1139
- end
1140
- function __TS__Generator(fn)
1141
- return function(...)
1142
- local args = {...}
1143
- local argsLength = select("#", ...)
1129
+ local function generatorNext(self, ...)
1130
+ local co = self.____coroutine
1131
+ if coroutine.status(co) == "dead" then
1132
+ return {done = true}
1133
+ end
1134
+ local status, value = coroutine.resume(co, ...)
1135
+ if not status then
1136
+ error(value, 0)
1137
+ end
1144
1138
  return {
1145
- ____coroutine = coroutine.create(function() return fn((unpack or table.unpack)(args, 1, argsLength)) end),
1146
- [Symbol.iterator] = __TS__GeneratorIterator,
1147
- next = __TS__GeneratorNext
1139
+ value = value,
1140
+ done = coroutine.status(co) == "dead"
1148
1141
  }
1149
1142
  end
1143
+ function __TS__Generator(fn)
1144
+ return function(...)
1145
+ local args = {...}
1146
+ local argsLength = select("#", ...)
1147
+ return {
1148
+ ____coroutine = coroutine.create(function() return fn((unpack or table.unpack)(args, 1, argsLength)) end),
1149
+ [Symbol.iterator] = generatorIterator,
1150
+ next = generatorNext
1151
+ }
1152
+ end
1153
+ end
1150
1154
  end
1151
1155
 
1152
- function __TS__InstanceOfObject(value)
1156
+ local function __TS__InstanceOfObject(value)
1153
1157
  local valueType = type(value)
1154
1158
  return valueType == "table" or valueType == "function"
1155
1159
  end
1156
1160
 
1157
- function __TS__IteratorGeneratorStep(self)
1158
- local co = self.____coroutine
1159
- local status, value = coroutine.resume(co)
1160
- if not status then
1161
- error(value, 0)
1162
- end
1163
- if coroutine.status(co) == "dead" then
1164
- return
1165
- end
1166
- return true, value
1167
- end
1168
- function __TS__IteratorIteratorStep(self)
1169
- local result = self:next()
1170
- if result.done then
1171
- return
1172
- end
1173
- return true, result.value
1174
- end
1175
- function __TS__IteratorStringStep(self, index)
1176
- index = index + 1
1177
- if index > #self then
1178
- return
1161
+ local __TS__Iterator
1162
+ do
1163
+ local function iteratorGeneratorStep(self)
1164
+ local co = self.____coroutine
1165
+ local status, value = coroutine.resume(co)
1166
+ if not status then
1167
+ error(value, 0)
1168
+ end
1169
+ if coroutine.status(co) == "dead" then
1170
+ return
1171
+ end
1172
+ return true, value
1179
1173
  end
1180
- return index, string.sub(self, index, index)
1181
- end
1182
- function __TS__Iterator(iterable)
1183
- if type(iterable) == "string" then
1184
- return __TS__IteratorStringStep, iterable, 0
1185
- elseif iterable.____coroutine ~= nil then
1186
- return __TS__IteratorGeneratorStep, iterable
1187
- elseif iterable[Symbol.iterator] then
1188
- local iterator = iterable[Symbol.iterator](iterable)
1189
- return __TS__IteratorIteratorStep, iterator
1190
- else
1191
- return ipairs(iterable)
1174
+ local function iteratorIteratorStep(self)
1175
+ local result = self:next()
1176
+ if result.done then
1177
+ return
1178
+ end
1179
+ return true, result.value
1192
1180
  end
1193
- end
1194
-
1195
- Map = __TS__Class()
1196
- Map.name = "Map"
1197
- function Map.prototype.____constructor(self, entries)
1198
- self[Symbol.toStringTag] = "Map"
1199
- self.items = {}
1200
- self.size = 0
1201
- self.nextKey = {}
1202
- self.previousKey = {}
1203
- if entries == nil then
1204
- return
1181
+ local function iteratorStringStep(self, index)
1182
+ index = index + 1
1183
+ if index > #self then
1184
+ return
1185
+ end
1186
+ return index, string.sub(self, index, index)
1205
1187
  end
1206
- local iterable = entries
1207
- if iterable[Symbol.iterator] then
1208
- local iterator = iterable[Symbol.iterator](iterable)
1209
- while true do
1210
- local result = iterator:next()
1211
- if result.done then
1212
- break
1188
+ function __TS__Iterator(iterable)
1189
+ if type(iterable) == "string" then
1190
+ return iteratorStringStep, iterable, 0
1191
+ elseif iterable.____coroutine ~= nil then
1192
+ return iteratorGeneratorStep, iterable
1193
+ elseif iterable[Symbol.iterator] then
1194
+ local iterator = iterable[Symbol.iterator](iterable)
1195
+ return iteratorIteratorStep, iterator
1196
+ else
1197
+ return ipairs(iterable)
1198
+ end
1199
+ end
1200
+ end
1201
+
1202
+ local Map
1203
+ do
1204
+ Map = __TS__Class()
1205
+ Map.name = "Map"
1206
+ function Map.prototype.____constructor(self, entries)
1207
+ self[Symbol.toStringTag] = "Map"
1208
+ self.items = {}
1209
+ self.size = 0
1210
+ self.nextKey = {}
1211
+ self.previousKey = {}
1212
+ if entries == nil then
1213
+ return
1214
+ end
1215
+ local iterable = entries
1216
+ if iterable[Symbol.iterator] then
1217
+ local iterator = iterable[Symbol.iterator](iterable)
1218
+ while true do
1219
+ local result = iterator:next()
1220
+ if result.done then
1221
+ break
1222
+ end
1223
+ local value = result.value
1224
+ self:set(value[1], value[2])
1213
1225
  end
1214
- local value = result.value
1215
- self:set(value[1], value[2])
1216
- end
1217
- else
1218
- local array = entries
1219
- for ____, kvp in ipairs(array) do
1220
- self:set(kvp[1], kvp[2])
1221
- end
1222
- end
1223
- end
1224
- function Map.prototype.clear(self)
1225
- self.items = {}
1226
- self.nextKey = {}
1227
- self.previousKey = {}
1228
- self.firstKey = nil
1229
- self.lastKey = nil
1230
- self.size = 0
1231
- end
1232
- function Map.prototype.delete(self, key)
1233
- local contains = self:has(key)
1234
- if contains then
1235
- self.size = self.size - 1
1236
- local next = self.nextKey[key]
1237
- local previous = self.previousKey[key]
1238
- if next and previous then
1239
- self.nextKey[previous] = next
1240
- self.previousKey[next] = previous
1241
- elseif next then
1242
- self.firstKey = next
1243
- self.previousKey[next] = nil
1244
- elseif previous then
1245
- self.lastKey = previous
1246
- self.nextKey[previous] = nil
1247
1226
  else
1248
- self.firstKey = nil
1249
- self.lastKey = nil
1227
+ local array = entries
1228
+ for ____, kvp in ipairs(array) do
1229
+ self:set(kvp[1], kvp[2])
1230
+ end
1250
1231
  end
1251
- self.nextKey[key] = nil
1252
- self.previousKey[key] = nil
1253
1232
  end
1254
- self.items[key] = nil
1255
- return contains
1256
- end
1257
- function Map.prototype.forEach(self, callback)
1258
- for ____, key in __TS__Iterator(self:keys()) do
1259
- callback(_G, self.items[key], key, self)
1233
+ function Map.prototype.clear(self)
1234
+ self.items = {}
1235
+ self.nextKey = {}
1236
+ self.previousKey = {}
1237
+ self.firstKey = nil
1238
+ self.lastKey = nil
1239
+ self.size = 0
1240
+ end
1241
+ function Map.prototype.delete(self, key)
1242
+ local contains = self:has(key)
1243
+ if contains then
1244
+ self.size = self.size - 1
1245
+ local next = self.nextKey[key]
1246
+ local previous = self.previousKey[key]
1247
+ if next and previous then
1248
+ self.nextKey[previous] = next
1249
+ self.previousKey[next] = previous
1250
+ elseif next then
1251
+ self.firstKey = next
1252
+ self.previousKey[next] = nil
1253
+ elseif previous then
1254
+ self.lastKey = previous
1255
+ self.nextKey[previous] = nil
1256
+ else
1257
+ self.firstKey = nil
1258
+ self.lastKey = nil
1259
+ end
1260
+ self.nextKey[key] = nil
1261
+ self.previousKey[key] = nil
1262
+ end
1263
+ self.items[key] = nil
1264
+ return contains
1260
1265
  end
1261
- end
1262
- function Map.prototype.get(self, key)
1263
- return self.items[key]
1264
- end
1265
- function Map.prototype.has(self, key)
1266
- return self.nextKey[key] ~= nil or self.lastKey == key
1267
- end
1268
- function Map.prototype.set(self, key, value)
1269
- local isNewValue = not self:has(key)
1270
- if isNewValue then
1271
- self.size = self.size + 1
1266
+ function Map.prototype.forEach(self, callback)
1267
+ for ____, key in __TS__Iterator(self:keys()) do
1268
+ callback(nil, self.items[key], key, self)
1269
+ end
1272
1270
  end
1273
- self.items[key] = value
1274
- if self.firstKey == nil then
1275
- self.firstKey = key
1276
- self.lastKey = key
1277
- elseif isNewValue then
1278
- self.nextKey[self.lastKey] = key
1279
- self.previousKey[key] = self.lastKey
1280
- self.lastKey = key
1271
+ function Map.prototype.get(self, key)
1272
+ return self.items[key]
1281
1273
  end
1282
- return self
1283
- end
1284
- Map.prototype[Symbol.iterator] = function(self)
1285
- return self:entries()
1286
- end
1287
- function Map.prototype.entries(self)
1288
- local ____temp_0 = self
1289
- local items = ____temp_0.items
1290
- local nextKey = ____temp_0.nextKey
1291
- local key = self.firstKey
1292
- return {
1293
- [Symbol.iterator] = function(self)
1294
- return self
1295
- end,
1296
- next = function(self)
1297
- local result = {done = not key, value = {key, items[key]}}
1298
- key = nextKey[key]
1299
- return result
1300
- end
1301
- }
1302
- end
1303
- function Map.prototype.keys(self)
1304
- local nextKey = self.nextKey
1305
- local key = self.firstKey
1306
- return {
1307
- [Symbol.iterator] = function(self)
1308
- return self
1309
- end,
1310
- next = function(self)
1311
- local result = {done = not key, value = key}
1312
- key = nextKey[key]
1313
- return result
1274
+ function Map.prototype.has(self, key)
1275
+ return self.nextKey[key] ~= nil or self.lastKey == key
1276
+ end
1277
+ function Map.prototype.set(self, key, value)
1278
+ local isNewValue = not self:has(key)
1279
+ if isNewValue then
1280
+ self.size = self.size + 1
1314
1281
  end
1315
- }
1316
- end
1317
- function Map.prototype.values(self)
1318
- local ____temp_1 = self
1319
- local items = ____temp_1.items
1320
- local nextKey = ____temp_1.nextKey
1321
- local key = self.firstKey
1322
- return {
1323
- [Symbol.iterator] = function(self)
1324
- return self
1325
- end,
1326
- next = function(self)
1327
- local result = {done = not key, value = items[key]}
1328
- key = nextKey[key]
1329
- return result
1282
+ self.items[key] = value
1283
+ if self.firstKey == nil then
1284
+ self.firstKey = key
1285
+ self.lastKey = key
1286
+ elseif isNewValue then
1287
+ self.nextKey[self.lastKey] = key
1288
+ self.previousKey[key] = self.lastKey
1289
+ self.lastKey = key
1330
1290
  end
1331
- }
1291
+ return self
1292
+ end
1293
+ Map.prototype[Symbol.iterator] = function(self)
1294
+ return self:entries()
1295
+ end
1296
+ function Map.prototype.entries(self)
1297
+ local ____temp_0 = self
1298
+ local items = ____temp_0.items
1299
+ local nextKey = ____temp_0.nextKey
1300
+ local key = self.firstKey
1301
+ return {
1302
+ [Symbol.iterator] = function(self)
1303
+ return self
1304
+ end,
1305
+ next = function(self)
1306
+ local result = {done = not key, value = {key, items[key]}}
1307
+ key = nextKey[key]
1308
+ return result
1309
+ end
1310
+ }
1311
+ end
1312
+ function Map.prototype.keys(self)
1313
+ local nextKey = self.nextKey
1314
+ local key = self.firstKey
1315
+ return {
1316
+ [Symbol.iterator] = function(self)
1317
+ return self
1318
+ end,
1319
+ next = function(self)
1320
+ local result = {done = not key, value = key}
1321
+ key = nextKey[key]
1322
+ return result
1323
+ end
1324
+ }
1325
+ end
1326
+ function Map.prototype.values(self)
1327
+ local ____temp_1 = self
1328
+ local items = ____temp_1.items
1329
+ local nextKey = ____temp_1.nextKey
1330
+ local key = self.firstKey
1331
+ return {
1332
+ [Symbol.iterator] = function(self)
1333
+ return self
1334
+ end,
1335
+ next = function(self)
1336
+ local result = {done = not key, value = items[key]}
1337
+ key = nextKey[key]
1338
+ return result
1339
+ end
1340
+ }
1341
+ end
1342
+ Map[Symbol.species] = Map
1332
1343
  end
1333
- Map[Symbol.species] = Map
1334
- Map = Map
1335
1344
 
1336
- __TS__MathAtan2 = math.atan2 or math.atan
1345
+ local __TS__MathAtan2 = math.atan2 or math.atan
1337
1346
 
1338
- function __TS__MathSign(val)
1347
+ local function __TS__MathSign(val)
1339
1348
  if val > 0 then
1340
1349
  return 1
1341
1350
  elseif val < 0 then
@@ -1344,7 +1353,7 @@ function __TS__MathSign(val)
1344
1353
  return 0
1345
1354
  end
1346
1355
 
1347
- function __TS__Number(value)
1356
+ local function __TS__Number(value)
1348
1357
  local valueType = type(value)
1349
1358
  if valueType == "number" then
1350
1359
  return value
@@ -1371,57 +1380,60 @@ function __TS__Number(value)
1371
1380
  end
1372
1381
  end
1373
1382
 
1374
- function __TS__NumberIsFinite(value)
1383
+ local function __TS__NumberIsFinite(value)
1375
1384
  return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
1376
1385
  end
1377
1386
 
1378
- function __TS__NumberIsNaN(value)
1387
+ local function __TS__NumberIsNaN(value)
1379
1388
  return value ~= value
1380
1389
  end
1381
1390
 
1382
- ____radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
1383
- function __TS__NumberToString(self, radix)
1384
- if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
1385
- return tostring(self)
1386
- end
1387
- radix = math.floor(radix)
1388
- if radix < 2 or radix > 36 then
1389
- error("toString() radix argument must be between 2 and 36", 0)
1390
- end
1391
- local integer, fraction = math.modf(math.abs(self))
1392
- local result = ""
1393
- if radix == 8 then
1394
- result = string.format("%o", integer)
1395
- elseif radix == 16 then
1396
- result = string.format("%x", integer)
1397
- else
1398
- repeat
1399
- do
1400
- result = __TS__StringAccess(____radixChars, integer % radix) .. result
1401
- integer = math.floor(integer / radix)
1402
- end
1403
- until not (integer ~= 0)
1404
- end
1405
- if fraction ~= 0 then
1406
- result = result .. "."
1407
- local delta = 1e-16
1408
- repeat
1409
- do
1410
- fraction = fraction * radix
1411
- delta = delta * radix
1412
- local digit = math.floor(fraction)
1413
- result = result .. __TS__StringAccess(____radixChars, digit)
1414
- fraction = fraction - digit
1415
- end
1416
- until not (fraction >= delta)
1417
- end
1418
- if self < 0 then
1419
- result = "-" .. result
1391
+ local __TS__NumberToString
1392
+ do
1393
+ local radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
1394
+ function __TS__NumberToString(self, radix)
1395
+ if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
1396
+ return tostring(self)
1397
+ end
1398
+ radix = math.floor(radix)
1399
+ if radix < 2 or radix > 36 then
1400
+ error("toString() radix argument must be between 2 and 36", 0)
1401
+ end
1402
+ local integer, fraction = math.modf(math.abs(self))
1403
+ local result = ""
1404
+ if radix == 8 then
1405
+ result = string.format("%o", integer)
1406
+ elseif radix == 16 then
1407
+ result = string.format("%x", integer)
1408
+ else
1409
+ repeat
1410
+ do
1411
+ result = __TS__StringAccess(radixChars, integer % radix) .. result
1412
+ integer = math.floor(integer / radix)
1413
+ end
1414
+ until not (integer ~= 0)
1415
+ end
1416
+ if fraction ~= 0 then
1417
+ result = result .. "."
1418
+ local delta = 1e-16
1419
+ repeat
1420
+ do
1421
+ fraction = fraction * radix
1422
+ delta = delta * radix
1423
+ local digit = math.floor(fraction)
1424
+ result = result .. __TS__StringAccess(radixChars, digit)
1425
+ fraction = fraction - digit
1426
+ end
1427
+ until not (fraction >= delta)
1428
+ end
1429
+ if self < 0 then
1430
+ result = "-" .. result
1431
+ end
1432
+ return result
1420
1433
  end
1421
- return result
1422
1434
  end
1423
1435
 
1424
- function __TS__ObjectDefineProperty(target, key, desc)
1436
+ local function __TS__ObjectDefineProperty(target, key, desc)
1425
1437
  local ____temp_0
1426
1438
  if type(key) == "number" then
1427
1439
  ____temp_0 = key + 1
@@ -1481,7 +1493,7 @@ function __TS__ObjectDefineProperty(target, key, desc)
1481
1493
  return target
1482
1494
  end
1483
1495
 
1484
- function __TS__ObjectEntries(obj)
1496
+ local function __TS__ObjectEntries(obj)
1485
1497
  local result = {}
1486
1498
  for key in pairs(obj) do
1487
1499
  result[#result + 1] = {key, obj[key]}
@@ -1489,7 +1501,7 @@ function __TS__ObjectEntries(obj)
1489
1501
  return result
1490
1502
  end
1491
1503
 
1492
- function __TS__ObjectFromEntries(entries)
1504
+ local function __TS__ObjectFromEntries(entries)
1493
1505
  local obj = {}
1494
1506
  local iterable = entries
1495
1507
  if iterable[Symbol.iterator] then
@@ -1510,7 +1522,7 @@ function __TS__ObjectFromEntries(entries)
1510
1522
  return obj
1511
1523
  end
1512
1524
 
1513
- function __TS__ObjectKeys(obj)
1525
+ local function __TS__ObjectKeys(obj)
1514
1526
  local result = {}
1515
1527
  for key in pairs(obj) do
1516
1528
  result[#result + 1] = key
@@ -1518,7 +1530,7 @@ function __TS__ObjectKeys(obj)
1518
1530
  return result
1519
1531
  end
1520
1532
 
1521
- function __TS__ObjectRest(target, usedProperties)
1533
+ local function __TS__ObjectRest(target, usedProperties)
1522
1534
  local result = {}
1523
1535
  for property in pairs(target) do
1524
1536
  if not usedProperties[property] then
@@ -1528,7 +1540,7 @@ function __TS__ObjectRest(target, usedProperties)
1528
1540
  return result
1529
1541
  end
1530
1542
 
1531
- function __TS__ObjectValues(obj)
1543
+ local function __TS__ObjectValues(obj)
1532
1544
  local result = {}
1533
1545
  for key in pairs(obj) do
1534
1546
  result[#result + 1] = obj[key]
@@ -1536,7 +1548,7 @@ function __TS__ObjectValues(obj)
1536
1548
  return result
1537
1549
  end
1538
1550
 
1539
- function __TS__ParseFloat(numberString)
1551
+ local function __TS__ParseFloat(numberString)
1540
1552
  local infinityMatch = string.match(numberString, "^%s*(-?Infinity)")
1541
1553
  if infinityMatch then
1542
1554
  local ____temp_0
@@ -1551,7 +1563,7 @@ function __TS__ParseFloat(numberString)
1551
1563
  return number or 0 / 0
1552
1564
  end
1553
1565
 
1554
- function __TS__StringSubstr(self, from, length)
1566
+ local function __TS__StringSubstr(self, from, length)
1555
1567
  if from ~= from then
1556
1568
  from = 0
1557
1569
  end
@@ -1567,7 +1579,7 @@ function __TS__StringSubstr(self, from, length)
1567
1579
  return string.sub(self, from, length)
1568
1580
  end
1569
1581
 
1570
- function __TS__StringSubstring(self, start, ____end)
1582
+ local function __TS__StringSubstring(self, start, ____end)
1571
1583
  if ____end ~= ____end then
1572
1584
  ____end = 0
1573
1585
  end
@@ -1585,57 +1597,60 @@ function __TS__StringSubstring(self, start, ____end)
1585
1597
  return string.sub(self, start, ____end)
1586
1598
  end
1587
1599
 
1588
- __TS__parseInt_base_pattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
1589
- function __TS__ParseInt(numberString, base)
1590
- if base == nil then
1591
- base = 10
1592
- local hexMatch = string.match(numberString, "^%s*-?0[xX]")
1593
- if hexMatch then
1594
- base = 16
1595
- local ____string_match_result__0_0
1596
- if string.match(hexMatch, "-") then
1597
- ____string_match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
1598
- else
1599
- ____string_match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
1600
+ local __TS__ParseInt
1601
+ do
1602
+ local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
1603
+ function __TS__ParseInt(numberString, base)
1604
+ if base == nil then
1605
+ base = 10
1606
+ local hexMatch = string.match(numberString, "^%s*-?0[xX]")
1607
+ if hexMatch then
1608
+ base = 16
1609
+ local ____string_match_result__0_0
1610
+ if string.match(hexMatch, "-") then
1611
+ ____string_match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
1612
+ else
1613
+ ____string_match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
1614
+ end
1615
+ numberString = ____string_match_result__0_0
1600
1616
  end
1601
- numberString = ____string_match_result__0_0
1602
1617
  end
1603
- end
1604
- if base < 2 or base > 36 then
1605
- return 0 / 0
1606
- end
1607
- local ____temp_1
1608
- if base <= 10 then
1609
- ____temp_1 = __TS__StringSubstring(__TS__parseInt_base_pattern, 0, base)
1610
- else
1611
- ____temp_1 = __TS__StringSubstr(__TS__parseInt_base_pattern, 0, 10 + 2 * (base - 10))
1612
- end
1613
- local allowedDigits = ____temp_1
1614
- local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
1615
- local number = tonumber(
1616
- string.match(numberString, pattern),
1617
- base
1618
- )
1619
- if number == nil then
1620
- return 0 / 0
1621
- end
1622
- if number >= 0 then
1623
- return math.floor(number)
1624
- else
1625
- return math.ceil(number)
1618
+ if base < 2 or base > 36 then
1619
+ return 0 / 0
1620
+ end
1621
+ local ____temp_1
1622
+ if base <= 10 then
1623
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
1624
+ else
1625
+ ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
1626
+ end
1627
+ local allowedDigits = ____temp_1
1628
+ local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
1629
+ local number = tonumber(
1630
+ string.match(numberString, pattern),
1631
+ base
1632
+ )
1633
+ if number == nil then
1634
+ return 0 / 0
1635
+ end
1636
+ if number >= 0 then
1637
+ return math.floor(number)
1638
+ else
1639
+ return math.ceil(number)
1640
+ end
1626
1641
  end
1627
1642
  end
1628
1643
 
1629
- function __TS__PromiseAll(iterable)
1644
+ local function __TS__PromiseAll(iterable)
1630
1645
  local results = {}
1631
1646
  local toResolve = {}
1632
1647
  local numToResolve = 0
1633
1648
  local i = 0
1634
1649
  for ____, item in __TS__Iterator(iterable) do
1635
1650
  if __TS__InstanceOf(item, __TS__Promise) then
1636
- if item.state == __TS__PromiseState.Fulfilled then
1651
+ if item.state == 1 then
1637
1652
  results[i + 1] = item.value
1638
- elseif item.state == __TS__PromiseState.Rejected then
1653
+ elseif item.state == 2 then
1639
1654
  return __TS__Promise.reject(item.rejectionReason)
1640
1655
  else
1641
1656
  numToResolve = numToResolve + 1
@@ -1659,11 +1674,11 @@ function __TS__PromiseAll(iterable)
1659
1674
  results[index + 1] = data
1660
1675
  numToResolve = numToResolve - 1
1661
1676
  if numToResolve == 0 then
1662
- resolve(_G, results)
1677
+ resolve(nil, results)
1663
1678
  end
1664
1679
  end,
1665
1680
  function(____, reason)
1666
- reject(_G, reason)
1681
+ reject(nil, reason)
1667
1682
  end
1668
1683
  )
1669
1684
  end
@@ -1671,16 +1686,16 @@ function __TS__PromiseAll(iterable)
1671
1686
  )
1672
1687
  end
1673
1688
 
1674
- function __TS__PromiseAllSettled(iterable)
1689
+ local function __TS__PromiseAllSettled(iterable)
1675
1690
  local results = {}
1676
1691
  local toResolve = {}
1677
1692
  local numToResolve = 0
1678
1693
  local i = 0
1679
1694
  for ____, item in __TS__Iterator(iterable) do
1680
1695
  if __TS__InstanceOf(item, __TS__Promise) then
1681
- if item.state == __TS__PromiseState.Fulfilled then
1696
+ if item.state == 1 then
1682
1697
  results[i + 1] = {status = "fulfilled", value = item.value}
1683
- elseif item.state == __TS__PromiseState.Rejected then
1698
+ elseif item.state == 2 then
1684
1699
  results[i + 1] = {status = "rejected", reason = item.rejectionReason}
1685
1700
  else
1686
1701
  numToResolve = numToResolve + 1
@@ -1704,14 +1719,14 @@ function __TS__PromiseAllSettled(iterable)
1704
1719
  results[index + 1] = {status = "fulfilled", value = data}
1705
1720
  numToResolve = numToResolve - 1
1706
1721
  if numToResolve == 0 then
1707
- resolve(_G, results)
1722
+ resolve(nil, results)
1708
1723
  end
1709
1724
  end,
1710
1725
  function(____, reason)
1711
1726
  results[index + 1] = {status = "rejected", reason = reason}
1712
1727
  numToResolve = numToResolve - 1
1713
1728
  if numToResolve == 0 then
1714
- resolve(_G, results)
1729
+ resolve(nil, results)
1715
1730
  end
1716
1731
  end
1717
1732
  )
@@ -1720,14 +1735,14 @@ function __TS__PromiseAllSettled(iterable)
1720
1735
  )
1721
1736
  end
1722
1737
 
1723
- function __TS__PromiseAny(iterable)
1738
+ local function __TS__PromiseAny(iterable)
1724
1739
  local rejections = {}
1725
1740
  local pending = {}
1726
1741
  for ____, item in __TS__Iterator(iterable) do
1727
1742
  if __TS__InstanceOf(item, __TS__Promise) then
1728
- if item.state == __TS__PromiseState.Fulfilled then
1743
+ if item.state == 1 then
1729
1744
  return __TS__Promise.resolve(item.value)
1730
- elseif item.state == __TS__PromiseState.Rejected then
1745
+ elseif item.state == 2 then
1731
1746
  __TS__ArrayPush(rejections, item.rejectionReason)
1732
1747
  else
1733
1748
  __TS__ArrayPush(pending, item)
@@ -1747,13 +1762,13 @@ function __TS__PromiseAny(iterable)
1747
1762
  promise["then"](
1748
1763
  promise,
1749
1764
  function(____, data)
1750
- resolve(_G, data)
1765
+ resolve(nil, data)
1751
1766
  end,
1752
1767
  function(____, reason)
1753
1768
  __TS__ArrayPush(rejections, reason)
1754
1769
  numResolved = numResolved + 1
1755
1770
  if numResolved == #pending then
1756
- reject(_G, {name = "AggregateError", message = "All Promises rejected", errors = rejections})
1771
+ reject(nil, {name = "AggregateError", message = "All Promises rejected", errors = rejections})
1757
1772
  end
1758
1773
  end
1759
1774
  )
@@ -1762,13 +1777,13 @@ function __TS__PromiseAny(iterable)
1762
1777
  )
1763
1778
  end
1764
1779
 
1765
- function __TS__PromiseRace(iterable)
1780
+ local function __TS__PromiseRace(iterable)
1766
1781
  local pending = {}
1767
1782
  for ____, item in __TS__Iterator(iterable) do
1768
1783
  if __TS__InstanceOf(item, __TS__Promise) then
1769
- if item.state == __TS__PromiseState.Fulfilled then
1784
+ if item.state == 1 then
1770
1785
  return __TS__Promise.resolve(item.value)
1771
- elseif item.state == __TS__PromiseState.Rejected then
1786
+ elseif item.state == 2 then
1772
1787
  return __TS__Promise.reject(item.rejectionReason)
1773
1788
  else
1774
1789
  __TS__ArrayPush(pending, item)
@@ -1783,150 +1798,152 @@ function __TS__PromiseRace(iterable)
1783
1798
  for ____, promise in ipairs(pending) do
1784
1799
  promise["then"](
1785
1800
  promise,
1786
- function(____, value) return resolve(_G, value) end,
1787
- function(____, reason) return reject(_G, reason) end
1801
+ function(____, value) return resolve(nil, value) end,
1802
+ function(____, reason) return reject(nil, reason) end
1788
1803
  )
1789
1804
  end
1790
1805
  end
1791
1806
  )
1792
1807
  end
1793
1808
 
1794
- Set = __TS__Class()
1795
- Set.name = "Set"
1796
- function Set.prototype.____constructor(self, values)
1797
- self[Symbol.toStringTag] = "Set"
1798
- self.size = 0
1799
- self.nextKey = {}
1800
- self.previousKey = {}
1801
- if values == nil then
1802
- return
1803
- end
1804
- local iterable = values
1805
- if iterable[Symbol.iterator] then
1806
- local iterator = iterable[Symbol.iterator](iterable)
1807
- while true do
1808
- local result = iterator:next()
1809
- if result.done then
1810
- break
1809
+ local Set
1810
+ do
1811
+ Set = __TS__Class()
1812
+ Set.name = "Set"
1813
+ function Set.prototype.____constructor(self, values)
1814
+ self[Symbol.toStringTag] = "Set"
1815
+ self.size = 0
1816
+ self.nextKey = {}
1817
+ self.previousKey = {}
1818
+ if values == nil then
1819
+ return
1820
+ end
1821
+ local iterable = values
1822
+ if iterable[Symbol.iterator] then
1823
+ local iterator = iterable[Symbol.iterator](iterable)
1824
+ while true do
1825
+ local result = iterator:next()
1826
+ if result.done then
1827
+ break
1828
+ end
1829
+ self:add(result.value)
1811
1830
  end
1812
- self:add(result.value)
1813
- end
1814
- else
1815
- local array = values
1816
- for ____, value in ipairs(array) do
1817
- self:add(value)
1818
- end
1819
- end
1820
- end
1821
- function Set.prototype.add(self, value)
1822
- local isNewValue = not self:has(value)
1823
- if isNewValue then
1824
- self.size = self.size + 1
1825
- end
1826
- if self.firstKey == nil then
1827
- self.firstKey = value
1828
- self.lastKey = value
1829
- elseif isNewValue then
1830
- self.nextKey[self.lastKey] = value
1831
- self.previousKey[value] = self.lastKey
1832
- self.lastKey = value
1833
- end
1834
- return self
1835
- end
1836
- function Set.prototype.clear(self)
1837
- self.nextKey = {}
1838
- self.previousKey = {}
1839
- self.firstKey = nil
1840
- self.lastKey = nil
1841
- self.size = 0
1842
- end
1843
- function Set.prototype.delete(self, value)
1844
- local contains = self:has(value)
1845
- if contains then
1846
- self.size = self.size - 1
1847
- local next = self.nextKey[value]
1848
- local previous = self.previousKey[value]
1849
- if next and previous then
1850
- self.nextKey[previous] = next
1851
- self.previousKey[next] = previous
1852
- elseif next then
1853
- self.firstKey = next
1854
- self.previousKey[next] = nil
1855
- elseif previous then
1856
- self.lastKey = previous
1857
- self.nextKey[previous] = nil
1858
1831
  else
1859
- self.firstKey = nil
1860
- self.lastKey = nil
1832
+ local array = values
1833
+ for ____, value in ipairs(array) do
1834
+ self:add(value)
1835
+ end
1861
1836
  end
1862
- self.nextKey[value] = nil
1863
- self.previousKey[value] = nil
1864
- end
1865
- return contains
1866
- end
1867
- function Set.prototype.forEach(self, callback)
1868
- for ____, key in __TS__Iterator(self:keys()) do
1869
- callback(_G, key, key, self)
1870
1837
  end
1871
- end
1872
- function Set.prototype.has(self, value)
1873
- return self.nextKey[value] ~= nil or self.lastKey == value
1874
- end
1875
- Set.prototype[Symbol.iterator] = function(self)
1876
- return self:values()
1877
- end
1878
- function Set.prototype.entries(self)
1879
- local nextKey = self.nextKey
1880
- local key = self.firstKey
1881
- return {
1882
- [Symbol.iterator] = function(self)
1883
- return self
1884
- end,
1885
- next = function(self)
1886
- local result = {done = not key, value = {key, key}}
1887
- key = nextKey[key]
1888
- return result
1838
+ function Set.prototype.add(self, value)
1839
+ local isNewValue = not self:has(value)
1840
+ if isNewValue then
1841
+ self.size = self.size + 1
1889
1842
  end
1890
- }
1891
- end
1892
- function Set.prototype.keys(self)
1893
- local nextKey = self.nextKey
1894
- local key = self.firstKey
1895
- return {
1896
- [Symbol.iterator] = function(self)
1897
- return self
1898
- end,
1899
- next = function(self)
1900
- local result = {done = not key, value = key}
1901
- key = nextKey[key]
1902
- return result
1843
+ if self.firstKey == nil then
1844
+ self.firstKey = value
1845
+ self.lastKey = value
1846
+ elseif isNewValue then
1847
+ self.nextKey[self.lastKey] = value
1848
+ self.previousKey[value] = self.lastKey
1849
+ self.lastKey = value
1903
1850
  end
1904
- }
1905
- end
1906
- function Set.prototype.values(self)
1907
- local nextKey = self.nextKey
1908
- local key = self.firstKey
1909
- return {
1910
- [Symbol.iterator] = function(self)
1911
- return self
1912
- end,
1913
- next = function(self)
1914
- local result = {done = not key, value = key}
1915
- key = nextKey[key]
1916
- return result
1851
+ return self
1852
+ end
1853
+ function Set.prototype.clear(self)
1854
+ self.nextKey = {}
1855
+ self.previousKey = {}
1856
+ self.firstKey = nil
1857
+ self.lastKey = nil
1858
+ self.size = 0
1859
+ end
1860
+ function Set.prototype.delete(self, value)
1861
+ local contains = self:has(value)
1862
+ if contains then
1863
+ self.size = self.size - 1
1864
+ local next = self.nextKey[value]
1865
+ local previous = self.previousKey[value]
1866
+ if next and previous then
1867
+ self.nextKey[previous] = next
1868
+ self.previousKey[next] = previous
1869
+ elseif next then
1870
+ self.firstKey = next
1871
+ self.previousKey[next] = nil
1872
+ elseif previous then
1873
+ self.lastKey = previous
1874
+ self.nextKey[previous] = nil
1875
+ else
1876
+ self.firstKey = nil
1877
+ self.lastKey = nil
1878
+ end
1879
+ self.nextKey[value] = nil
1880
+ self.previousKey[value] = nil
1917
1881
  end
1918
- }
1882
+ return contains
1883
+ end
1884
+ function Set.prototype.forEach(self, callback)
1885
+ for ____, key in __TS__Iterator(self:keys()) do
1886
+ callback(nil, key, key, self)
1887
+ end
1888
+ end
1889
+ function Set.prototype.has(self, value)
1890
+ return self.nextKey[value] ~= nil or self.lastKey == value
1891
+ end
1892
+ Set.prototype[Symbol.iterator] = function(self)
1893
+ return self:values()
1894
+ end
1895
+ function Set.prototype.entries(self)
1896
+ local nextKey = self.nextKey
1897
+ local key = self.firstKey
1898
+ return {
1899
+ [Symbol.iterator] = function(self)
1900
+ return self
1901
+ end,
1902
+ next = function(self)
1903
+ local result = {done = not key, value = {key, key}}
1904
+ key = nextKey[key]
1905
+ return result
1906
+ end
1907
+ }
1908
+ end
1909
+ function Set.prototype.keys(self)
1910
+ local nextKey = self.nextKey
1911
+ local key = self.firstKey
1912
+ return {
1913
+ [Symbol.iterator] = function(self)
1914
+ return self
1915
+ end,
1916
+ next = function(self)
1917
+ local result = {done = not key, value = key}
1918
+ key = nextKey[key]
1919
+ return result
1920
+ end
1921
+ }
1922
+ end
1923
+ function Set.prototype.values(self)
1924
+ local nextKey = self.nextKey
1925
+ local key = self.firstKey
1926
+ return {
1927
+ [Symbol.iterator] = function(self)
1928
+ return self
1929
+ end,
1930
+ next = function(self)
1931
+ local result = {done = not key, value = key}
1932
+ key = nextKey[key]
1933
+ return result
1934
+ end
1935
+ }
1936
+ end
1937
+ Set[Symbol.species] = Set
1919
1938
  end
1920
- Set[Symbol.species] = Set
1921
- Set = Set
1922
1939
 
1923
- function __TS__SparseArrayNew(...)
1940
+ local function __TS__SparseArrayNew(...)
1924
1941
  local sparseArray = {...}
1925
1942
  sparseArray.sparseLength = select("#", ...)
1926
1943
  return sparseArray
1927
1944
  end
1928
1945
 
1929
- function __TS__SparseArrayPush(sparseArray, ...)
1946
+ local function __TS__SparseArrayPush(sparseArray, ...)
1930
1947
  local args = {...}
1931
1948
  local argsLen = select("#", ...)
1932
1949
  local listLen = sparseArray.sparseLength
@@ -1936,106 +1953,111 @@ function __TS__SparseArrayPush(sparseArray, ...)
1936
1953
  sparseArray.sparseLength = listLen + argsLen
1937
1954
  end
1938
1955
 
1939
- function __TS__SparseArraySpread(sparseArray)
1956
+ local function __TS__SparseArraySpread(sparseArray)
1940
1957
  local _unpack = unpack or table.unpack
1941
1958
  return _unpack(sparseArray, 1, sparseArray.sparseLength)
1942
1959
  end
1943
1960
 
1944
- WeakMap = __TS__Class()
1945
- WeakMap.name = "WeakMap"
1946
- function WeakMap.prototype.____constructor(self, entries)
1947
- self[Symbol.toStringTag] = "WeakMap"
1948
- self.items = {}
1949
- setmetatable(self.items, {__mode = "k"})
1950
- if entries == nil then
1951
- return
1952
- end
1953
- local iterable = entries
1954
- if iterable[Symbol.iterator] then
1955
- local iterator = iterable[Symbol.iterator](iterable)
1956
- while true do
1957
- local result = iterator:next()
1958
- if result.done then
1959
- break
1961
+ local WeakMap
1962
+ do
1963
+ WeakMap = __TS__Class()
1964
+ WeakMap.name = "WeakMap"
1965
+ function WeakMap.prototype.____constructor(self, entries)
1966
+ self[Symbol.toStringTag] = "WeakMap"
1967
+ self.items = {}
1968
+ setmetatable(self.items, {__mode = "k"})
1969
+ if entries == nil then
1970
+ return
1971
+ end
1972
+ local iterable = entries
1973
+ if iterable[Symbol.iterator] then
1974
+ local iterator = iterable[Symbol.iterator](iterable)
1975
+ while true do
1976
+ local result = iterator:next()
1977
+ if result.done then
1978
+ break
1979
+ end
1980
+ local value = result.value
1981
+ self.items[value[1]] = value[2]
1982
+ end
1983
+ else
1984
+ for ____, kvp in ipairs(entries) do
1985
+ self.items[kvp[1]] = kvp[2]
1960
1986
  end
1961
- local value = result.value
1962
- self.items[value[1]] = value[2]
1963
- end
1964
- else
1965
- for ____, kvp in ipairs(entries) do
1966
- self.items[kvp[1]] = kvp[2]
1967
1987
  end
1968
1988
  end
1969
- end
1970
- function WeakMap.prototype.delete(self, key)
1971
- local contains = self:has(key)
1972
- self.items[key] = nil
1973
- return contains
1974
- end
1975
- function WeakMap.prototype.get(self, key)
1976
- return self.items[key]
1977
- end
1978
- function WeakMap.prototype.has(self, key)
1979
- return self.items[key] ~= nil
1980
- end
1981
- function WeakMap.prototype.set(self, key, value)
1982
- self.items[key] = value
1983
- return self
1984
- end
1985
- WeakMap[Symbol.species] = WeakMap
1986
- WeakMap = WeakMap
1987
-
1988
- WeakSet = __TS__Class()
1989
- WeakSet.name = "WeakSet"
1990
- function WeakSet.prototype.____constructor(self, values)
1991
- self[Symbol.toStringTag] = "WeakSet"
1992
- self.items = {}
1993
- setmetatable(self.items, {__mode = "k"})
1994
- if values == nil then
1995
- return
1989
+ function WeakMap.prototype.delete(self, key)
1990
+ local contains = self:has(key)
1991
+ self.items[key] = nil
1992
+ return contains
1996
1993
  end
1997
- local iterable = values
1998
- if iterable[Symbol.iterator] then
1999
- local iterator = iterable[Symbol.iterator](iterable)
2000
- while true do
2001
- local result = iterator:next()
2002
- if result.done then
2003
- break
1994
+ function WeakMap.prototype.get(self, key)
1995
+ return self.items[key]
1996
+ end
1997
+ function WeakMap.prototype.has(self, key)
1998
+ return self.items[key] ~= nil
1999
+ end
2000
+ function WeakMap.prototype.set(self, key, value)
2001
+ self.items[key] = value
2002
+ return self
2003
+ end
2004
+ WeakMap[Symbol.species] = WeakMap
2005
+ end
2006
+
2007
+ local WeakSet
2008
+ do
2009
+ WeakSet = __TS__Class()
2010
+ WeakSet.name = "WeakSet"
2011
+ function WeakSet.prototype.____constructor(self, values)
2012
+ self[Symbol.toStringTag] = "WeakSet"
2013
+ self.items = {}
2014
+ setmetatable(self.items, {__mode = "k"})
2015
+ if values == nil then
2016
+ return
2017
+ end
2018
+ local iterable = values
2019
+ if iterable[Symbol.iterator] then
2020
+ local iterator = iterable[Symbol.iterator](iterable)
2021
+ while true do
2022
+ local result = iterator:next()
2023
+ if result.done then
2024
+ break
2025
+ end
2026
+ self.items[result.value] = true
2027
+ end
2028
+ else
2029
+ for ____, value in ipairs(values) do
2030
+ self.items[value] = true
2004
2031
  end
2005
- self.items[result.value] = true
2006
- end
2007
- else
2008
- for ____, value in ipairs(values) do
2009
- self.items[value] = true
2010
2032
  end
2011
2033
  end
2034
+ function WeakSet.prototype.add(self, value)
2035
+ self.items[value] = true
2036
+ return self
2037
+ end
2038
+ function WeakSet.prototype.delete(self, value)
2039
+ local contains = self:has(value)
2040
+ self.items[value] = nil
2041
+ return contains
2042
+ end
2043
+ function WeakSet.prototype.has(self, value)
2044
+ return self.items[value] == true
2045
+ end
2046
+ WeakSet[Symbol.species] = WeakSet
2012
2047
  end
2013
- function WeakSet.prototype.add(self, value)
2014
- self.items[value] = true
2015
- return self
2016
- end
2017
- function WeakSet.prototype.delete(self, value)
2018
- local contains = self:has(value)
2019
- self.items[value] = nil
2020
- return contains
2021
- end
2022
- function WeakSet.prototype.has(self, value)
2023
- return self.items[value] == true
2024
- end
2025
- WeakSet[Symbol.species] = WeakSet
2026
- WeakSet = WeakSet
2027
2048
 
2028
- function __TS__SourceMapTraceBack(fileName, sourceMap)
2049
+ local function __TS__SourceMapTraceBack(fileName, sourceMap)
2029
2050
  _G.__TS__sourcemap = _G.__TS__sourcemap or ({})
2030
2051
  _G.__TS__sourcemap[fileName] = sourceMap
2031
2052
  if _G.__TS__originalTraceback == nil then
2032
- _G.__TS__originalTraceback = debug.traceback
2053
+ local originalTraceback = debug.traceback
2054
+ _G.__TS__originalTraceback = originalTraceback
2033
2055
  debug.traceback = function(thread, message, level)
2034
2056
  local trace
2035
2057
  if thread == nil and message == nil and level == nil then
2036
- trace = _G.__TS__originalTraceback()
2058
+ trace = originalTraceback()
2037
2059
  else
2038
- trace = _G.__TS__originalTraceback(thread, message, level)
2060
+ trace = originalTraceback(thread, message, level)
2039
2061
  end
2040
2062
  if type(trace) ~= "string" then
2041
2063
  return trace
@@ -2054,19 +2076,19 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
2054
2076
  local result = string.gsub(
2055
2077
  trace,
2056
2078
  "(%S+)%.lua:(%d+)",
2057
- function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
2079
+ function(file, line) return replacer(nil, file .. ".lua", file .. ".ts", line) end
2058
2080
  )
2059
2081
  result = string.gsub(
2060
2082
  result,
2061
2083
  "(%[string \"[^\"]+\"%]):(%d+)",
2062
- function(file, line) return replacer(_G, file, "unknown", line) end
2084
+ function(file, line) return replacer(nil, file, "unknown", line) end
2063
2085
  )
2064
2086
  return result
2065
2087
  end
2066
2088
  end
2067
2089
  end
2068
2090
 
2069
- function __TS__Spread(iterable)
2091
+ local function __TS__Spread(iterable)
2070
2092
  local arr = {}
2071
2093
  if type(iterable) == "string" then
2072
2094
  do
@@ -2084,7 +2106,7 @@ function __TS__Spread(iterable)
2084
2106
  return __TS__Unpack(arr)
2085
2107
  end
2086
2108
 
2087
- function __TS__StringCharAt(self, pos)
2109
+ local function __TS__StringCharAt(self, pos)
2088
2110
  if pos ~= pos then
2089
2111
  pos = 0
2090
2112
  end
@@ -2094,7 +2116,7 @@ function __TS__StringCharAt(self, pos)
2094
2116
  return string.sub(self, pos + 1, pos + 1)
2095
2117
  end
2096
2118
 
2097
- function __TS__StringCharCodeAt(self, index)
2119
+ local function __TS__StringCharCodeAt(self, index)
2098
2120
  if index ~= index then
2099
2121
  index = 0
2100
2122
  end
@@ -2104,7 +2126,7 @@ function __TS__StringCharCodeAt(self, index)
2104
2126
  return string.byte(self, index + 1) or 0 / 0
2105
2127
  end
2106
2128
 
2107
- function __TS__StringConcat(str1, ...)
2129
+ local function __TS__StringConcat(str1, ...)
2108
2130
  local args = {...}
2109
2131
  local out = str1
2110
2132
  for ____, arg in ipairs(args) do
@@ -2113,14 +2135,14 @@ function __TS__StringConcat(str1, ...)
2113
2135
  return out
2114
2136
  end
2115
2137
 
2116
- function __TS__StringEndsWith(self, searchString, endPosition)
2138
+ local function __TS__StringEndsWith(self, searchString, endPosition)
2117
2139
  if endPosition == nil or endPosition > #self then
2118
2140
  endPosition = #self
2119
2141
  end
2120
2142
  return string.sub(self, endPosition - #searchString + 1, endPosition) == searchString
2121
2143
  end
2122
2144
 
2123
- function __TS__StringIncludes(self, searchString, position)
2145
+ local function __TS__StringIncludes(self, searchString, position)
2124
2146
  if not position then
2125
2147
  position = 1
2126
2148
  else
@@ -2130,7 +2152,7 @@ function __TS__StringIncludes(self, searchString, position)
2130
2152
  return index ~= nil
2131
2153
  end
2132
2154
 
2133
- function __TS__StringPadEnd(self, maxLength, fillString)
2155
+ local function __TS__StringPadEnd(self, maxLength, fillString)
2134
2156
  if fillString == nil then
2135
2157
  fillString = " "
2136
2158
  end
@@ -2157,7 +2179,7 @@ function __TS__StringPadEnd(self, maxLength, fillString)
2157
2179
  )
2158
2180
  end
2159
2181
 
2160
- function __TS__StringPadStart(self, maxLength, fillString)
2182
+ local function __TS__StringPadStart(self, maxLength, fillString)
2161
2183
  if fillString == nil then
2162
2184
  fillString = " "
2163
2185
  end
@@ -2184,7 +2206,7 @@ function __TS__StringPadStart(self, maxLength, fillString)
2184
2206
  ) .. self
2185
2207
  end
2186
2208
 
2187
- function __TS__StringReplace(source, searchValue, replaceValue)
2209
+ local function __TS__StringReplace(source, searchValue, replaceValue)
2188
2210
  local startPos, endPos = string.find(source, searchValue, nil, true)
2189
2211
  if not startPos then
2190
2212
  return source
@@ -2195,14 +2217,14 @@ function __TS__StringReplace(source, searchValue, replaceValue)
2195
2217
  if type(replaceValue) == "string" then
2196
2218
  ____temp_0 = replaceValue
2197
2219
  else
2198
- ____temp_0 = replaceValue(_G, searchValue, startPos - 1, source)
2220
+ ____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
2199
2221
  end
2200
2222
  local replacement = ____temp_0
2201
2223
  local after = sub(source, endPos + 1)
2202
2224
  return (before .. replacement) .. after
2203
2225
  end
2204
2226
 
2205
- function __TS__StringReplaceAll(source, searchValue, replaceValue)
2227
+ local function __TS__StringReplaceAll(source, searchValue, replaceValue)
2206
2228
  local replacer
2207
2229
  if type(replaceValue) == "string" then
2208
2230
  replacer = function() return replaceValue end
@@ -2213,11 +2235,11 @@ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2213
2235
  local partsIndex = 1
2214
2236
  local sub = string.sub
2215
2237
  if #searchValue == 0 then
2216
- parts[1] = replacer(_G, "", 0, source)
2238
+ parts[1] = replacer(nil, "", 0, source)
2217
2239
  partsIndex = 2
2218
2240
  for i = 1, #source do
2219
2241
  parts[partsIndex] = sub(source, i, i)
2220
- parts[partsIndex + 1] = replacer(_G, "", i, source)
2242
+ parts[partsIndex + 1] = replacer(nil, "", i, source)
2221
2243
  partsIndex = partsIndex + 2
2222
2244
  end
2223
2245
  else
@@ -2229,7 +2251,7 @@ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2229
2251
  break
2230
2252
  end
2231
2253
  parts[partsIndex] = sub(source, currentPos, startPos - 1)
2232
- parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
2254
+ parts[partsIndex + 1] = replacer(nil, searchValue, startPos - 1, source)
2233
2255
  partsIndex = partsIndex + 2
2234
2256
  currentPos = endPos + 1
2235
2257
  end
@@ -2238,7 +2260,7 @@ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2238
2260
  return table.concat(parts)
2239
2261
  end
2240
2262
 
2241
- function __TS__StringSlice(self, start, ____end)
2263
+ local function __TS__StringSlice(self, start, ____end)
2242
2264
  if start == nil or start ~= start then
2243
2265
  start = 0
2244
2266
  end
@@ -2254,7 +2276,7 @@ function __TS__StringSlice(self, start, ____end)
2254
2276
  return string.sub(self, start, ____end)
2255
2277
  end
2256
2278
 
2257
- function __TS__StringSplit(source, separator, limit)
2279
+ local function __TS__StringSplit(source, separator, limit)
2258
2280
  if limit == nil then
2259
2281
  limit = 4294967295
2260
2282
  end
@@ -2291,44 +2313,47 @@ function __TS__StringSplit(source, separator, limit)
2291
2313
  return out
2292
2314
  end
2293
2315
 
2294
- function __TS__StringStartsWith(self, searchString, position)
2316
+ local function __TS__StringStartsWith(self, searchString, position)
2295
2317
  if position == nil or position < 0 then
2296
2318
  position = 0
2297
2319
  end
2298
2320
  return string.sub(self, position + 1, #searchString + position) == searchString
2299
2321
  end
2300
2322
 
2301
- function __TS__StringTrim(self)
2323
+ local function __TS__StringTrim(self)
2302
2324
  local result = string.gsub(self, "^[%s ]*(.-)[%s ]*$", "%1")
2303
2325
  return result
2304
2326
  end
2305
2327
 
2306
- function __TS__StringTrimEnd(self)
2328
+ local function __TS__StringTrimEnd(self)
2307
2329
  local result = string.gsub(self, "[%s ]*$", "")
2308
2330
  return result
2309
2331
  end
2310
2332
 
2311
- function __TS__StringTrimStart(self)
2333
+ local function __TS__StringTrimStart(self)
2312
2334
  local result = string.gsub(self, "^[%s ]*", "")
2313
2335
  return result
2314
2336
  end
2315
2337
 
2316
- ____symbolRegistry = {}
2317
- function __TS__SymbolRegistryFor(key)
2318
- if not ____symbolRegistry[key] then
2319
- ____symbolRegistry[key] = __TS__Symbol(key)
2338
+ local __TS__SymbolRegistryFor, __TS__SymbolRegistryKeyFor
2339
+ do
2340
+ local symbolRegistry = {}
2341
+ function __TS__SymbolRegistryFor(key)
2342
+ if not symbolRegistry[key] then
2343
+ symbolRegistry[key] = __TS__Symbol(key)
2344
+ end
2345
+ return symbolRegistry[key]
2320
2346
  end
2321
- return ____symbolRegistry[key]
2322
- end
2323
- function __TS__SymbolRegistryKeyFor(sym)
2324
- for key in pairs(____symbolRegistry) do
2325
- if ____symbolRegistry[key] == sym then
2326
- return key
2347
+ function __TS__SymbolRegistryKeyFor(sym)
2348
+ for key in pairs(symbolRegistry) do
2349
+ if symbolRegistry[key] == sym then
2350
+ return key
2351
+ end
2327
2352
  end
2328
2353
  end
2329
2354
  end
2330
2355
 
2331
- function __TS__TypeOf(value)
2356
+ local function __TS__TypeOf(value)
2332
2357
  local luaType = type(value)
2333
2358
  if luaType == "table" then
2334
2359
  return "object"
@@ -2339,3 +2364,108 @@ function __TS__TypeOf(value)
2339
2364
  end
2340
2365
  end
2341
2366
 
2367
+ return {
2368
+ __TS__ArrayConcat = __TS__ArrayConcat,
2369
+ __TS__ArrayEntries = __TS__ArrayEntries,
2370
+ __TS__ArrayEvery = __TS__ArrayEvery,
2371
+ __TS__ArrayFilter = __TS__ArrayFilter,
2372
+ __TS__ArrayForEach = __TS__ArrayForEach,
2373
+ __TS__ArrayFind = __TS__ArrayFind,
2374
+ __TS__ArrayFindIndex = __TS__ArrayFindIndex,
2375
+ __TS__ArrayIncludes = __TS__ArrayIncludes,
2376
+ __TS__ArrayIndexOf = __TS__ArrayIndexOf,
2377
+ __TS__ArrayIsArray = __TS__ArrayIsArray,
2378
+ __TS__ArrayJoin = __TS__ArrayJoin,
2379
+ __TS__ArrayMap = __TS__ArrayMap,
2380
+ __TS__ArrayPush = __TS__ArrayPush,
2381
+ __TS__ArrayReduce = __TS__ArrayReduce,
2382
+ __TS__ArrayReduceRight = __TS__ArrayReduceRight,
2383
+ __TS__ArrayReverse = __TS__ArrayReverse,
2384
+ __TS__ArrayShift = __TS__ArrayShift,
2385
+ __TS__ArrayUnshift = __TS__ArrayUnshift,
2386
+ __TS__ArraySort = __TS__ArraySort,
2387
+ __TS__ArraySlice = __TS__ArraySlice,
2388
+ __TS__ArraySome = __TS__ArraySome,
2389
+ __TS__ArraySplice = __TS__ArraySplice,
2390
+ __TS__ArrayToObject = __TS__ArrayToObject,
2391
+ __TS__ArrayFlat = __TS__ArrayFlat,
2392
+ __TS__ArrayFlatMap = __TS__ArrayFlatMap,
2393
+ __TS__ArraySetLength = __TS__ArraySetLength,
2394
+ __TS__AsyncAwaiter = __TS__AsyncAwaiter,
2395
+ __TS__Await = __TS__Await,
2396
+ __TS__Class = __TS__Class,
2397
+ __TS__ClassExtends = __TS__ClassExtends,
2398
+ __TS__CloneDescriptor = __TS__CloneDescriptor,
2399
+ __TS__Decorate = __TS__Decorate,
2400
+ __TS__DecorateParam = __TS__DecorateParam,
2401
+ __TS__Delete = __TS__Delete,
2402
+ __TS__DelegatedYield = __TS__DelegatedYield,
2403
+ Error = Error,
2404
+ RangeError = RangeError,
2405
+ ReferenceError = ReferenceError,
2406
+ SyntaxError = SyntaxError,
2407
+ TypeError = TypeError,
2408
+ URIError = URIError,
2409
+ __TS__FunctionBind = __TS__FunctionBind,
2410
+ __TS__Generator = __TS__Generator,
2411
+ __TS__InstanceOf = __TS__InstanceOf,
2412
+ __TS__InstanceOfObject = __TS__InstanceOfObject,
2413
+ __TS__Iterator = __TS__Iterator,
2414
+ Map = Map,
2415
+ __TS__MathAtan2 = __TS__MathAtan2,
2416
+ __TS__MathSign = __TS__MathSign,
2417
+ __TS__New = __TS__New,
2418
+ __TS__Number = __TS__Number,
2419
+ __TS__NumberIsFinite = __TS__NumberIsFinite,
2420
+ __TS__NumberIsNaN = __TS__NumberIsNaN,
2421
+ __TS__NumberToString = __TS__NumberToString,
2422
+ __TS__ObjectAssign = __TS__ObjectAssign,
2423
+ __TS__ObjectDefineProperty = __TS__ObjectDefineProperty,
2424
+ __TS__ObjectEntries = __TS__ObjectEntries,
2425
+ __TS__ObjectFromEntries = __TS__ObjectFromEntries,
2426
+ __TS__ObjectGetOwnPropertyDescriptor = __TS__ObjectGetOwnPropertyDescriptor,
2427
+ __TS__ObjectGetOwnPropertyDescriptors = __TS__ObjectGetOwnPropertyDescriptors,
2428
+ __TS__ObjectKeys = __TS__ObjectKeys,
2429
+ __TS__ObjectRest = __TS__ObjectRest,
2430
+ __TS__ObjectValues = __TS__ObjectValues,
2431
+ __TS__ParseFloat = __TS__ParseFloat,
2432
+ __TS__ParseInt = __TS__ParseInt,
2433
+ __TS__Promise = __TS__Promise,
2434
+ __TS__PromiseAll = __TS__PromiseAll,
2435
+ __TS__PromiseAllSettled = __TS__PromiseAllSettled,
2436
+ __TS__PromiseAny = __TS__PromiseAny,
2437
+ __TS__PromiseRace = __TS__PromiseRace,
2438
+ Set = Set,
2439
+ __TS__SetDescriptor = __TS__SetDescriptor,
2440
+ __TS__SparseArrayNew = __TS__SparseArrayNew,
2441
+ __TS__SparseArrayPush = __TS__SparseArrayPush,
2442
+ __TS__SparseArraySpread = __TS__SparseArraySpread,
2443
+ WeakMap = WeakMap,
2444
+ WeakSet = WeakSet,
2445
+ __TS__SourceMapTraceBack = __TS__SourceMapTraceBack,
2446
+ __TS__Spread = __TS__Spread,
2447
+ __TS__StringAccess = __TS__StringAccess,
2448
+ __TS__StringCharAt = __TS__StringCharAt,
2449
+ __TS__StringCharCodeAt = __TS__StringCharCodeAt,
2450
+ __TS__StringConcat = __TS__StringConcat,
2451
+ __TS__StringEndsWith = __TS__StringEndsWith,
2452
+ __TS__StringIncludes = __TS__StringIncludes,
2453
+ __TS__StringPadEnd = __TS__StringPadEnd,
2454
+ __TS__StringPadStart = __TS__StringPadStart,
2455
+ __TS__StringReplace = __TS__StringReplace,
2456
+ __TS__StringReplaceAll = __TS__StringReplaceAll,
2457
+ __TS__StringSlice = __TS__StringSlice,
2458
+ __TS__StringSplit = __TS__StringSplit,
2459
+ __TS__StringStartsWith = __TS__StringStartsWith,
2460
+ __TS__StringSubstr = __TS__StringSubstr,
2461
+ __TS__StringSubstring = __TS__StringSubstring,
2462
+ __TS__StringTrim = __TS__StringTrim,
2463
+ __TS__StringTrimEnd = __TS__StringTrimEnd,
2464
+ __TS__StringTrimStart = __TS__StringTrimStart,
2465
+ __TS__Symbol = __TS__Symbol,
2466
+ Symbol = Symbol,
2467
+ __TS__SymbolRegistryFor = __TS__SymbolRegistryFor,
2468
+ __TS__SymbolRegistryKeyFor = __TS__SymbolRegistryKeyFor,
2469
+ __TS__TypeOf = __TS__TypeOf,
2470
+ __TS__Unpack = __TS__Unpack
2471
+ }