typescript-to-lua 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -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 +6 -5
- package/dist/LuaPrinter.d.ts +15 -4
- package/dist/LuaPrinter.js +81 -29
- 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 +43 -19
- package/dist/lualib/CloneDescriptor.lua +7 -7
- 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 +44 -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 +876 -745
- package/dist/transformation/builtins/array.js +29 -30
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +14 -12
- 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 +9 -0
- package/dist/transformation/utils/diagnostics.js +8 -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/language-extensions.d.ts +2 -0
- package/dist/transformation/utils/language-extensions.js +7 -1
- 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.d.ts +4 -2
- package/dist/transformation/utils/safe-names.js +13 -7
- package/dist/transformation/utils/scope.d.ts +9 -1
- package/dist/transformation/utils/scope.js +78 -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/utils/typescript/types.d.ts +3 -1
- package/dist/transformation/utils/typescript/types.js +40 -13
- 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 -42
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +2 -2
- 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 +36 -43
- package/dist/transformation/visitors/delete.js +8 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +35 -33
- 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.d.ts +2 -0
- package/dist/transformation/visitors/function.js +80 -33
- 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/pairsIterable.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +53 -0
- 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 +17 -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 +26 -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 +23 -16
- package/dist/transformation/visitors/switch.js +63 -20
- 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 +55 -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 +52 -10
- 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 +20 -13
- 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/language-extensions/index.d.ts +11 -1
- 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
|
@@ -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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function __TS__StringSlice(self, start, ____end)
|
|
2
|
-
if
|
|
2
|
+
if start == nil or start ~= start then
|
|
3
3
|
start = 0
|
|
4
4
|
end
|
|
5
5
|
if ____end ~= ____end then
|
|
@@ -8,7 +8,7 @@ function __TS__StringSlice(self, start, ____end)
|
|
|
8
8
|
if start >= 0 then
|
|
9
9
|
start = start + 1
|
|
10
10
|
end
|
|
11
|
-
if
|
|
11
|
+
if ____end ~= nil and ____end < 0 then
|
|
12
12
|
____end = ____end - 1
|
|
13
13
|
end
|
|
14
14
|
return string.sub(self, start, ____end)
|
|
@@ -8,8 +8,8 @@ function __TS__StringSplit(source, separator, limit)
|
|
|
8
8
|
local out = {}
|
|
9
9
|
local index = 0
|
|
10
10
|
local count = 0
|
|
11
|
-
if
|
|
12
|
-
while
|
|
11
|
+
if separator == nil or separator == "" then
|
|
12
|
+
while index < #source - 1 and count < limit do
|
|
13
13
|
out[count + 1] = __TS__StringAccess(source, index)
|
|
14
14
|
count = count + 1
|
|
15
15
|
index = index + 1
|
|
@@ -17,7 +17,7 @@ function __TS__StringSplit(source, separator, limit)
|
|
|
17
17
|
else
|
|
18
18
|
local separatorLength = #separator
|
|
19
19
|
local nextIndex = (string.find(source, separator, nil, true) or 0) - 1
|
|
20
|
-
while
|
|
20
|
+
while nextIndex >= 0 and count < limit do
|
|
21
21
|
out[count + 1] = __TS__StringSubstring(source, index, nextIndex)
|
|
22
22
|
count = count + 1
|
|
23
23
|
index = nextIndex + separatorLength
|
|
@@ -2,7 +2,7 @@ function __TS__StringSubstring(self, start, ____end)
|
|
|
2
2
|
if ____end ~= ____end then
|
|
3
3
|
____end = 0
|
|
4
4
|
end
|
|
5
|
-
if
|
|
5
|
+
if ____end ~= nil and start > ____end then
|
|
6
6
|
start, ____end = ____end, start
|
|
7
7
|
end
|
|
8
8
|
if start >= 0 then
|
|
@@ -10,7 +10,7 @@ function __TS__StringSubstring(self, start, ____end)
|
|
|
10
10
|
else
|
|
11
11
|
start = 1
|
|
12
12
|
end
|
|
13
|
-
if
|
|
13
|
+
if ____end ~= nil and ____end < 0 then
|
|
14
14
|
____end = 0
|
|
15
15
|
end
|
|
16
16
|
return string.sub(self, start, ____end)
|
package/dist/lualib/Symbol.lua
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
____symbolMetatable = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
end
|
|
5
|
-
}
|
|
1
|
+
____symbolMetatable = {__tostring = function(self)
|
|
2
|
+
return ("Symbol(" .. (self.description or "")) .. ")"
|
|
3
|
+
end}
|
|
6
4
|
function __TS__Symbol(description)
|
|
7
5
|
return setmetatable({description = description}, ____symbolMetatable)
|
|
8
6
|
end
|
package/dist/lualib/WeakMap.lua
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
|
-
WeakMap = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
break
|
|
18
|
-
end
|
|
19
|
-
local value = result.value
|
|
20
|
-
self.items[value[1]] = value[2]
|
|
21
|
-
end
|
|
22
|
-
else
|
|
23
|
-
for ____, kvp in ipairs(entries) do
|
|
24
|
-
self.items[kvp[1]] = kvp[2]
|
|
1
|
+
WeakMap = __TS__Class()
|
|
2
|
+
WeakMap.name = "WeakMap"
|
|
3
|
+
function WeakMap.prototype.____constructor(self, entries)
|
|
4
|
+
self[Symbol.toStringTag] = "WeakMap"
|
|
5
|
+
self.items = {}
|
|
6
|
+
setmetatable(self.items, {__mode = "k"})
|
|
7
|
+
if entries == nil then
|
|
8
|
+
return
|
|
9
|
+
end
|
|
10
|
+
local iterable = entries
|
|
11
|
+
if iterable[Symbol.iterator] then
|
|
12
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
13
|
+
while true do
|
|
14
|
+
local result = iterator:next()
|
|
15
|
+
if result.done then
|
|
16
|
+
break
|
|
25
17
|
end
|
|
18
|
+
local value = result.value
|
|
19
|
+
self.items[value[1]] = value[2]
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
for ____, kvp in ipairs(entries) do
|
|
23
|
+
self.items[kvp[1]] = kvp[2]
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
end
|
|
27
|
+
function WeakMap.prototype.delete(self, key)
|
|
28
|
+
local contains = self:has(key)
|
|
29
|
+
self.items[key] = nil
|
|
30
|
+
return contains
|
|
31
|
+
end
|
|
32
|
+
function WeakMap.prototype.get(self, key)
|
|
33
|
+
return self.items[key]
|
|
34
|
+
end
|
|
35
|
+
function WeakMap.prototype.has(self, key)
|
|
36
|
+
return self.items[key] ~= nil
|
|
37
|
+
end
|
|
38
|
+
function WeakMap.prototype.set(self, key, value)
|
|
39
|
+
self.items[key] = value
|
|
40
|
+
return self
|
|
41
|
+
end
|
|
42
|
+
WeakMap[Symbol.species] = WeakMap
|
|
43
|
+
WeakMap = WeakMap
|
package/dist/lualib/WeakSet.lua
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
WeakSet = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
break
|
|
18
|
-
end
|
|
19
|
-
self.items[result.value] = true
|
|
20
|
-
end
|
|
21
|
-
else
|
|
22
|
-
for ____, value in ipairs(values) do
|
|
23
|
-
self.items[value] = true
|
|
1
|
+
WeakSet = __TS__Class()
|
|
2
|
+
WeakSet.name = "WeakSet"
|
|
3
|
+
function WeakSet.prototype.____constructor(self, values)
|
|
4
|
+
self[Symbol.toStringTag] = "WeakSet"
|
|
5
|
+
self.items = {}
|
|
6
|
+
setmetatable(self.items, {__mode = "k"})
|
|
7
|
+
if values == nil then
|
|
8
|
+
return
|
|
9
|
+
end
|
|
10
|
+
local iterable = values
|
|
11
|
+
if iterable[Symbol.iterator] then
|
|
12
|
+
local iterator = iterable[Symbol.iterator](iterable)
|
|
13
|
+
while true do
|
|
14
|
+
local result = iterator:next()
|
|
15
|
+
if result.done then
|
|
16
|
+
break
|
|
24
17
|
end
|
|
18
|
+
self.items[result.value] = true
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
for ____, value in ipairs(values) do
|
|
22
|
+
self.items[value] = true
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
end
|
|
26
|
+
function WeakSet.prototype.add(self, value)
|
|
27
|
+
self.items[value] = true
|
|
28
|
+
return self
|
|
29
|
+
end
|
|
30
|
+
function WeakSet.prototype.delete(self, value)
|
|
31
|
+
local contains = self:has(value)
|
|
32
|
+
self.items[value] = nil
|
|
33
|
+
return contains
|
|
34
|
+
end
|
|
35
|
+
function WeakSet.prototype.has(self, value)
|
|
36
|
+
return self.items[value] == true
|
|
37
|
+
end
|
|
38
|
+
WeakSet[Symbol.species] = WeakSet
|
|
39
|
+
WeakSet = WeakSet
|