typescript-to-lua 1.0.1 → 1.3.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 (194) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/CompilerOptions.d.ts +4 -3
  3. package/dist/LuaAST.d.ts +1 -0
  4. package/dist/LuaAST.js +14 -6
  5. package/dist/LuaLib.d.ts +4 -3
  6. package/dist/LuaLib.js +6 -5
  7. package/dist/LuaPrinter.d.ts +15 -4
  8. package/dist/LuaPrinter.js +81 -29
  9. package/dist/cli/diagnostics.js +2 -2
  10. package/dist/cli/parse.d.ts +1 -1
  11. package/dist/cli/parse.js +14 -0
  12. package/dist/cli/report.js +1 -1
  13. package/dist/cli/tsconfig.js +4 -4
  14. package/dist/lualib/ArrayFlat.lua +1 -1
  15. package/dist/lualib/ArrayFlatMap.lua +1 -1
  16. package/dist/lualib/ArrayIsArray.lua +1 -1
  17. package/dist/lualib/ArrayReduce.lua +7 -1
  18. package/dist/lualib/ArrayReduceRight.lua +7 -1
  19. package/dist/lualib/ArraySetLength.lua +1 -1
  20. package/dist/lualib/ArraySplice.lua +5 -5
  21. package/dist/lualib/Await.lua +43 -19
  22. package/dist/lualib/CloneDescriptor.lua +7 -7
  23. package/dist/lualib/Decorate.lua +1 -1
  24. package/dist/lualib/DelegatedYield.lua +1 -3
  25. package/dist/lualib/Delete.lua +6 -6
  26. package/dist/lualib/Error.lua +47 -44
  27. package/dist/lualib/Generator.lua +1 -5
  28. package/dist/lualib/InstanceOf.lua +1 -1
  29. package/dist/lualib/InstanceOfObject.lua +1 -1
  30. package/dist/lualib/Map.lua +130 -134
  31. package/dist/lualib/Number.lua +1 -1
  32. package/dist/lualib/NumberIsFinite.lua +1 -1
  33. package/dist/lualib/NumberToString.lua +3 -5
  34. package/dist/lualib/ObjectDefineProperty.lua +40 -8
  35. package/dist/lualib/ParseFloat.lua +9 -5
  36. package/dist/lualib/ParseInt.lua +15 -3
  37. package/dist/lualib/Promise.lua +44 -26
  38. package/dist/lualib/Set.lua +119 -123
  39. package/dist/lualib/SetDescriptor.lua +7 -1
  40. package/dist/lualib/SourceMapTraceBack.lua +19 -9
  41. package/dist/lualib/SparseArrayNew.lua +5 -0
  42. package/dist/lualib/SparseArrayPush.lua +9 -0
  43. package/dist/lualib/SparseArraySpread.lua +4 -0
  44. package/dist/lualib/StringAccess.lua +1 -1
  45. package/dist/lualib/StringCharCodeAt.lua +1 -1
  46. package/dist/lualib/StringEndsWith.lua +2 -2
  47. package/dist/lualib/StringPadEnd.lua +2 -2
  48. package/dist/lualib/StringPadStart.lua +2 -2
  49. package/dist/lualib/StringReplace.lua +12 -11
  50. package/dist/lualib/StringReplaceAll.lua +35 -0
  51. package/dist/lualib/StringSlice.lua +2 -2
  52. package/dist/lualib/StringSplit.lua +3 -3
  53. package/dist/lualib/StringStartsWith.lua +1 -1
  54. package/dist/lualib/StringSubstr.lua +1 -1
  55. package/dist/lualib/StringSubstring.lua +2 -2
  56. package/dist/lualib/Symbol.lua +3 -5
  57. package/dist/lualib/WeakMap.lua +40 -42
  58. package/dist/lualib/WeakSet.lua +36 -38
  59. package/dist/lualib/lualib_bundle.lua +876 -745
  60. package/dist/transformation/builtins/array.js +29 -30
  61. package/dist/transformation/builtins/console.js +2 -2
  62. package/dist/transformation/builtins/function.js +14 -12
  63. package/dist/transformation/builtins/global.js +8 -8
  64. package/dist/transformation/builtins/index.d.ts +1 -1
  65. package/dist/transformation/builtins/index.js +69 -36
  66. package/dist/transformation/builtins/math.js +4 -4
  67. package/dist/transformation/builtins/number.js +7 -7
  68. package/dist/transformation/builtins/object.d.ts +2 -1
  69. package/dist/transformation/builtins/object.js +12 -13
  70. package/dist/transformation/builtins/promise.js +9 -9
  71. package/dist/transformation/builtins/string.js +32 -31
  72. package/dist/transformation/builtins/symbol.js +3 -3
  73. package/dist/transformation/context/context.d.ts +12 -0
  74. package/dist/transformation/context/context.js +105 -6
  75. package/dist/transformation/index.js +1 -1
  76. package/dist/transformation/utils/annotations.d.ts +1 -3
  77. package/dist/transformation/utils/annotations.js +0 -2
  78. package/dist/transformation/utils/assignment-validation.js +8 -7
  79. package/dist/transformation/utils/diagnostics.d.ts +9 -0
  80. package/dist/transformation/utils/diagnostics.js +8 -5
  81. package/dist/transformation/utils/export.d.ts +3 -2
  82. package/dist/transformation/utils/export.js +14 -7
  83. package/dist/transformation/utils/function-context.js +8 -8
  84. package/dist/transformation/utils/language-extensions.d.ts +2 -0
  85. package/dist/transformation/utils/language-extensions.js +7 -1
  86. package/dist/transformation/utils/lua-ast.d.ts +0 -1
  87. package/dist/transformation/utils/lua-ast.js +25 -35
  88. package/dist/transformation/utils/lualib.js +1 -1
  89. package/dist/transformation/utils/preceding-statements.d.ts +3 -0
  90. package/dist/transformation/utils/preceding-statements.js +11 -0
  91. package/dist/transformation/utils/safe-names.d.ts +4 -2
  92. package/dist/transformation/utils/safe-names.js +13 -7
  93. package/dist/transformation/utils/scope.d.ts +9 -1
  94. package/dist/transformation/utils/scope.js +78 -40
  95. package/dist/transformation/utils/symbols.js +6 -6
  96. package/dist/transformation/utils/typescript/index.d.ts +1 -0
  97. package/dist/transformation/utils/typescript/index.js +16 -1
  98. package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
  99. package/dist/transformation/utils/typescript/nodes.js +21 -1
  100. package/dist/transformation/utils/typescript/types.d.ts +3 -1
  101. package/dist/transformation/utils/typescript/types.js +40 -13
  102. package/dist/transformation/visitors/access.d.ts +3 -0
  103. package/dist/transformation/visitors/access.js +74 -47
  104. package/dist/transformation/visitors/async-await.js +5 -4
  105. package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
  106. package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
  107. package/dist/transformation/visitors/binary-expression/bit.js +4 -4
  108. package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
  109. package/dist/transformation/visitors/binary-expression/compound.js +69 -71
  110. package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
  111. package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
  112. package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
  113. package/dist/transformation/visitors/binary-expression/index.js +84 -42
  114. package/dist/transformation/visitors/block.js +6 -6
  115. package/dist/transformation/visitors/break-continue.js +2 -2
  116. package/dist/transformation/visitors/call.d.ts +3 -2
  117. package/dist/transformation/visitors/call.js +130 -143
  118. package/dist/transformation/visitors/class/decorators.js +3 -3
  119. package/dist/transformation/visitors/class/index.js +43 -39
  120. package/dist/transformation/visitors/class/members/accessors.js +6 -6
  121. package/dist/transformation/visitors/class/members/constructor.js +7 -7
  122. package/dist/transformation/visitors/class/members/fields.js +6 -6
  123. package/dist/transformation/visitors/class/members/method.js +6 -6
  124. package/dist/transformation/visitors/class/new.js +14 -16
  125. package/dist/transformation/visitors/class/setup.js +11 -11
  126. package/dist/transformation/visitors/class/utils.js +2 -2
  127. package/dist/transformation/visitors/conditional.js +36 -43
  128. package/dist/transformation/visitors/delete.js +8 -4
  129. package/dist/transformation/visitors/enum.js +8 -8
  130. package/dist/transformation/visitors/errors.js +35 -33
  131. package/dist/transformation/visitors/expression-list.d.ts +7 -0
  132. package/dist/transformation/visitors/expression-list.js +120 -0
  133. package/dist/transformation/visitors/expression-statement.js +10 -6
  134. package/dist/transformation/visitors/function.d.ts +2 -0
  135. package/dist/transformation/visitors/function.js +80 -33
  136. package/dist/transformation/visitors/identifier.js +26 -22
  137. package/dist/transformation/visitors/index.js +2 -2
  138. package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
  139. package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
  140. package/dist/transformation/visitors/language-extensions/multi.js +3 -3
  141. package/dist/transformation/visitors/language-extensions/operators.js +6 -6
  142. package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +5 -0
  143. package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
  144. package/dist/transformation/visitors/language-extensions/range.js +6 -6
  145. package/dist/transformation/visitors/language-extensions/table.js +5 -5
  146. package/dist/transformation/visitors/literal.d.ts +1 -2
  147. package/dist/transformation/visitors/literal.js +87 -57
  148. package/dist/transformation/visitors/loops/do-while.js +35 -9
  149. package/dist/transformation/visitors/loops/for-in.js +4 -4
  150. package/dist/transformation/visitors/loops/for-of.js +17 -13
  151. package/dist/transformation/visitors/loops/for.js +28 -8
  152. package/dist/transformation/visitors/loops/utils.d.ts +1 -0
  153. package/dist/transformation/visitors/loops/utils.js +26 -10
  154. package/dist/transformation/visitors/modules/export.js +14 -15
  155. package/dist/transformation/visitors/modules/import.js +10 -10
  156. package/dist/transformation/visitors/namespace.js +13 -13
  157. package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
  158. package/dist/transformation/visitors/optional-chaining.js +172 -0
  159. package/dist/transformation/visitors/return.d.ts +1 -0
  160. package/dist/transformation/visitors/return.js +40 -26
  161. package/dist/transformation/visitors/sourceFile.js +12 -9
  162. package/dist/transformation/visitors/spread.js +23 -16
  163. package/dist/transformation/visitors/switch.js +63 -20
  164. package/dist/transformation/visitors/template.js +10 -7
  165. package/dist/transformation/visitors/typeof.js +4 -2
  166. package/dist/transformation/visitors/typescript.js +1 -1
  167. package/dist/transformation/visitors/unary-expression.js +9 -9
  168. package/dist/transformation/visitors/variable-declaration.js +55 -32
  169. package/dist/transformation/visitors/void.d.ts +6 -0
  170. package/dist/transformation/visitors/void.js +20 -0
  171. package/dist/transpilation/bundle.d.ts +3 -0
  172. package/dist/transpilation/bundle.js +52 -10
  173. package/dist/transpilation/diagnostics.js +3 -3
  174. package/dist/transpilation/index.js +2 -2
  175. package/dist/transpilation/output-collector.js +2 -2
  176. package/dist/transpilation/plugins.js +1 -1
  177. package/dist/transpilation/resolve.js +20 -13
  178. package/dist/transpilation/transformers.js +45 -25
  179. package/dist/transpilation/transpile.js +6 -6
  180. package/dist/transpilation/transpiler.js +8 -8
  181. package/dist/transpilation/utils.js +5 -3
  182. package/dist/tstl.js +8 -8
  183. package/dist/utils.js +2 -2
  184. package/language-extensions/index.d.ts +11 -1
  185. package/package.json +15 -12
  186. package/dist/lualib/OptionalChainAccess.lua +0 -6
  187. package/dist/lualib/OptionalFunctionCall.lua +0 -6
  188. package/dist/lualib/OptionalMethodCall.lua +0 -11
  189. package/dist/transformation/utils/transform.d.ts +0 -8
  190. package/dist/transformation/utils/transform.js +0 -14
  191. package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
  192. package/dist/transformation/visitors/jsx/jsx.js +0 -237
  193. package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
  194. package/dist/transformation/visitors/jsx/xhtml.js +0 -260
@@ -1,5 +1,5 @@
1
1
  function __TS__ArraySetLength(arr, length)
2
- if (((length < 0) or (length ~= length)) or (length == math.huge)) or (math.floor(length) ~= length) then
2
+ if length < 0 or length ~= length or length == math.huge or math.floor(length) ~= length then
3
3
  error(
4
4
  "invalid array length: " .. tostring(length),
5
5
  0
@@ -35,7 +35,7 @@ function __TS__ArraySplice(list, ...)
35
35
  if itemCount < actualDeleteCount then
36
36
  do
37
37
  local k = actualStart
38
- while k < (len - actualDeleteCount) do
38
+ while k < len - actualDeleteCount do
39
39
  local from = k + actualDeleteCount
40
40
  local to = k + itemCount
41
41
  if list[from + 1] then
@@ -48,7 +48,7 @@ function __TS__ArraySplice(list, ...)
48
48
  end
49
49
  do
50
50
  local k = len
51
- while k > ((len - actualDeleteCount) + itemCount) do
51
+ while k > len - actualDeleteCount + itemCount do
52
52
  list[k] = nil
53
53
  k = k - 1
54
54
  end
@@ -57,8 +57,8 @@ function __TS__ArraySplice(list, ...)
57
57
  do
58
58
  local k = len - actualDeleteCount
59
59
  while k > actualStart do
60
- local from = (k + actualDeleteCount) - 1
61
- local to = (k + itemCount) - 1
60
+ local from = k + actualDeleteCount - 1
61
+ local to = k + itemCount - 1
62
62
  if list[from + 1] then
63
63
  list[to + 1] = list[from + 1]
64
64
  else
@@ -75,7 +75,7 @@ function __TS__ArraySplice(list, ...)
75
75
  end
76
76
  do
77
77
  local k = #list - 1
78
- while k >= ((len - actualDeleteCount) + itemCount) do
78
+ while k >= len - actualDeleteCount + itemCount do
79
79
  list[k + 1] = nil
80
80
  k = k - 1
81
81
  end
@@ -2,42 +2,66 @@ function __TS__AsyncAwaiter(generator)
2
2
  return __TS__New(
3
3
  __TS__Promise,
4
4
  function(____, resolve, reject)
5
- local asyncCoroutine, adopt, fulfilled, step
5
+ local adopt, fulfilled, rejected, step, asyncCoroutine
6
6
  function adopt(self, value)
7
- return ((__TS__InstanceOf(value, __TS__Promise) and (function() return value end)) or (function() return __TS__Promise.resolve(value) end))()
7
+ local ____temp_0
8
+ if __TS__InstanceOf(value, __TS__Promise) then
9
+ ____temp_0 = value
10
+ else
11
+ ____temp_0 = __TS__Promise.resolve(value)
12
+ end
13
+ return ____temp_0
8
14
  end
9
15
  function fulfilled(self, value)
10
- local success, resultOrError = coroutine.resume(asyncCoroutine, value)
16
+ local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine, value)
11
17
  if success then
12
- step(_G, resultOrError)
18
+ step(_G, resultOrError, errorOrErrorHandler)
19
+ else
20
+ reject(_G, errorOrErrorHandler)
21
+ end
22
+ end
23
+ function rejected(self, handler)
24
+ if handler then
25
+ return function(____, value)
26
+ local success, hasReturnedOrError, returnedValue = pcall(handler, value)
27
+ if success then
28
+ if hasReturnedOrError then
29
+ resolve(_G, returnedValue)
30
+ else
31
+ step(_G, hasReturnedOrError, handler)
32
+ end
33
+ else
34
+ reject(_G, hasReturnedOrError)
35
+ end
36
+ end
13
37
  else
14
- reject(_G, resultOrError)
38
+ return function(____, value)
39
+ reject(_G, value)
40
+ end
15
41
  end
16
42
  end
17
- function step(self, result)
43
+ function step(self, result, errorHandler)
18
44
  if coroutine.status(asyncCoroutine) == "dead" then
19
45
  resolve(_G, result)
20
46
  else
21
- (function()
22
- local ____self = adopt(_G, result)
23
- return ____self["then"](
24
- ____self,
25
- fulfilled,
26
- function(____, reason) return reject(_G, reason) end
27
- )
28
- end)()
47
+ local ____self_1 = adopt(_G, result)
48
+ ____self_1["then"](
49
+ ____self_1,
50
+ fulfilled,
51
+ rejected(_G, errorHandler)
52
+ )
29
53
  end
30
54
  end
31
55
  asyncCoroutine = coroutine.create(generator)
32
- local success, resultOrError = coroutine.resume(asyncCoroutine)
56
+ local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
33
57
  if success then
34
- step(_G, resultOrError)
58
+ step(_G, resultOrError, errorOrErrorHandler)
35
59
  else
36
- reject(_G, resultOrError)
60
+ reject(_G, errorOrErrorHandler)
37
61
  end
38
62
  end
39
63
  )
40
64
  end
41
- function __TS__Await(thing)
42
- return coroutine.yield(thing)
65
+ function __TS__Await(errorHandler, thing)
66
+ return coroutine.yield(errorHandler, thing)
43
67
  end
@@ -1,19 +1,19 @@
1
1
  function __TS__CloneDescriptor(____bindingPattern0)
2
+ local value
3
+ local writable
4
+ local set
5
+ local get
6
+ local configurable
2
7
  local enumerable
3
8
  enumerable = ____bindingPattern0.enumerable
4
- local configurable
5
9
  configurable = ____bindingPattern0.configurable
6
- local get
7
10
  get = ____bindingPattern0.get
8
- local set
9
11
  set = ____bindingPattern0.set
10
- local writable
11
12
  writable = ____bindingPattern0.writable
12
- local value
13
13
  value = ____bindingPattern0.value
14
14
  local descriptor = {enumerable = enumerable == true, configurable = configurable == true}
15
- local hasGetterOrSetter = (get ~= nil) or (set ~= nil)
16
- local hasValueOrWritableAttribute = (writable ~= nil) or (value ~= nil)
15
+ local hasGetterOrSetter = get ~= nil or set ~= nil
16
+ local hasValueOrWritableAttribute = writable ~= nil or value ~= nil
17
17
  if hasGetterOrSetter and hasValueOrWritableAttribute then
18
18
  error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.", 0)
19
19
  end
@@ -12,7 +12,7 @@ function __TS__Decorate(decorators, target, key, desc)
12
12
  local value = rawget(target, key)
13
13
  local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
14
  local desc = decorator(_G, target, key, descriptor) or descriptor
15
- local isSimpleValue = (((desc.configurable == true) and (desc.writable == true)) and (not desc.get)) and (not desc.set)
15
+ local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
16
  if isSimpleValue then
17
17
  rawset(target, key, desc.value)
18
18
  else
@@ -1,9 +1,7 @@
1
1
  function __TS__DelegatedYield(iterable)
2
2
  if type(iterable) == "string" then
3
3
  for index = 0, #iterable - 1 do
4
- coroutine.yield(
5
- __TS__StringAccess(iterable, index)
6
- )
4
+ coroutine.yield(__TS__StringAccess(iterable, index))
7
5
  end
8
6
  elseif iterable.____coroutine ~= nil then
9
7
  local co = iterable.____coroutine
@@ -4,16 +4,16 @@ function __TS__Delete(target, key)
4
4
  if descriptor then
5
5
  if not descriptor.configurable then
6
6
  error(
7
- ((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. ".",
7
+ __TS__New(
8
+ TypeError,
9
+ ((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. "."
10
+ ),
8
11
  0
9
12
  )
10
13
  end
11
14
  descriptors[key] = nil
12
15
  return true
13
16
  end
14
- if target[key] ~= nil then
15
- target[key] = nil
16
- return true
17
- end
18
- return false
17
+ target[key] = nil
18
+ return true
19
19
  end
@@ -16,7 +16,7 @@ function __TS__WrapErrorToString(self, getDescription)
16
16
  return function(self)
17
17
  local description = getDescription(self)
18
18
  local caller = debug.getinfo(3, "f")
19
- if (_VERSION == "Lua 5.1") or (caller and (caller.func ~= error)) then
19
+ if _VERSION == "Lua 5.1" or caller and caller.func ~= error then
20
20
  return description
21
21
  else
22
22
  return (tostring(description) .. "\n") .. self.stack
@@ -27,49 +27,52 @@ function __TS__InitErrorClass(self, Type, name)
27
27
  Type.name = name
28
28
  return setmetatable(
29
29
  Type,
30
- {
31
- __call = function(____, _self, message) return __TS__New(Type, message) end
32
- }
30
+ {__call = function(____, _self, message) return __TS__New(Type, message) end}
33
31
  )
34
32
  end
35
- Error = __TS__InitErrorClass(
36
- _G,
37
- (function()
38
- local ____ = __TS__Class()
39
- ____.name = ""
40
- function ____.prototype.____constructor(self, message)
41
- if message == nil then
42
- message = ""
43
- end
44
- self.message = message
45
- self.name = "Error"
46
- self.stack = __TS__GetErrorStack(_G, self.constructor.new)
47
- local metatable = getmetatable(self)
48
- if not metatable.__errorToStringPatched then
49
- metatable.__errorToStringPatched = true
50
- metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
51
- end
52
- end
53
- function ____.prototype.__tostring(self)
54
- return (((self.message ~= "") and (function() return (self.name .. ": ") .. self.message end)) or (function() return self.name end))()
55
- end
56
- return ____
57
- end)(),
58
- "Error"
59
- )
60
- for ____, errorName in ipairs({"RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"}) do
61
- _G[errorName] = __TS__InitErrorClass(
62
- _G,
63
- (function()
64
- local ____ = __TS__Class()
65
- ____.name = ____.name
66
- __TS__ClassExtends(____, Error)
67
- function ____.prototype.____constructor(self, ...)
68
- Error.prototype.____constructor(self, ...)
69
- self.name = errorName
70
- end
71
- return ____
72
- end)(),
73
- errorName
74
- )
33
+ local ____TS__InitErrorClass_3 = __TS__InitErrorClass
34
+ local ____G_2 = _G
35
+ ____class_0 = __TS__Class()
36
+ ____class_0.name = ""
37
+ function ____class_0.prototype.____constructor(self, message)
38
+ if message == nil then
39
+ message = ""
40
+ end
41
+ self.message = message
42
+ self.name = "Error"
43
+ self.stack = __TS__GetErrorStack(_G, self.constructor.new)
44
+ local metatable = getmetatable(self)
45
+ if not metatable.__errorToStringPatched then
46
+ metatable.__errorToStringPatched = true
47
+ metatable.__tostring = __TS__WrapErrorToString(_G, metatable.__tostring)
48
+ end
49
+ end
50
+ function ____class_0.prototype.__tostring(self)
51
+ local ____temp_1
52
+ if self.message ~= "" then
53
+ ____temp_1 = (self.name .. ": ") .. self.message
54
+ else
55
+ ____temp_1 = self.name
56
+ end
57
+ return ____temp_1
58
+ end
59
+ Error = ____TS__InitErrorClass_3(____G_2, ____class_0, "Error")
60
+ for ____, errorName in ipairs({
61
+ "RangeError",
62
+ "ReferenceError",
63
+ "SyntaxError",
64
+ "TypeError",
65
+ "URIError"
66
+ }) do
67
+ local ____G_7 = _G
68
+ local ____TS__InitErrorClass_6 = __TS__InitErrorClass
69
+ local ____G_5 = _G
70
+ local ____class_4 = __TS__Class()
71
+ ____class_4.name = ____class_4.name
72
+ __TS__ClassExtends(____class_4, Error)
73
+ function ____class_4.prototype.____constructor(self, ...)
74
+ Error.prototype.____constructor(self, ...)
75
+ self.name = errorName
76
+ end
77
+ ____G_7[errorName] = ____TS__InitErrorClass_6(____G_5, ____class_4, errorName)
75
78
  end
@@ -20,11 +20,7 @@ function __TS__Generator(fn)
20
20
  local args = {...}
21
21
  local argsLength = select("#", ...)
22
22
  return {
23
- ____coroutine = coroutine.create(
24
- function() return fn(
25
- (unpack or table.unpack)(args, 1, argsLength)
26
- ) end
27
- ),
23
+ ____coroutine = coroutine.create(function() return fn((unpack or table.unpack)(args, 1, argsLength)) end),
28
24
  [Symbol.iterator] = __TS__GeneratorIterator,
29
25
  next = __TS__GeneratorNext
30
26
  }
@@ -3,7 +3,7 @@ function __TS__InstanceOf(obj, classTbl)
3
3
  error("Right-hand side of 'instanceof' is not an object", 0)
4
4
  end
5
5
  if classTbl[Symbol.hasInstance] ~= nil then
6
- return not (not classTbl[Symbol.hasInstance](classTbl, obj))
6
+ return not not classTbl[Symbol.hasInstance](classTbl, obj)
7
7
  end
8
8
  if type(obj) == "table" then
9
9
  local luaClass = obj.constructor
@@ -1,4 +1,4 @@
1
1
  function __TS__InstanceOfObject(value)
2
2
  local valueType = type(value)
3
- return (valueType == "table") or (valueType == "function")
3
+ return valueType == "table" or valueType == "function"
4
4
  end
@@ -1,144 +1,140 @@
1
- Map = (function()
2
- local Map = __TS__Class()
3
- Map.name = "Map"
4
- function Map.prototype.____constructor(self, entries)
5
- self[Symbol.toStringTag] = "Map"
6
- self.items = {}
7
- self.size = 0
8
- self.nextKey = {}
9
- self.previousKey = {}
10
- if entries == nil then
11
- return
12
- end
13
- local iterable = entries
14
- if iterable[Symbol.iterator] then
15
- local iterator = iterable[Symbol.iterator](iterable)
16
- while true do
17
- local result = iterator:next()
18
- if result.done then
19
- break
20
- end
21
- local value = result.value
22
- self:set(value[1], value[2])
23
- end
24
- else
25
- local array = entries
26
- for ____, kvp in ipairs(array) do
27
- self:set(kvp[1], kvp[2])
28
- end
29
- end
1
+ Map = __TS__Class()
2
+ Map.name = "Map"
3
+ function Map.prototype.____constructor(self, entries)
4
+ self[Symbol.toStringTag] = "Map"
5
+ self.items = {}
6
+ self.size = 0
7
+ self.nextKey = {}
8
+ self.previousKey = {}
9
+ if entries == nil then
10
+ return
30
11
  end
31
- function Map.prototype.clear(self)
32
- self.items = {}
33
- self.nextKey = {}
34
- self.previousKey = {}
35
- self.firstKey = nil
36
- self.lastKey = nil
37
- self.size = 0
38
- end
39
- function Map.prototype.delete(self, key)
40
- local contains = self:has(key)
41
- if contains then
42
- self.size = self.size - 1
43
- local next = self.nextKey[key]
44
- local previous = self.previousKey[key]
45
- if next and previous then
46
- self.nextKey[previous] = next
47
- self.previousKey[next] = previous
48
- elseif next then
49
- self.firstKey = next
50
- self.previousKey[next] = nil
51
- elseif previous then
52
- self.lastKey = previous
53
- self.nextKey[previous] = nil
54
- else
55
- self.firstKey = nil
56
- self.lastKey = nil
12
+ local iterable = entries
13
+ if iterable[Symbol.iterator] then
14
+ local iterator = iterable[Symbol.iterator](iterable)
15
+ while true do
16
+ local result = iterator:next()
17
+ if result.done then
18
+ break
57
19
  end
58
- self.nextKey[key] = nil
59
- self.previousKey[key] = nil
20
+ local value = result.value
21
+ self:set(value[1], value[2])
60
22
  end
61
- self.items[key] = nil
62
- return contains
63
- end
64
- function Map.prototype.forEach(self, callback)
65
- for ____, key in __TS__Iterator(
66
- self:keys()
67
- ) do
68
- callback(_G, self.items[key], key, self)
23
+ else
24
+ local array = entries
25
+ for ____, kvp in ipairs(array) do
26
+ self:set(kvp[1], kvp[2])
69
27
  end
70
28
  end
71
- function Map.prototype.get(self, key)
72
- return self.items[key]
73
- end
74
- function Map.prototype.has(self, key)
75
- return (self.nextKey[key] ~= nil) or (self.lastKey == key)
76
- end
77
- function Map.prototype.set(self, key, value)
78
- local isNewValue = not self:has(key)
79
- if isNewValue then
80
- self.size = self.size + 1
81
- end
82
- self.items[key] = value
83
- if self.firstKey == nil then
84
- self.firstKey = key
85
- self.lastKey = key
86
- elseif isNewValue then
87
- self.nextKey[self.lastKey] = key
88
- self.previousKey[key] = self.lastKey
89
- self.lastKey = key
29
+ end
30
+ function Map.prototype.clear(self)
31
+ self.items = {}
32
+ self.nextKey = {}
33
+ self.previousKey = {}
34
+ self.firstKey = nil
35
+ self.lastKey = nil
36
+ self.size = 0
37
+ end
38
+ function Map.prototype.delete(self, key)
39
+ local contains = self:has(key)
40
+ if contains then
41
+ self.size = self.size - 1
42
+ local next = self.nextKey[key]
43
+ local previous = self.previousKey[key]
44
+ if next and previous then
45
+ self.nextKey[previous] = next
46
+ self.previousKey[next] = previous
47
+ elseif next then
48
+ self.firstKey = next
49
+ self.previousKey[next] = nil
50
+ elseif previous then
51
+ self.lastKey = previous
52
+ self.nextKey[previous] = nil
53
+ else
54
+ self.firstKey = nil
55
+ self.lastKey = nil
90
56
  end
91
- return self
57
+ self.nextKey[key] = nil
58
+ self.previousKey[key] = nil
92
59
  end
93
- Map.prototype[Symbol.iterator] = function(self)
94
- return self:entries()
60
+ self.items[key] = nil
61
+ return contains
62
+ end
63
+ function Map.prototype.forEach(self, callback)
64
+ for ____, key in __TS__Iterator(self:keys()) do
65
+ callback(_G, self.items[key], key, self)
95
66
  end
96
- function Map.prototype.entries(self)
97
- local ____ = self
98
- local items = ____.items
99
- local nextKey = ____.nextKey
100
- local key = self.firstKey
101
- return {
102
- [Symbol.iterator] = function(self)
103
- return self
104
- end,
105
- next = function(self)
106
- local result = {done = not key, value = {key, items[key]}}
107
- key = nextKey[key]
108
- return result
109
- end
110
- }
67
+ end
68
+ function Map.prototype.get(self, key)
69
+ return self.items[key]
70
+ end
71
+ function Map.prototype.has(self, key)
72
+ return self.nextKey[key] ~= nil or self.lastKey == key
73
+ end
74
+ function Map.prototype.set(self, key, value)
75
+ local isNewValue = not self:has(key)
76
+ if isNewValue then
77
+ self.size = self.size + 1
111
78
  end
112
- function Map.prototype.keys(self)
113
- local nextKey = self.nextKey
114
- local key = self.firstKey
115
- return {
116
- [Symbol.iterator] = function(self)
117
- return self
118
- end,
119
- next = function(self)
120
- local result = {done = not key, value = key}
121
- key = nextKey[key]
122
- return result
123
- end
124
- }
79
+ self.items[key] = value
80
+ if self.firstKey == nil then
81
+ self.firstKey = key
82
+ self.lastKey = key
83
+ elseif isNewValue then
84
+ self.nextKey[self.lastKey] = key
85
+ self.previousKey[key] = self.lastKey
86
+ self.lastKey = key
125
87
  end
126
- function Map.prototype.values(self)
127
- local ____ = self
128
- local items = ____.items
129
- local nextKey = ____.nextKey
130
- local key = self.firstKey
131
- return {
132
- [Symbol.iterator] = function(self)
133
- return self
134
- end,
135
- next = function(self)
136
- local result = {done = not key, value = items[key]}
137
- key = nextKey[key]
138
- return result
139
- end
140
- }
141
- end
142
- Map[Symbol.species] = Map
143
- return Map
144
- end)()
88
+ return self
89
+ end
90
+ Map.prototype[Symbol.iterator] = function(self)
91
+ return self:entries()
92
+ end
93
+ function Map.prototype.entries(self)
94
+ local ____temp_0 = self
95
+ local items = ____temp_0.items
96
+ local nextKey = ____temp_0.nextKey
97
+ local key = self.firstKey
98
+ return {
99
+ [Symbol.iterator] = function(self)
100
+ return self
101
+ end,
102
+ next = function(self)
103
+ local result = {done = not key, value = {key, items[key]}}
104
+ key = nextKey[key]
105
+ return result
106
+ end
107
+ }
108
+ end
109
+ function Map.prototype.keys(self)
110
+ local nextKey = self.nextKey
111
+ local key = self.firstKey
112
+ return {
113
+ [Symbol.iterator] = function(self)
114
+ return self
115
+ end,
116
+ next = function(self)
117
+ local result = {done = not key, value = key}
118
+ key = nextKey[key]
119
+ return result
120
+ end
121
+ }
122
+ end
123
+ function Map.prototype.values(self)
124
+ local ____temp_1 = self
125
+ local items = ____temp_1.items
126
+ local nextKey = ____temp_1.nextKey
127
+ local key = self.firstKey
128
+ return {
129
+ [Symbol.iterator] = function(self)
130
+ return self
131
+ end,
132
+ next = function(self)
133
+ local result = {done = not key, value = items[key]}
134
+ key = nextKey[key]
135
+ return result
136
+ end
137
+ }
138
+ end
139
+ Map[Symbol.species] = Map
140
+ Map = Map
@@ -19,7 +19,7 @@ function __TS__Number(value)
19
19
  end
20
20
  return 0 / 0
21
21
  elseif valueType == "boolean" then
22
- return (value and 1) or 0
22
+ return value and 1 or 0
23
23
  else
24
24
  return 0 / 0
25
25
  end
@@ -1,3 +1,3 @@
1
1
  function __TS__NumberIsFinite(value)
2
- return (((type(value) == "number") and (value == value)) and (value ~= math.huge)) and (value ~= -math.huge)
2
+ return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
3
3
  end
@@ -1,15 +1,13 @@
1
1
  ____radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
2
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
3
+ if radix == nil or radix == 10 or self == math.huge or self == -math.huge or self ~= self then
4
4
  return tostring(self)
5
5
  end
6
6
  radix = math.floor(radix)
7
- if (radix < 2) or (radix > 36) then
7
+ if radix < 2 or radix > 36 then
8
8
  error("toString() radix argument must be between 2 and 36", 0)
9
9
  end
10
- local integer, fraction = math.modf(
11
- math.abs(self)
12
- )
10
+ local integer, fraction = math.modf(math.abs(self))
13
11
  local result = ""
14
12
  if radix == 8 then
15
13
  result = string.format("%o", integer)