typescript-to-lua 1.3.2 → 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 (135) 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/members/constructor.js +1 -3
  121. package/dist/transformation/visitors/class/members/fields.js +12 -8
  122. package/dist/transformation/visitors/class/new.d.ts +1 -2
  123. package/dist/transformation/visitors/class/new.js +1 -40
  124. package/dist/transformation/visitors/conditional.js +15 -14
  125. package/dist/transformation/visitors/identifier.js +5 -0
  126. package/dist/transformation/visitors/literal.js +22 -0
  127. package/dist/transformation/visitors/modules/import.js +4 -14
  128. package/dist/transpilation/bundle.js +1 -1
  129. package/dist/transpilation/index.js +5 -1
  130. package/dist/transpilation/plugins.d.ts +11 -0
  131. package/dist/transpilation/resolve.js +2 -2
  132. package/dist/transpilation/transpile.js +13 -0
  133. package/dist/transpilation/transpiler.js +6 -2
  134. package/package.json +12 -11
  135. package/CHANGELOG.md +0 -703
@@ -1,3 +1,3 @@
1
- function __TS__NumberIsNaN(value)
1
+ local function __TS__NumberIsNaN(value)
2
2
  return value ~= value
3
3
  end
@@ -1,41 +1,44 @@
1
- ____radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
2
- function __TS__NumberToString(self, radix)
3
- if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
4
- return tostring(self)
1
+ local __TS__NumberToString
2
+ do
3
+ local radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
4
+ function __TS__NumberToString(self, radix)
5
+ if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
6
+ return tostring(self)
7
+ end
8
+ radix = math.floor(radix)
9
+ if radix < 2 or radix > 36 then
10
+ error("toString() radix argument must be between 2 and 36", 0)
11
+ end
12
+ local integer, fraction = math.modf(math.abs(self))
13
+ local result = ""
14
+ if radix == 8 then
15
+ result = string.format("%o", integer)
16
+ elseif radix == 16 then
17
+ result = string.format("%x", integer)
18
+ else
19
+ repeat
20
+ do
21
+ result = __TS__StringAccess(radixChars, integer % radix) .. result
22
+ integer = math.floor(integer / radix)
23
+ end
24
+ until not (integer ~= 0)
25
+ end
26
+ if fraction ~= 0 then
27
+ result = result .. "."
28
+ local delta = 1e-16
29
+ repeat
30
+ do
31
+ fraction = fraction * radix
32
+ delta = delta * radix
33
+ local digit = math.floor(fraction)
34
+ result = result .. __TS__StringAccess(radixChars, digit)
35
+ fraction = fraction - digit
36
+ end
37
+ until not (fraction >= delta)
38
+ end
39
+ if self < 0 then
40
+ result = "-" .. result
41
+ end
42
+ return result
5
43
  end
6
- radix = math.floor(radix)
7
- if radix < 2 or radix > 36 then
8
- error("toString() radix argument must be between 2 and 36", 0)
9
- end
10
- local integer, fraction = math.modf(math.abs(self))
11
- local result = ""
12
- if radix == 8 then
13
- result = string.format("%o", integer)
14
- elseif radix == 16 then
15
- result = string.format("%x", integer)
16
- else
17
- repeat
18
- do
19
- result = __TS__StringAccess(____radixChars, integer % radix) .. result
20
- integer = math.floor(integer / radix)
21
- end
22
- until not (integer ~= 0)
23
- end
24
- if fraction ~= 0 then
25
- result = result .. "."
26
- local delta = 1e-16
27
- repeat
28
- do
29
- fraction = fraction * radix
30
- delta = delta * radix
31
- local digit = math.floor(fraction)
32
- result = result .. __TS__StringAccess(____radixChars, digit)
33
- fraction = fraction - digit
34
- end
35
- until not (fraction >= delta)
36
- end
37
- if self < 0 then
38
- result = "-" .. result
39
- end
40
- return result
41
44
  end
@@ -1,4 +1,4 @@
1
- function __TS__ObjectAssign(to, ...)
1
+ local function __TS__ObjectAssign(to, ...)
2
2
  local sources = {...}
3
3
  if to == nil then
4
4
  return to
@@ -1,4 +1,4 @@
1
- function __TS__ObjectDefineProperty(target, key, desc)
1
+ local function __TS__ObjectDefineProperty(target, key, desc)
2
2
  local ____temp_0
3
3
  if type(key) == "number" then
4
4
  ____temp_0 = key + 1
@@ -1,4 +1,4 @@
1
- function __TS__ObjectEntries(obj)
1
+ local function __TS__ObjectEntries(obj)
2
2
  local result = {}
3
3
  for key in pairs(obj) do
4
4
  result[#result + 1] = {key, obj[key]}
@@ -1,4 +1,4 @@
1
- function __TS__ObjectFromEntries(entries)
1
+ local function __TS__ObjectFromEntries(entries)
2
2
  local obj = {}
3
3
  local iterable = entries
4
4
  if iterable[Symbol.iterator] then
@@ -1,4 +1,4 @@
1
- function __TS__ObjectGetOwnPropertyDescriptor(object, key)
1
+ local function __TS__ObjectGetOwnPropertyDescriptor(object, key)
2
2
  local metatable = getmetatable(object)
3
3
  if not metatable then
4
4
  return
@@ -1,4 +1,4 @@
1
- function __TS__ObjectGetOwnPropertyDescriptors(object)
1
+ local function __TS__ObjectGetOwnPropertyDescriptors(object)
2
2
  local metatable = getmetatable(object)
3
3
  if not metatable then
4
4
  return {}
@@ -1,4 +1,4 @@
1
- function __TS__ObjectKeys(obj)
1
+ local function __TS__ObjectKeys(obj)
2
2
  local result = {}
3
3
  for key in pairs(obj) do
4
4
  result[#result + 1] = key
@@ -1,4 +1,4 @@
1
- function __TS__ObjectRest(target, usedProperties)
1
+ local function __TS__ObjectRest(target, usedProperties)
2
2
  local result = {}
3
3
  for property in pairs(target) do
4
4
  if not usedProperties[property] then
@@ -1,4 +1,4 @@
1
- function __TS__ObjectValues(obj)
1
+ local function __TS__ObjectValues(obj)
2
2
  local result = {}
3
3
  for key in pairs(obj) do
4
4
  result[#result + 1] = obj[key]
@@ -1,4 +1,4 @@
1
- function __TS__ParseFloat(numberString)
1
+ local function __TS__ParseFloat(numberString)
2
2
  local infinityMatch = string.match(numberString, "^%s*(-?Infinity)")
3
3
  if infinityMatch then
4
4
  local ____temp_0
@@ -1,40 +1,43 @@
1
- __TS__parseInt_base_pattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
2
- function __TS__ParseInt(numberString, base)
3
- if base == nil then
4
- base = 10
5
- local hexMatch = string.match(numberString, "^%s*-?0[xX]")
6
- if hexMatch then
7
- base = 16
8
- local ____string_match_result__0_0
9
- if string.match(hexMatch, "-") then
10
- ____string_match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
11
- else
12
- ____string_match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
1
+ local __TS__ParseInt
2
+ do
3
+ local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
4
+ function __TS__ParseInt(numberString, base)
5
+ if base == nil then
6
+ base = 10
7
+ local hexMatch = string.match(numberString, "^%s*-?0[xX]")
8
+ if hexMatch then
9
+ base = 16
10
+ local ____string_match_result__0_0
11
+ if string.match(hexMatch, "-") then
12
+ ____string_match_result__0_0 = "-" .. __TS__StringSubstr(numberString, #hexMatch)
13
+ else
14
+ ____string_match_result__0_0 = __TS__StringSubstr(numberString, #hexMatch)
15
+ end
16
+ numberString = ____string_match_result__0_0
13
17
  end
14
- numberString = ____string_match_result__0_0
15
18
  end
16
- end
17
- if base < 2 or base > 36 then
18
- return 0 / 0
19
- end
20
- local ____temp_1
21
- if base <= 10 then
22
- ____temp_1 = __TS__StringSubstring(__TS__parseInt_base_pattern, 0, base)
23
- else
24
- ____temp_1 = __TS__StringSubstr(__TS__parseInt_base_pattern, 0, 10 + 2 * (base - 10))
25
- end
26
- local allowedDigits = ____temp_1
27
- local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
28
- local number = tonumber(
29
- string.match(numberString, pattern),
30
- base
31
- )
32
- if number == nil then
33
- return 0 / 0
34
- end
35
- if number >= 0 then
36
- return math.floor(number)
37
- else
38
- return math.ceil(number)
19
+ if base < 2 or base > 36 then
20
+ return 0 / 0
21
+ end
22
+ local ____temp_1
23
+ if base <= 10 then
24
+ ____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
25
+ else
26
+ ____temp_1 = __TS__StringSubstr(parseIntBasePattern, 0, 10 + 2 * (base - 10))
27
+ end
28
+ local allowedDigits = ____temp_1
29
+ local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
30
+ local number = tonumber(
31
+ string.match(numberString, pattern),
32
+ base
33
+ )
34
+ if number == nil then
35
+ return 0 / 0
36
+ end
37
+ if number >= 0 then
38
+ return math.floor(number)
39
+ else
40
+ return math.ceil(number)
41
+ end
39
42
  end
40
43
  end
@@ -1,176 +1,172 @@
1
- __TS__PromiseState = __TS__PromiseState or ({})
2
- __TS__PromiseState.Pending = 0
3
- __TS__PromiseState[__TS__PromiseState.Pending] = "Pending"
4
- __TS__PromiseState.Fulfilled = 1
5
- __TS__PromiseState[__TS__PromiseState.Fulfilled] = "Fulfilled"
6
- __TS__PromiseState.Rejected = 2
7
- __TS__PromiseState[__TS__PromiseState.Rejected] = "Rejected"
8
- function __TS__PromiseDeferred(self)
9
- local resolve
10
- local reject
11
- local promise = __TS__New(
12
- __TS__Promise,
13
- function(____, res, rej)
14
- resolve = res
15
- reject = rej
16
- end
17
- )
18
- return {promise = promise, resolve = resolve, reject = reject}
19
- end
20
- function __TS__IsPromiseLike(self, thing)
21
- return __TS__InstanceOf(thing, __TS__Promise)
22
- end
23
- __TS__Promise = __TS__Class()
24
- __TS__Promise.name = "__TS__Promise"
25
- function __TS__Promise.prototype.____constructor(self, executor)
26
- self.state = __TS__PromiseState.Pending
27
- self.fulfilledCallbacks = {}
28
- self.rejectedCallbacks = {}
29
- self.finallyCallbacks = {}
30
- do
31
- local function ____catch(e)
32
- self:reject(e)
33
- end
34
- local ____try, ____hasReturned = pcall(function()
35
- executor(
36
- _G,
37
- __TS__FunctionBind(self.resolve, self),
38
- __TS__FunctionBind(self.reject, self)
39
- )
40
- end)
41
- if not ____try then
42
- ____catch(____hasReturned)
1
+ local __TS__Promise
2
+ do
3
+ local function promiseDeferred(self)
4
+ local resolve
5
+ local reject
6
+ local promise = __TS__New(
7
+ __TS__Promise,
8
+ function(____, res, rej)
9
+ resolve = res
10
+ reject = rej
11
+ end
12
+ )
13
+ return {promise = promise, resolve = resolve, reject = reject}
14
+ end
15
+ local function isPromiseLike(self, thing)
16
+ return __TS__InstanceOf(thing, __TS__Promise)
17
+ end
18
+ __TS__Promise = __TS__Class()
19
+ __TS__Promise.name = "__TS__Promise"
20
+ function __TS__Promise.prototype.____constructor(self, executor)
21
+ self.state = 0
22
+ self.fulfilledCallbacks = {}
23
+ self.rejectedCallbacks = {}
24
+ self.finallyCallbacks = {}
25
+ do
26
+ local function ____catch(e)
27
+ self:reject(e)
28
+ end
29
+ local ____try, ____hasReturned = pcall(function()
30
+ executor(
31
+ nil,
32
+ __TS__FunctionBind(self.resolve, self),
33
+ __TS__FunctionBind(self.reject, self)
34
+ )
35
+ end)
36
+ if not ____try then
37
+ ____catch(____hasReturned)
38
+ end
43
39
  end
44
40
  end
45
- end
46
- function __TS__Promise.resolve(data)
47
- local promise = __TS__New(
48
- __TS__Promise,
49
- function()
41
+ function __TS__Promise.resolve(data)
42
+ local promise = __TS__New(
43
+ __TS__Promise,
44
+ function()
45
+ end
46
+ )
47
+ promise.state = 1
48
+ promise.value = data
49
+ return promise
50
+ end
51
+ function __TS__Promise.reject(reason)
52
+ local promise = __TS__New(
53
+ __TS__Promise,
54
+ function()
55
+ end
56
+ )
57
+ promise.state = 2
58
+ promise.rejectionReason = reason
59
+ return promise
60
+ end
61
+ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
62
+ local ____promiseDeferred_result_0 = promiseDeferred(nil)
63
+ local promise = ____promiseDeferred_result_0.promise
64
+ local resolve = ____promiseDeferred_result_0.resolve
65
+ local reject = ____promiseDeferred_result_0.reject
66
+ local isFulfilled = self.state == 1
67
+ local isRejected = self.state == 2
68
+ if onFulfilled then
69
+ local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
70
+ __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
71
+ if isFulfilled then
72
+ internalCallback(nil, self.value)
73
+ end
74
+ else
75
+ __TS__ArrayPush(
76
+ self.fulfilledCallbacks,
77
+ function() return resolve(nil, nil) end
78
+ )
50
79
  end
51
- )
52
- promise.state = __TS__PromiseState.Fulfilled
53
- promise.value = data
54
- return promise
55
- end
56
- function __TS__Promise.reject(reason)
57
- local promise = __TS__New(
58
- __TS__Promise,
59
- function()
80
+ if onRejected then
81
+ local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
82
+ __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
83
+ if isRejected then
84
+ internalCallback(nil, self.rejectionReason)
85
+ end
60
86
  end
61
- )
62
- promise.state = __TS__PromiseState.Rejected
63
- promise.rejectionReason = reason
64
- return promise
65
- end
66
- __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
67
- local ____TS__PromiseDeferred_result_0 = __TS__PromiseDeferred(_G)
68
- local promise = ____TS__PromiseDeferred_result_0.promise
69
- local resolve = ____TS__PromiseDeferred_result_0.resolve
70
- local reject = ____TS__PromiseDeferred_result_0.reject
71
- local isFulfilled = self.state == __TS__PromiseState.Fulfilled
72
- local isRejected = self.state == __TS__PromiseState.Rejected
73
- if onFulfilled then
74
- local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
75
- __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
76
87
  if isFulfilled then
77
- internalCallback(_G, self.value)
88
+ resolve(nil, self.value)
78
89
  end
79
- else
80
- __TS__ArrayPush(
81
- self.fulfilledCallbacks,
82
- function() return resolve(_G, nil) end
83
- )
84
- end
85
- if onRejected then
86
- local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
87
- __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
88
90
  if isRejected then
89
- internalCallback(_G, self.rejectionReason)
91
+ reject(nil, self.rejectionReason)
90
92
  end
93
+ return promise
91
94
  end
92
- if isFulfilled then
93
- resolve(_G, self.value)
95
+ function __TS__Promise.prototype.catch(self, onRejected)
96
+ return self["then"](self, nil, onRejected)
94
97
  end
95
- if isRejected then
96
- reject(_G, self.rejectionReason)
97
- end
98
- return promise
99
- end
100
- function __TS__Promise.prototype.catch(self, onRejected)
101
- return self["then"](self, nil, onRejected)
102
- end
103
- function __TS__Promise.prototype.finally(self, onFinally)
104
- if onFinally then
105
- __TS__ArrayPush(self.finallyCallbacks, onFinally)
106
- if self.state ~= __TS__PromiseState.Pending then
107
- onFinally(_G)
98
+ function __TS__Promise.prototype.finally(self, onFinally)
99
+ if onFinally then
100
+ __TS__ArrayPush(self.finallyCallbacks, onFinally)
101
+ if self.state ~= 0 then
102
+ onFinally(nil)
103
+ end
108
104
  end
105
+ return self
109
106
  end
110
- return self
111
- end
112
- function __TS__Promise.prototype.resolve(self, data)
113
- if __TS__InstanceOf(data, __TS__Promise) then
114
- data["then"](
115
- data,
116
- function(____, v) return self:resolve(v) end,
117
- function(____, err) return self:reject(err) end
118
- )
119
- return
120
- end
121
- if self.state == __TS__PromiseState.Pending then
122
- self.state = __TS__PromiseState.Fulfilled
123
- self.value = data
124
- for ____, callback in ipairs(self.fulfilledCallbacks) do
125
- callback(_G, data)
107
+ function __TS__Promise.prototype.resolve(self, data)
108
+ if __TS__InstanceOf(data, __TS__Promise) then
109
+ data["then"](
110
+ data,
111
+ function(____, v) return self:resolve(v) end,
112
+ function(____, err) return self:reject(err) end
113
+ )
114
+ return
126
115
  end
127
- for ____, callback in ipairs(self.finallyCallbacks) do
128
- callback(_G)
116
+ if self.state == 0 then
117
+ self.state = 1
118
+ self.value = data
119
+ for ____, callback in ipairs(self.fulfilledCallbacks) do
120
+ callback(nil, data)
121
+ end
122
+ for ____, callback in ipairs(self.finallyCallbacks) do
123
+ callback(nil)
124
+ end
129
125
  end
130
126
  end
131
- end
132
- function __TS__Promise.prototype.reject(self, reason)
133
- if self.state == __TS__PromiseState.Pending then
134
- self.state = __TS__PromiseState.Rejected
135
- self.rejectionReason = reason
136
- for ____, callback in ipairs(self.rejectedCallbacks) do
137
- callback(_G, reason)
138
- end
139
- for ____, callback in ipairs(self.finallyCallbacks) do
140
- callback(_G)
127
+ function __TS__Promise.prototype.reject(self, reason)
128
+ if self.state == 0 then
129
+ self.state = 2
130
+ self.rejectionReason = reason
131
+ for ____, callback in ipairs(self.rejectedCallbacks) do
132
+ callback(nil, reason)
133
+ end
134
+ for ____, callback in ipairs(self.finallyCallbacks) do
135
+ callback(nil)
136
+ end
141
137
  end
142
138
  end
143
- end
144
- function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
145
- return function(____, value)
146
- do
147
- local function ____catch(e)
148
- reject(_G, e)
149
- end
150
- local ____try, ____hasReturned = pcall(function()
151
- self:handleCallbackData(
152
- f(_G, value),
153
- resolve,
154
- reject
155
- )
156
- end)
157
- if not ____try then
158
- ____catch(____hasReturned)
139
+ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
140
+ return function(____, value)
141
+ do
142
+ local function ____catch(e)
143
+ reject(nil, e)
144
+ end
145
+ local ____try, ____hasReturned = pcall(function()
146
+ self:handleCallbackData(
147
+ f(nil, value),
148
+ resolve,
149
+ reject
150
+ )
151
+ end)
152
+ if not ____try then
153
+ ____catch(____hasReturned)
154
+ end
159
155
  end
160
156
  end
161
157
  end
162
- end
163
- function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
164
- if __TS__IsPromiseLike(_G, data) then
165
- local nextpromise = data
166
- if nextpromise.state == __TS__PromiseState.Fulfilled then
167
- resolve(_G, nextpromise.value)
168
- elseif nextpromise.state == __TS__PromiseState.Rejected then
169
- reject(_G, nextpromise.rejectionReason)
158
+ function __TS__Promise.prototype.handleCallbackData(self, data, resolve, reject)
159
+ if isPromiseLike(nil, data) then
160
+ local nextpromise = data
161
+ if nextpromise.state == 1 then
162
+ resolve(nil, nextpromise.value)
163
+ elseif nextpromise.state == 2 then
164
+ reject(nil, nextpromise.rejectionReason)
165
+ else
166
+ data["then"](data, resolve, reject)
167
+ end
170
168
  else
171
- data["then"](data, resolve, reject)
169
+ resolve(nil, data)
172
170
  end
173
- else
174
- resolve(_G, data)
175
171
  end
176
172
  end
@@ -1,13 +1,13 @@
1
- function __TS__PromiseAll(iterable)
1
+ local function __TS__PromiseAll(iterable)
2
2
  local results = {}
3
3
  local toResolve = {}
4
4
  local numToResolve = 0
5
5
  local i = 0
6
6
  for ____, item in __TS__Iterator(iterable) do
7
7
  if __TS__InstanceOf(item, __TS__Promise) then
8
- if item.state == __TS__PromiseState.Fulfilled then
8
+ if item.state == 1 then
9
9
  results[i + 1] = item.value
10
- elseif item.state == __TS__PromiseState.Rejected then
10
+ elseif item.state == 2 then
11
11
  return __TS__Promise.reject(item.rejectionReason)
12
12
  else
13
13
  numToResolve = numToResolve + 1
@@ -31,11 +31,11 @@ function __TS__PromiseAll(iterable)
31
31
  results[index + 1] = data
32
32
  numToResolve = numToResolve - 1
33
33
  if numToResolve == 0 then
34
- resolve(_G, results)
34
+ resolve(nil, results)
35
35
  end
36
36
  end,
37
37
  function(____, reason)
38
- reject(_G, reason)
38
+ reject(nil, reason)
39
39
  end
40
40
  )
41
41
  end
@@ -1,13 +1,13 @@
1
- function __TS__PromiseAllSettled(iterable)
1
+ local function __TS__PromiseAllSettled(iterable)
2
2
  local results = {}
3
3
  local toResolve = {}
4
4
  local numToResolve = 0
5
5
  local i = 0
6
6
  for ____, item in __TS__Iterator(iterable) do
7
7
  if __TS__InstanceOf(item, __TS__Promise) then
8
- if item.state == __TS__PromiseState.Fulfilled then
8
+ if item.state == 1 then
9
9
  results[i + 1] = {status = "fulfilled", value = item.value}
10
- elseif item.state == __TS__PromiseState.Rejected then
10
+ elseif item.state == 2 then
11
11
  results[i + 1] = {status = "rejected", reason = item.rejectionReason}
12
12
  else
13
13
  numToResolve = numToResolve + 1
@@ -31,14 +31,14 @@ function __TS__PromiseAllSettled(iterable)
31
31
  results[index + 1] = {status = "fulfilled", value = data}
32
32
  numToResolve = numToResolve - 1
33
33
  if numToResolve == 0 then
34
- resolve(_G, results)
34
+ resolve(nil, results)
35
35
  end
36
36
  end,
37
37
  function(____, reason)
38
38
  results[index + 1] = {status = "rejected", reason = reason}
39
39
  numToResolve = numToResolve - 1
40
40
  if numToResolve == 0 then
41
- resolve(_G, results)
41
+ resolve(nil, results)
42
42
  end
43
43
  end
44
44
  )