typescript-to-lua 1.0.0 → 1.2.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 (185) hide show
  1. package/CHANGELOG.md +34 -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 +5 -4
  7. package/dist/LuaPrinter.d.ts +15 -4
  8. package/dist/LuaPrinter.js +79 -27
  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 +39 -19
  22. package/dist/lualib/CloneDescriptor.lua +8 -8
  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 +36 -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 +705 -586
  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 +9 -10
  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 +6 -0
  80. package/dist/transformation/utils/diagnostics.js +7 -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/lua-ast.d.ts +0 -1
  85. package/dist/transformation/utils/lua-ast.js +25 -35
  86. package/dist/transformation/utils/lualib.js +1 -1
  87. package/dist/transformation/utils/preceding-statements.d.ts +3 -0
  88. package/dist/transformation/utils/preceding-statements.js +11 -0
  89. package/dist/transformation/utils/safe-names.js +5 -5
  90. package/dist/transformation/utils/scope.d.ts +7 -0
  91. package/dist/transformation/utils/scope.js +77 -40
  92. package/dist/transformation/utils/symbols.js +6 -6
  93. package/dist/transformation/utils/typescript/index.d.ts +1 -0
  94. package/dist/transformation/utils/typescript/index.js +16 -1
  95. package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
  96. package/dist/transformation/utils/typescript/nodes.js +21 -1
  97. package/dist/transformation/visitors/access.d.ts +3 -0
  98. package/dist/transformation/visitors/access.js +74 -47
  99. package/dist/transformation/visitors/async-await.js +5 -4
  100. package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
  101. package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
  102. package/dist/transformation/visitors/binary-expression/bit.js +4 -4
  103. package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
  104. package/dist/transformation/visitors/binary-expression/compound.js +69 -71
  105. package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
  106. package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
  107. package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
  108. package/dist/transformation/visitors/binary-expression/index.js +84 -40
  109. package/dist/transformation/visitors/block.js +6 -6
  110. package/dist/transformation/visitors/break-continue.js +4 -9
  111. package/dist/transformation/visitors/call.d.ts +3 -2
  112. package/dist/transformation/visitors/call.js +130 -143
  113. package/dist/transformation/visitors/class/decorators.js +3 -3
  114. package/dist/transformation/visitors/class/index.js +43 -39
  115. package/dist/transformation/visitors/class/members/accessors.js +6 -6
  116. package/dist/transformation/visitors/class/members/constructor.js +7 -7
  117. package/dist/transformation/visitors/class/members/fields.js +6 -6
  118. package/dist/transformation/visitors/class/members/method.js +6 -6
  119. package/dist/transformation/visitors/class/new.js +14 -16
  120. package/dist/transformation/visitors/class/setup.js +11 -11
  121. package/dist/transformation/visitors/class/utils.js +2 -2
  122. package/dist/transformation/visitors/conditional.js +34 -20
  123. package/dist/transformation/visitors/delete.js +8 -4
  124. package/dist/transformation/visitors/enum.js +8 -8
  125. package/dist/transformation/visitors/errors.js +30 -30
  126. package/dist/transformation/visitors/expression-list.d.ts +7 -0
  127. package/dist/transformation/visitors/expression-list.js +120 -0
  128. package/dist/transformation/visitors/expression-statement.js +10 -6
  129. package/dist/transformation/visitors/function.js +30 -32
  130. package/dist/transformation/visitors/identifier.js +26 -22
  131. package/dist/transformation/visitors/index.js +2 -2
  132. package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
  133. package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
  134. package/dist/transformation/visitors/language-extensions/multi.js +3 -3
  135. package/dist/transformation/visitors/language-extensions/operators.js +6 -6
  136. package/dist/transformation/visitors/language-extensions/range.js +6 -6
  137. package/dist/transformation/visitors/language-extensions/table.js +5 -5
  138. package/dist/transformation/visitors/literal.d.ts +1 -2
  139. package/dist/transformation/visitors/literal.js +87 -57
  140. package/dist/transformation/visitors/loops/do-while.js +35 -9
  141. package/dist/transformation/visitors/loops/for-in.js +4 -4
  142. package/dist/transformation/visitors/loops/for-of.js +13 -13
  143. package/dist/transformation/visitors/loops/for.js +28 -8
  144. package/dist/transformation/visitors/loops/utils.d.ts +1 -0
  145. package/dist/transformation/visitors/loops/utils.js +21 -10
  146. package/dist/transformation/visitors/modules/export.js +14 -15
  147. package/dist/transformation/visitors/modules/import.js +10 -10
  148. package/dist/transformation/visitors/namespace.js +13 -13
  149. package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
  150. package/dist/transformation/visitors/optional-chaining.js +172 -0
  151. package/dist/transformation/visitors/return.d.ts +1 -0
  152. package/dist/transformation/visitors/return.js +40 -26
  153. package/dist/transformation/visitors/sourceFile.js +12 -9
  154. package/dist/transformation/visitors/spread.js +11 -11
  155. package/dist/transformation/visitors/switch.js +152 -30
  156. package/dist/transformation/visitors/template.js +10 -7
  157. package/dist/transformation/visitors/typeof.js +4 -2
  158. package/dist/transformation/visitors/typescript.js +1 -1
  159. package/dist/transformation/visitors/unary-expression.js +9 -9
  160. package/dist/transformation/visitors/variable-declaration.js +46 -32
  161. package/dist/transformation/visitors/void.d.ts +6 -0
  162. package/dist/transformation/visitors/void.js +20 -0
  163. package/dist/transpilation/bundle.d.ts +3 -0
  164. package/dist/transpilation/bundle.js +56 -13
  165. package/dist/transpilation/diagnostics.js +3 -3
  166. package/dist/transpilation/index.js +2 -2
  167. package/dist/transpilation/output-collector.js +2 -2
  168. package/dist/transpilation/plugins.js +1 -1
  169. package/dist/transpilation/resolve.js +26 -14
  170. package/dist/transpilation/transformers.js +45 -25
  171. package/dist/transpilation/transpile.js +6 -6
  172. package/dist/transpilation/transpiler.js +8 -8
  173. package/dist/transpilation/utils.js +5 -3
  174. package/dist/tstl.js +8 -8
  175. package/dist/utils.js +2 -2
  176. package/package.json +15 -12
  177. package/dist/lualib/OptionalChainAccess.lua +0 -6
  178. package/dist/lualib/OptionalFunctionCall.lua +0 -6
  179. package/dist/lualib/OptionalMethodCall.lua +0 -11
  180. package/dist/transformation/utils/transform.d.ts +0 -8
  181. package/dist/transformation/utils/transform.js +0 -14
  182. package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
  183. package/dist/transformation/visitors/jsx/jsx.js +0 -237
  184. package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
  185. package/dist/transformation/visitors/jsx/xhtml.js +0 -260
@@ -1,7 +1,13 @@
1
1
  function __TS__ObjectDefineProperty(target, key, desc)
2
- local luaKey = (((type(key) == "number") and (function() return key + 1 end)) or (function() return key end))()
2
+ local ____temp_0
3
+ if type(key) == "number" then
4
+ ____temp_0 = key + 1
5
+ else
6
+ ____temp_0 = key
7
+ end
8
+ local luaKey = ____temp_0
3
9
  local value = rawget(target, luaKey)
4
- local hasGetterOrSetter = (desc.get ~= nil) or (desc.set ~= nil)
10
+ local hasGetterOrSetter = desc.get ~= nil or desc.set ~= nil
5
11
  local descriptor
6
12
  if hasGetterOrSetter then
7
13
  if value ~= nil then
@@ -13,13 +19,39 @@ function __TS__ObjectDefineProperty(target, key, desc)
13
19
  descriptor = desc
14
20
  else
15
21
  local valueExists = value ~= nil
22
+ local ____desc_set_5 = desc.set
23
+ local ____desc_get_6 = desc.get
24
+ local ____temp_1
25
+ if desc.configurable ~= nil then
26
+ ____temp_1 = desc.configurable
27
+ else
28
+ ____temp_1 = valueExists
29
+ end
30
+ local ____temp_2
31
+ if desc.enumerable ~= nil then
32
+ ____temp_2 = desc.enumerable
33
+ else
34
+ ____temp_2 = valueExists
35
+ end
36
+ local ____temp_3
37
+ if desc.writable ~= nil then
38
+ ____temp_3 = desc.writable
39
+ else
40
+ ____temp_3 = valueExists
41
+ end
42
+ local ____temp_4
43
+ if desc.value ~= nil then
44
+ ____temp_4 = desc.value
45
+ else
46
+ ____temp_4 = value
47
+ end
16
48
  descriptor = {
17
- set = desc.set,
18
- get = desc.get,
19
- configurable = (((desc.configurable ~= nil) and (function() return desc.configurable end)) or (function() return valueExists end))(),
20
- enumerable = (((desc.enumerable ~= nil) and (function() return desc.enumerable end)) or (function() return valueExists end))(),
21
- writable = (((desc.writable ~= nil) and (function() return desc.writable end)) or (function() return valueExists end))(),
22
- value = (((desc.value ~= nil) and (function() return desc.value end)) or (function() return value end))()
49
+ set = ____desc_set_5,
50
+ get = ____desc_get_6,
51
+ configurable = ____temp_1,
52
+ enumerable = ____temp_2,
53
+ writable = ____temp_3,
54
+ value = ____temp_4
23
55
  }
24
56
  end
25
57
  __TS__SetDescriptor(target, luaKey, descriptor)
@@ -1,10 +1,14 @@
1
1
  function __TS__ParseFloat(numberString)
2
2
  local infinityMatch = string.match(numberString, "^%s*(-?Infinity)")
3
3
  if infinityMatch then
4
- return (((__TS__StringAccess(infinityMatch, 0) == "-") and (function() return -math.huge end)) or (function() return math.huge end))()
4
+ local ____temp_0
5
+ if __TS__StringAccess(infinityMatch, 0) == "-" then
6
+ ____temp_0 = -math.huge
7
+ else
8
+ ____temp_0 = math.huge
9
+ end
10
+ return ____temp_0
5
11
  end
6
- local number = tonumber(
7
- string.match(numberString, "^%s*(-?%d+%.?%d*)")
8
- )
9
- return number or (0 / 0)
12
+ local number = tonumber(string.match(numberString, "^%s*(-?%d+%.?%d*)"))
13
+ return number or 0 / 0
10
14
  end
@@ -5,13 +5,25 @@ function __TS__ParseInt(numberString, base)
5
5
  local hexMatch = string.match(numberString, "^%s*-?0[xX]")
6
6
  if hexMatch then
7
7
  base = 16
8
- numberString = ((string.match(hexMatch, "-") and (function() return "-" .. __TS__StringSubstr(numberString, #hexMatch) end)) or (function() return __TS__StringSubstr(numberString, #hexMatch) end))()
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)
13
+ end
14
+ numberString = ____string_match_result__0_0
9
15
  end
10
16
  end
11
- if (base < 2) or (base > 36) then
17
+ if base < 2 or base > 36 then
12
18
  return 0 / 0
13
19
  end
14
- local allowedDigits = (((base <= 10) and (function() return __TS__StringSubstring(__TS__parseInt_base_pattern, 0, base) end)) or (function() return __TS__StringSubstr(__TS__parseInt_base_pattern, 0, 10 + (2 * (base - 10))) 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
15
27
  local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
16
28
  local number = tonumber(
17
29
  string.match(numberString, pattern),
@@ -28,18 +28,19 @@ function __TS__Promise.prototype.____constructor(self, executor)
28
28
  self.rejectedCallbacks = {}
29
29
  self.finallyCallbacks = {}
30
30
  do
31
- local ____try, e = pcall(
32
- function()
33
- executor(
34
- _G,
35
- __TS__FunctionBind(self.resolve, self),
36
- __TS__FunctionBind(self.reject, self)
37
- )
38
- end
39
- )
40
- if not ____try then
31
+ local function ____catch(e)
41
32
  self:reject(e)
42
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
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
43
+ end
43
44
  end
44
45
  end
45
46
  function __TS__Promise.resolve(data)
@@ -63,14 +64,16 @@ function __TS__Promise.reject(reason)
63
64
  return promise
64
65
  end
65
66
  __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
66
- local ____ = __TS__PromiseDeferred(_G)
67
- local promise = ____.promise
68
- local resolve = ____.resolve
69
- local reject = ____.reject
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
70
73
  if onFulfilled then
71
74
  local internalCallback = self:createPromiseResolvingCallback(onFulfilled, resolve, reject)
72
75
  __TS__ArrayPush(self.fulfilledCallbacks, internalCallback)
73
- if self.state == __TS__PromiseState.Fulfilled then
76
+ if isFulfilled then
74
77
  internalCallback(_G, self.value)
75
78
  end
76
79
  else
@@ -82,10 +85,16 @@ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
82
85
  if onRejected then
83
86
  local internalCallback = self:createPromiseResolvingCallback(onRejected, resolve, reject)
84
87
  __TS__ArrayPush(self.rejectedCallbacks, internalCallback)
85
- if self.state == __TS__PromiseState.Rejected then
88
+ if isRejected then
86
89
  internalCallback(_G, self.rejectionReason)
87
90
  end
88
91
  end
92
+ if isFulfilled then
93
+ resolve(_G, self.value)
94
+ end
95
+ if isRejected then
96
+ reject(_G, self.rejectionReason)
97
+ end
89
98
  return promise
90
99
  end
91
100
  function __TS__Promise.prototype.catch(self, onRejected)
@@ -127,18 +136,19 @@ end
127
136
  function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
128
137
  return function(____, value)
129
138
  do
130
- local ____try, e = pcall(
131
- function()
132
- self:handleCallbackData(
133
- f(_G, value),
134
- resolve,
135
- reject
136
- )
137
- end
138
- )
139
- if not ____try then
139
+ local function ____catch(e)
140
140
  reject(_G, e)
141
141
  end
142
+ local ____try, ____hasReturned = pcall(function()
143
+ self:handleCallbackData(
144
+ f(_G, value),
145
+ resolve,
146
+ reject
147
+ )
148
+ end)
149
+ if not ____try then
150
+ ____hasReturned, ____returnValue = ____catch(____hasReturned)
151
+ end
142
152
  end
143
153
  end
144
154
  end
@@ -1,132 +1,128 @@
1
- Set = (function()
2
- local Set = __TS__Class()
3
- Set.name = "Set"
4
- function Set.prototype.____constructor(self, values)
5
- self[Symbol.toStringTag] = "Set"
6
- self.size = 0
7
- self.nextKey = {}
8
- self.previousKey = {}
9
- if values == nil then
10
- return
11
- end
12
- local iterable = values
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
19
- end
20
- self:add(result.value)
21
- end
22
- else
23
- local array = values
24
- for ____, value in ipairs(array) do
25
- self:add(value)
26
- end
27
- end
1
+ Set = __TS__Class()
2
+ Set.name = "Set"
3
+ function Set.prototype.____constructor(self, values)
4
+ self[Symbol.toStringTag] = "Set"
5
+ self.size = 0
6
+ self.nextKey = {}
7
+ self.previousKey = {}
8
+ if values == nil then
9
+ return
28
10
  end
29
- function Set.prototype.add(self, value)
30
- local isNewValue = not self:has(value)
31
- if isNewValue then
32
- self.size = self.size + 1
33
- end
34
- if self.firstKey == nil then
35
- self.firstKey = value
36
- self.lastKey = value
37
- elseif isNewValue then
38
- self.nextKey[self.lastKey] = value
39
- self.previousKey[value] = self.lastKey
40
- self.lastKey = value
41
- end
42
- return self
43
- end
44
- function Set.prototype.clear(self)
45
- self.nextKey = {}
46
- self.previousKey = {}
47
- self.firstKey = nil
48
- self.lastKey = nil
49
- self.size = 0
50
- end
51
- function Set.prototype.delete(self, value)
52
- local contains = self:has(value)
53
- if contains then
54
- self.size = self.size - 1
55
- local next = self.nextKey[value]
56
- local previous = self.previousKey[value]
57
- if next and previous then
58
- self.nextKey[previous] = next
59
- self.previousKey[next] = previous
60
- elseif next then
61
- self.firstKey = next
62
- self.previousKey[next] = nil
63
- elseif previous then
64
- self.lastKey = previous
65
- self.nextKey[previous] = nil
66
- else
67
- self.firstKey = nil
68
- self.lastKey = nil
11
+ local iterable = values
12
+ if iterable[Symbol.iterator] then
13
+ local iterator = iterable[Symbol.iterator](iterable)
14
+ while true do
15
+ local result = iterator:next()
16
+ if result.done then
17
+ break
69
18
  end
70
- self.nextKey[value] = nil
71
- self.previousKey[value] = nil
19
+ self:add(result.value)
72
20
  end
73
- return contains
74
- end
75
- function Set.prototype.forEach(self, callback)
76
- for ____, key in __TS__Iterator(
77
- self:keys()
78
- ) do
79
- callback(_G, key, key, self)
21
+ else
22
+ local array = values
23
+ for ____, value in ipairs(array) do
24
+ self:add(value)
80
25
  end
81
26
  end
82
- function Set.prototype.has(self, value)
83
- return (self.nextKey[value] ~= nil) or (self.lastKey == value)
27
+ end
28
+ function Set.prototype.add(self, value)
29
+ local isNewValue = not self:has(value)
30
+ if isNewValue then
31
+ self.size = self.size + 1
84
32
  end
85
- Set.prototype[Symbol.iterator] = function(self)
86
- return self:values()
33
+ if self.firstKey == nil then
34
+ self.firstKey = value
35
+ self.lastKey = value
36
+ elseif isNewValue then
37
+ self.nextKey[self.lastKey] = value
38
+ self.previousKey[value] = self.lastKey
39
+ self.lastKey = value
87
40
  end
88
- function Set.prototype.entries(self)
89
- local nextKey = self.nextKey
90
- local key = self.firstKey
91
- return {
92
- [Symbol.iterator] = function(self)
93
- return self
94
- end,
95
- next = function(self)
96
- local result = {done = not key, value = {key, key}}
97
- key = nextKey[key]
98
- return result
99
- end
100
- }
41
+ return self
42
+ end
43
+ function Set.prototype.clear(self)
44
+ self.nextKey = {}
45
+ self.previousKey = {}
46
+ self.firstKey = nil
47
+ self.lastKey = nil
48
+ self.size = 0
49
+ end
50
+ function Set.prototype.delete(self, value)
51
+ local contains = self:has(value)
52
+ if contains then
53
+ self.size = self.size - 1
54
+ local next = self.nextKey[value]
55
+ local previous = self.previousKey[value]
56
+ if next and previous then
57
+ self.nextKey[previous] = next
58
+ self.previousKey[next] = previous
59
+ elseif next then
60
+ self.firstKey = next
61
+ self.previousKey[next] = nil
62
+ elseif previous then
63
+ self.lastKey = previous
64
+ self.nextKey[previous] = nil
65
+ else
66
+ self.firstKey = nil
67
+ self.lastKey = nil
68
+ end
69
+ self.nextKey[value] = nil
70
+ self.previousKey[value] = nil
101
71
  end
102
- function Set.prototype.keys(self)
103
- local nextKey = self.nextKey
104
- local key = self.firstKey
105
- return {
106
- [Symbol.iterator] = function(self)
107
- return self
108
- end,
109
- next = function(self)
110
- local result = {done = not key, value = key}
111
- key = nextKey[key]
112
- return result
113
- end
114
- }
72
+ return contains
73
+ end
74
+ function Set.prototype.forEach(self, callback)
75
+ for ____, key in __TS__Iterator(self:keys()) do
76
+ callback(_G, key, key, self)
115
77
  end
116
- function Set.prototype.values(self)
117
- local nextKey = self.nextKey
118
- local key = self.firstKey
119
- return {
120
- [Symbol.iterator] = function(self)
121
- return self
122
- end,
123
- next = function(self)
124
- local result = {done = not key, value = key}
125
- key = nextKey[key]
126
- return result
127
- end
128
- }
129
- end
130
- Set[Symbol.species] = Set
131
- return Set
132
- end)()
78
+ end
79
+ function Set.prototype.has(self, value)
80
+ return self.nextKey[value] ~= nil or self.lastKey == value
81
+ end
82
+ Set.prototype[Symbol.iterator] = function(self)
83
+ return self:values()
84
+ end
85
+ function Set.prototype.entries(self)
86
+ local nextKey = self.nextKey
87
+ local key = self.firstKey
88
+ return {
89
+ [Symbol.iterator] = function(self)
90
+ return self
91
+ end,
92
+ next = function(self)
93
+ local result = {done = not key, value = {key, key}}
94
+ key = nextKey[key]
95
+ return result
96
+ end
97
+ }
98
+ end
99
+ function Set.prototype.keys(self)
100
+ local nextKey = self.nextKey
101
+ local key = self.firstKey
102
+ return {
103
+ [Symbol.iterator] = function(self)
104
+ return self
105
+ end,
106
+ next = function(self)
107
+ local result = {done = not key, value = key}
108
+ key = nextKey[key]
109
+ return result
110
+ end
111
+ }
112
+ end
113
+ function Set.prototype.values(self)
114
+ local nextKey = self.nextKey
115
+ local key = self.firstKey
116
+ return {
117
+ [Symbol.iterator] = function(self)
118
+ return self
119
+ end,
120
+ next = function(self)
121
+ local result = {done = not key, value = key}
122
+ key = nextKey[key]
123
+ return result
124
+ end
125
+ }
126
+ end
127
+ Set[Symbol.species] = Set
128
+ Set = Set
@@ -51,7 +51,13 @@ function __TS__SetDescriptor(target, key, desc, isPrototype)
51
51
  if isPrototype == nil then
52
52
  isPrototype = false
53
53
  end
54
- local metatable = ((isPrototype and (function() return target end)) or (function() return getmetatable(target) end))()
54
+ local ____isPrototype_0
55
+ if isPrototype then
56
+ ____isPrototype_0 = target
57
+ else
58
+ ____isPrototype_0 = getmetatable(target)
59
+ end
60
+ local metatable = ____isPrototype_0
55
61
  if not metatable then
56
62
  metatable = {}
57
63
  setmetatable(target, metatable)
@@ -5,7 +5,7 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
5
5
  _G.__TS__originalTraceback = debug.traceback
6
6
  debug.traceback = function(thread, message, level)
7
7
  local trace
8
- if ((thread == nil) and (message == nil)) and (level == nil) then
8
+ if thread == nil and message == nil and level == nil then
9
9
  trace = _G.__TS__originalTraceback()
10
10
  else
11
11
  trace = _G.__TS__originalTraceback(thread, message, level)
@@ -13,16 +13,26 @@ function __TS__SourceMapTraceBack(fileName, sourceMap)
13
13
  if type(trace) ~= "string" then
14
14
  return trace
15
15
  end
16
- local result = string.gsub(
17
- trace,
18
- "(%S+).lua:(%d+)",
19
- function(file, line)
20
- local fileSourceMap = _G.__TS__sourcemap[file .. ".lua"]
21
- if fileSourceMap and fileSourceMap[line] then
22
- return (file .. ".ts:") .. tostring(fileSourceMap[line])
16
+ local function replacer(____, file, srcFile, line)
17
+ local fileSourceMap = _G.__TS__sourcemap[file]
18
+ if fileSourceMap and fileSourceMap[line] then
19
+ local data = fileSourceMap[line]
20
+ if type(data) == "number" then
21
+ return (srcFile .. ":") .. tostring(data)
23
22
  end
24
- return (file .. ".lua:") .. line
23
+ return (tostring(data.file) .. ":") .. tostring(data.line)
25
24
  end
25
+ return (file .. ":") .. line
26
+ end
27
+ local result = string.gsub(
28
+ trace,
29
+ "(%S+)%.lua:(%d+)",
30
+ function(file, line) return replacer(_G, file .. ".lua", file .. ".ts", line) end
31
+ )
32
+ result = string.gsub(
33
+ result,
34
+ "(%[string \"[^\"]+\"%]):(%d+)",
35
+ function(file, line) return replacer(_G, file, "unknown", line) end
26
36
  )
27
37
  return result
28
38
  end
@@ -0,0 +1,5 @@
1
+ function __TS__SparseArrayNew(...)
2
+ local sparseArray = {...}
3
+ sparseArray.sparseLength = select("#", ...)
4
+ return sparseArray
5
+ end
@@ -0,0 +1,9 @@
1
+ function __TS__SparseArrayPush(sparseArray, ...)
2
+ local args = {...}
3
+ local argsLen = select("#", ...)
4
+ local listLen = sparseArray.sparseLength
5
+ for i = 1, argsLen do
6
+ sparseArray[listLen + i] = args[i]
7
+ end
8
+ sparseArray.sparseLength = listLen + argsLen
9
+ end
@@ -0,0 +1,4 @@
1
+ function __TS__SparseArraySpread(sparseArray)
2
+ local _unpack = unpack or table.unpack
3
+ return _unpack(sparseArray, 1, sparseArray.sparseLength)
4
+ end
@@ -1,5 +1,5 @@
1
1
  function __TS__StringAccess(self, index)
2
- if (index >= 0) and (index < #self) then
2
+ if index >= 0 and index < #self then
3
3
  return string.sub(self, index + 1, index + 1)
4
4
  end
5
5
  end
@@ -5,5 +5,5 @@ function __TS__StringCharCodeAt(self, index)
5
5
  if index < 0 then
6
6
  return 0 / 0
7
7
  end
8
- return string.byte(self, index + 1) or (0 / 0)
8
+ return string.byte(self, index + 1) or 0 / 0
9
9
  end
@@ -1,6 +1,6 @@
1
1
  function __TS__StringEndsWith(self, searchString, endPosition)
2
- if (endPosition == nil) or (endPosition > #self) then
2
+ if endPosition == nil or endPosition > #self then
3
3
  endPosition = #self
4
4
  end
5
- return string.sub(self, (endPosition - #searchString) + 1, endPosition) == searchString
5
+ return string.sub(self, endPosition - #searchString + 1, endPosition) == searchString
6
6
  end
@@ -5,10 +5,10 @@ function __TS__StringPadEnd(self, maxLength, fillString)
5
5
  if maxLength ~= maxLength then
6
6
  maxLength = 0
7
7
  end
8
- if (maxLength == -math.huge) or (maxLength == math.huge) then
8
+ if maxLength == -math.huge or maxLength == math.huge then
9
9
  error("Invalid string length", 0)
10
10
  end
11
- if (#self >= maxLength) or (#fillString == 0) then
11
+ if #self >= maxLength or #fillString == 0 then
12
12
  return self
13
13
  end
14
14
  maxLength = maxLength - #self
@@ -5,10 +5,10 @@ function __TS__StringPadStart(self, maxLength, fillString)
5
5
  if maxLength ~= maxLength then
6
6
  maxLength = 0
7
7
  end
8
- if (maxLength == -math.huge) or (maxLength == math.huge) then
8
+ if maxLength == -math.huge or maxLength == math.huge then
9
9
  error("Invalid string length", 0)
10
10
  end
11
- if (#self >= maxLength) or (#fillString == 0) then
11
+ if #self >= maxLength or #fillString == 0 then
12
12
  return self
13
13
  end
14
14
  maxLength = maxLength - #self
@@ -1,16 +1,17 @@
1
1
  function __TS__StringReplace(source, searchValue, replaceValue)
2
- searchValue = string.gsub(searchValue, "[%%%(%)%.%+%-%*%?%[%^%$]", "%%%1")
2
+ local startPos, endPos = string.find(source, searchValue, nil, true)
3
+ if not startPos then
4
+ return source
5
+ end
6
+ local sub = string.sub
7
+ local before = sub(source, 1, startPos - 1)
8
+ local ____temp_0
3
9
  if type(replaceValue) == "string" then
4
- replaceValue = string.gsub(replaceValue, "%%", "%%%%")
5
- local result = string.gsub(source, searchValue, replaceValue, 1)
6
- return result
10
+ ____temp_0 = replaceValue
7
11
  else
8
- local result = string.gsub(
9
- source,
10
- searchValue,
11
- function(match) return replaceValue(_G, match) end,
12
- 1
13
- )
14
- return result
12
+ ____temp_0 = replaceValue(_G, searchValue, startPos - 1, source)
15
13
  end
14
+ local replacement = ____temp_0
15
+ local after = sub(source, endPos + 1)
16
+ return (before .. replacement) .. after
16
17
  end
@@ -0,0 +1,35 @@
1
+ function __TS__StringReplaceAll(source, searchValue, replaceValue)
2
+ local replacer
3
+ if type(replaceValue) == "string" then
4
+ replacer = function() return replaceValue end
5
+ else
6
+ replacer = replaceValue
7
+ end
8
+ local parts = {}
9
+ local partsIndex = 1
10
+ local sub = string.sub
11
+ if #searchValue == 0 then
12
+ parts[1] = replacer(_G, "", 0, source)
13
+ partsIndex = 2
14
+ for i = 1, #source do
15
+ parts[partsIndex] = sub(source, i, i)
16
+ parts[partsIndex + 1] = replacer(_G, "", i, source)
17
+ partsIndex = partsIndex + 2
18
+ end
19
+ else
20
+ local find = string.find
21
+ local currentPos = 1
22
+ while true do
23
+ local startPos, endPos = find(source, searchValue, currentPos, true)
24
+ if not startPos then
25
+ break
26
+ end
27
+ parts[partsIndex] = sub(source, currentPos, startPos - 1)
28
+ parts[partsIndex + 1] = replacer(_G, searchValue, startPos - 1, source)
29
+ partsIndex = partsIndex + 2
30
+ currentPos = endPos + 1
31
+ end
32
+ parts[partsIndex] = sub(source, currentPos)
33
+ end
34
+ return table.concat(parts)
35
+ end