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
|
@@ -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 <
|
|
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 >
|
|
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 =
|
|
61
|
-
local to =
|
|
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 >=
|
|
78
|
+
while k >= len - actualDeleteCount + itemCount do
|
|
79
79
|
list[k + 1] = nil
|
|
80
80
|
k = k - 1
|
|
81
81
|
end
|
package/dist/lualib/Await.lua
CHANGED
|
@@ -2,42 +2,62 @@ function __TS__AsyncAwaiter(generator)
|
|
|
2
2
|
return __TS__New(
|
|
3
3
|
__TS__Promise,
|
|
4
4
|
function(____, resolve, reject)
|
|
5
|
-
local
|
|
5
|
+
local adopt, fulfilled, rejected, step, asyncCoroutine
|
|
6
6
|
function adopt(self, value)
|
|
7
|
-
|
|
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, valueOrError = pcall(handler, value)
|
|
27
|
+
if success then
|
|
28
|
+
step(_G, valueOrError, handler)
|
|
29
|
+
else
|
|
30
|
+
reject(_G, valueOrError)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
13
33
|
else
|
|
14
|
-
|
|
34
|
+
return function(____, value)
|
|
35
|
+
reject(_G, value)
|
|
36
|
+
end
|
|
15
37
|
end
|
|
16
38
|
end
|
|
17
|
-
function step(self, result)
|
|
39
|
+
function step(self, result, errorHandler)
|
|
18
40
|
if coroutine.status(asyncCoroutine) == "dead" then
|
|
19
41
|
resolve(_G, result)
|
|
20
42
|
else
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
end)()
|
|
43
|
+
local ____self_1 = adopt(_G, result)
|
|
44
|
+
____self_1["then"](
|
|
45
|
+
____self_1,
|
|
46
|
+
fulfilled,
|
|
47
|
+
rejected(_G, errorHandler)
|
|
48
|
+
)
|
|
29
49
|
end
|
|
30
50
|
end
|
|
31
51
|
asyncCoroutine = coroutine.create(generator)
|
|
32
|
-
local success, resultOrError = coroutine.resume(asyncCoroutine)
|
|
52
|
+
local success, errorOrErrorHandler, resultOrError = coroutine.resume(asyncCoroutine)
|
|
33
53
|
if success then
|
|
34
|
-
step(_G, resultOrError)
|
|
54
|
+
step(_G, resultOrError, errorOrErrorHandler)
|
|
35
55
|
else
|
|
36
|
-
reject(_G,
|
|
56
|
+
reject(_G, errorOrErrorHandler)
|
|
37
57
|
end
|
|
38
58
|
end
|
|
39
59
|
)
|
|
40
60
|
end
|
|
41
|
-
function __TS__Await(thing)
|
|
42
|
-
return coroutine.yield(thing)
|
|
61
|
+
function __TS__Await(errorHandler, thing)
|
|
62
|
+
return coroutine.yield(errorHandler, thing)
|
|
43
63
|
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
local value
|
|
2
|
+
local writable
|
|
3
|
+
local set
|
|
4
|
+
local get
|
|
5
|
+
local configurable
|
|
6
|
+
local enumerable
|
|
1
7
|
function __TS__CloneDescriptor(____bindingPattern0)
|
|
2
|
-
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 =
|
|
16
|
-
local hasValueOrWritableAttribute =
|
|
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
|
package/dist/lualib/Decorate.lua
CHANGED
|
@@ -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 =
|
|
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
|
package/dist/lualib/Delete.lua
CHANGED
|
@@ -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
|
-
(
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
return true
|
|
17
|
-
end
|
|
18
|
-
return false
|
|
17
|
+
target[key] = nil
|
|
18
|
+
return true
|
|
19
19
|
end
|
package/dist/lualib/Error.lua
CHANGED
|
@@ -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
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
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
|
package/dist/lualib/Map.lua
CHANGED
|
@@ -1,144 +1,140 @@
|
|
|
1
|
-
Map = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
59
|
-
self
|
|
20
|
+
local value = result.value
|
|
21
|
+
self:set(value[1], value[2])
|
|
60
22
|
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
self.nextKey[
|
|
88
|
-
self.previousKey[
|
|
89
|
-
|
|
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
|
-
|
|
57
|
+
self.nextKey[key] = nil
|
|
58
|
+
self.previousKey[key] = nil
|
|
92
59
|
end
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
package/dist/lualib/Number.lua
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
____radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
2
2
|
function __TS__NumberToString(self, radix)
|
|
3
|
-
if
|
|
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
|
|
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)
|