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.
- package/CHANGELOG.md +34 -0
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.d.ts +1 -0
- package/dist/LuaAST.js +14 -6
- package/dist/LuaLib.d.ts +4 -3
- package/dist/LuaLib.js +5 -4
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +79 -27
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +7 -1
- package/dist/lualib/ArrayReduceRight.lua +7 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArraySplice.lua +5 -5
- package/dist/lualib/Await.lua +39 -19
- package/dist/lualib/CloneDescriptor.lua +8 -8
- package/dist/lualib/Decorate.lua +1 -1
- package/dist/lualib/DelegatedYield.lua +1 -3
- package/dist/lualib/Delete.lua +6 -6
- package/dist/lualib/Error.lua +47 -44
- package/dist/lualib/Generator.lua +1 -5
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Map.lua +130 -134
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberToString.lua +3 -5
- package/dist/lualib/ObjectDefineProperty.lua +40 -8
- package/dist/lualib/ParseFloat.lua +9 -5
- package/dist/lualib/ParseInt.lua +15 -3
- package/dist/lualib/Promise.lua +36 -26
- package/dist/lualib/Set.lua +119 -123
- package/dist/lualib/SetDescriptor.lua +7 -1
- package/dist/lualib/SourceMapTraceBack.lua +19 -9
- package/dist/lualib/SparseArrayNew.lua +5 -0
- package/dist/lualib/SparseArrayPush.lua +9 -0
- package/dist/lualib/SparseArraySpread.lua +4 -0
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +2 -2
- package/dist/lualib/StringPadEnd.lua +2 -2
- package/dist/lualib/StringPadStart.lua +2 -2
- package/dist/lualib/StringReplace.lua +12 -11
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/StringSlice.lua +2 -2
- package/dist/lualib/StringSplit.lua +3 -3
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +2 -2
- package/dist/lualib/Symbol.lua +3 -5
- package/dist/lualib/WeakMap.lua +40 -42
- package/dist/lualib/WeakSet.lua +36 -38
- package/dist/lualib/lualib_bundle.lua +705 -586
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -10
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.d.ts +1 -1
- package/dist/transformation/builtins/index.js +69 -36
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.d.ts +2 -1
- package/dist/transformation/builtins/object.js +12 -13
- package/dist/transformation/builtins/promise.js +9 -9
- package/dist/transformation/builtins/string.js +32 -31
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.d.ts +12 -0
- package/dist/transformation/context/context.js +105 -6
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -3
- package/dist/transformation/utils/annotations.js +0 -2
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +6 -0
- package/dist/transformation/utils/diagnostics.js +7 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +8 -8
- package/dist/transformation/utils/lua-ast.d.ts +0 -1
- package/dist/transformation/utils/lua-ast.js +25 -35
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/preceding-statements.d.ts +3 -0
- package/dist/transformation/utils/preceding-statements.js +11 -0
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +7 -0
- package/dist/transformation/utils/scope.js +77 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +16 -1
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.d.ts +3 -0
- package/dist/transformation/visitors/access.js +74 -47
- package/dist/transformation/visitors/async-await.js +5 -4
- package/dist/transformation/visitors/binary-expression/assignments.d.ts +3 -2
- package/dist/transformation/visitors/binary-expression/assignments.js +86 -77
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.d.ts +5 -4
- package/dist/transformation/visitors/binary-expression/compound.js +69 -71
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.d.ts +2 -2
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +65 -36
- package/dist/transformation/visitors/binary-expression/index.d.ts +3 -1
- package/dist/transformation/visitors/binary-expression/index.js +84 -40
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.d.ts +3 -2
- package/dist/transformation/visitors/call.js +130 -143
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +43 -39
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +14 -16
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +34 -20
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -30
- package/dist/transformation/visitors/expression-list.d.ts +7 -0
- package/dist/transformation/visitors/expression-list.js +120 -0
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +30 -32
- package/dist/transformation/visitors/identifier.js +26 -22
- package/dist/transformation/visitors/index.js +2 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +3 -3
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +87 -57
- package/dist/transformation/visitors/loops/do-while.js +35 -9
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +28 -8
- package/dist/transformation/visitors/loops/utils.d.ts +1 -0
- package/dist/transformation/visitors/loops/utils.js +21 -10
- package/dist/transformation/visitors/modules/export.js +14 -15
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/optional-chaining.d.ts +16 -0
- package/dist/transformation/visitors/optional-chaining.js +172 -0
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +40 -26
- package/dist/transformation/visitors/sourceFile.js +12 -9
- package/dist/transformation/visitors/spread.js +11 -11
- package/dist/transformation/visitors/switch.js +152 -30
- package/dist/transformation/visitors/template.js +10 -7
- package/dist/transformation/visitors/typeof.js +4 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +46 -32
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +20 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +26 -14
- package/dist/transpilation/transformers.js +45 -25
- package/dist/transpilation/transpile.js +6 -6
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +5 -3
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/lualib/OptionalChainAccess.lua +0 -6
- package/dist/lualib/OptionalFunctionCall.lua +0 -6
- package/dist/lualib/OptionalMethodCall.lua +0 -11
- package/dist/transformation/utils/transform.d.ts +0 -8
- package/dist/transformation/utils/transform.js +0 -14
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
function __TS__ObjectDefineProperty(target, key, desc)
|
|
2
|
-
local
|
|
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 =
|
|
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 =
|
|
18
|
-
get =
|
|
19
|
-
configurable =
|
|
20
|
-
enumerable =
|
|
21
|
-
writable =
|
|
22
|
-
value =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/dist/lualib/ParseInt.lua
CHANGED
|
@@ -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
|
-
|
|
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
|
|
17
|
+
if base < 2 or base > 36 then
|
|
12
18
|
return 0 / 0
|
|
13
19
|
end
|
|
14
|
-
local
|
|
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),
|
package/dist/lualib/Promise.lua
CHANGED
|
@@ -28,18 +28,19 @@ function __TS__Promise.prototype.____constructor(self, executor)
|
|
|
28
28
|
self.rejectedCallbacks = {}
|
|
29
29
|
self.finallyCallbacks = {}
|
|
30
30
|
do
|
|
31
|
-
local
|
|
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
|
|
67
|
-
local promise =
|
|
68
|
-
local resolve =
|
|
69
|
-
local 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
|
|
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
|
|
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
|
|
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
|
package/dist/lualib/Set.lua
CHANGED
|
@@ -1,132 +1,128 @@
|
|
|
1
|
-
Set = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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.
|
|
71
|
-
self.previousKey[value] = nil
|
|
19
|
+
self:add(result.value)
|
|
72
20
|
end
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
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
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 .. "
|
|
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,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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function __TS__StringEndsWith(self, searchString, endPosition)
|
|
2
|
-
if
|
|
2
|
+
if endPosition == nil or endPosition > #self then
|
|
3
3
|
endPosition = #self
|
|
4
4
|
end
|
|
5
|
-
return string.sub(self,
|
|
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
|
|
8
|
+
if maxLength == -math.huge or maxLength == math.huge then
|
|
9
9
|
error("Invalid string length", 0)
|
|
10
10
|
end
|
|
11
|
-
if
|
|
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
|
|
8
|
+
if maxLength == -math.huge or maxLength == math.huge then
|
|
9
9
|
error("Invalid string length", 0)
|
|
10
10
|
end
|
|
11
|
-
if
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
local result = string.gsub(source, searchValue, replaceValue, 1)
|
|
6
|
-
return result
|
|
10
|
+
____temp_0 = replaceValue
|
|
7
11
|
else
|
|
8
|
-
|
|
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
|