typescript-to-lua 1.12.1 → 1.13.1
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/dist/lualib/5.0/Await.lua +5 -11
- package/dist/lualib/5.0/Decorate.lua +1 -1
- package/dist/lualib/5.0/Error.lua +12 -18
- package/dist/lualib/5.0/Map.lua +3 -3
- package/dist/lualib/5.0/MathModf.lua +1 -7
- package/dist/lualib/5.0/ObjectDefineProperty.lua +21 -27
- package/dist/lualib/5.0/ParseFloat.lua +2 -8
- package/dist/lualib/5.0/ParseInt.lua +9 -21
- package/dist/lualib/5.0/Set.lua +3 -3
- package/dist/lualib/5.0/SetDescriptor.lua +2 -2
- package/dist/lualib/5.0/SourceMapTraceBack.lua +4 -4
- package/dist/lualib/5.0/StringReplace.lua +1 -7
- package/dist/lualib/5.0/SymbolRegistry.lua +1 -0
- package/dist/lualib/5.0/lualib_bundle.lua +65 -112
- package/dist/lualib/universal/Await.lua +5 -11
- package/dist/lualib/universal/Decorate.lua +1 -1
- package/dist/lualib/universal/Error.lua +12 -18
- package/dist/lualib/universal/Map.lua +3 -3
- package/dist/lualib/universal/ObjectDefineProperty.lua +21 -27
- package/dist/lualib/universal/ParseFloat.lua +2 -8
- package/dist/lualib/universal/ParseInt.lua +3 -15
- package/dist/lualib/universal/Set.lua +3 -3
- package/dist/lualib/universal/SetDescriptor.lua +2 -2
- package/dist/lualib/universal/SourceMapTraceBack.lua +5 -5
- package/dist/lualib/universal/StringReplace.lua +1 -7
- package/dist/lualib/universal/SymbolRegistry.lua +1 -0
- package/dist/lualib/universal/lualib_bundle.lua +59 -100
- package/dist/transformation/utils/preceding-statements.d.ts +5 -1
- package/dist/transformation/utils/preceding-statements.js +1 -1
- package/dist/transformation/visitors/binary-expression/assignments.js +3 -3
- package/dist/transformation/visitors/binary-expression/compound.d.ts +0 -7
- package/dist/transformation/visitors/binary-expression/compound.js +40 -22
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +5 -5
- package/dist/transformation/visitors/binary-expression/index.d.ts +3 -2
- package/dist/transformation/visitors/binary-expression/index.js +12 -13
- package/dist/transformation/visitors/call.js +2 -2
- package/dist/transformation/visitors/class/index.js +1 -1
- package/dist/transformation/visitors/class/members/fields.js +1 -1
- package/dist/transformation/visitors/conditional.js +10 -10
- package/dist/transformation/visitors/expression-list.js +1 -1
- package/dist/transformation/visitors/function.js +2 -2
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for.js +2 -2
- package/dist/transformation/visitors/loops/utils.js +1 -1
- package/dist/transformation/visitors/optional-chaining.js +2 -2
- package/dist/transformation/visitors/sourceFile.js +1 -1
- package/dist/transformation/visitors/switch.js +15 -6
- package/dist/transformation/visitors/typeof.js +1 -1
- package/dist/transformation/visitors/variable-declaration.js +3 -3
- package/dist/transpilation/output-collector.d.ts +1 -1
- package/dist/transpilation/output-collector.js +3 -3
- package/dist/transpilation/resolve.js +22 -10
- package/package.json +7 -7
|
@@ -9,7 +9,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
9
9
|
if thread == nil and message == nil and level == nil then
|
|
10
10
|
trace = originalTraceback()
|
|
11
11
|
elseif __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
|
12
|
-
trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. message)
|
|
12
|
+
trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. tostring(message))
|
|
13
13
|
else
|
|
14
14
|
trace = originalTraceback(thread, message, level)
|
|
15
15
|
end
|
|
@@ -18,12 +18,12 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
18
18
|
end
|
|
19
19
|
local function replacer(____, file, srcFile, line)
|
|
20
20
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
21
|
-
if fileSourceMap and fileSourceMap[line] then
|
|
21
|
+
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
22
22
|
local data = fileSourceMap[line]
|
|
23
23
|
if type(data) == "number" then
|
|
24
24
|
return (srcFile .. ":") .. tostring(data)
|
|
25
25
|
end
|
|
26
|
-
return (
|
|
26
|
+
return (data.file .. ":") .. tostring(data.line)
|
|
27
27
|
end
|
|
28
28
|
return (file .. ":") .. line
|
|
29
29
|
end
|
|
@@ -34,14 +34,14 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
34
34
|
)
|
|
35
35
|
local function stringReplacer(____, file, line)
|
|
36
36
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
37
|
-
if fileSourceMap and fileSourceMap[line] then
|
|
37
|
+
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
38
38
|
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
39
39
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
40
40
|
local data = fileSourceMap[line]
|
|
41
41
|
if type(data) == "number" then
|
|
42
42
|
return (sourceName .. ":") .. tostring(data)
|
|
43
43
|
end
|
|
44
|
-
return (
|
|
44
|
+
return (data.file .. ":") .. tostring(data.line)
|
|
45
45
|
end
|
|
46
46
|
return (file .. ":") .. line
|
|
47
47
|
end
|
|
@@ -7,13 +7,7 @@ do
|
|
|
7
7
|
return source
|
|
8
8
|
end
|
|
9
9
|
local before = sub(source, 1, startPos - 1)
|
|
10
|
-
local
|
|
11
|
-
if type(replaceValue) == "string" then
|
|
12
|
-
____temp_0 = replaceValue
|
|
13
|
-
else
|
|
14
|
-
____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
|
|
15
|
-
end
|
|
16
|
-
local replacement = ____temp_0
|
|
10
|
+
local replacement = type(replaceValue) == "string" and replaceValue or replaceValue(nil, searchValue, startPos - 1, source)
|
|
17
11
|
local after = sub(source, endPos + 1)
|
|
18
12
|
return (before .. replacement) .. after
|
|
19
13
|
end
|
|
@@ -762,13 +762,7 @@ local function __TS__AsyncAwaiter(generator)
|
|
|
762
762
|
function(____, resolve, reject)
|
|
763
763
|
local adopt, fulfilled, step, resolved, asyncCoroutine
|
|
764
764
|
function adopt(self, value)
|
|
765
|
-
|
|
766
|
-
if __TS__InstanceOf(value, __TS__Promise) then
|
|
767
|
-
____temp_0 = value
|
|
768
|
-
else
|
|
769
|
-
____temp_0 = __TS__Promise.resolve(value)
|
|
770
|
-
end
|
|
771
|
-
return ____temp_0
|
|
765
|
+
return __TS__InstanceOf(value, __TS__Promise) and value or __TS__Promise.resolve(value)
|
|
772
766
|
end
|
|
773
767
|
function fulfilled(self, value)
|
|
774
768
|
local success, resultOrError = coroutine.resume(asyncCoroutine, value)
|
|
@@ -785,8 +779,8 @@ local function __TS__AsyncAwaiter(generator)
|
|
|
785
779
|
if coroutine.status(asyncCoroutine) == "dead" then
|
|
786
780
|
resolve(nil, result)
|
|
787
781
|
else
|
|
788
|
-
local
|
|
789
|
-
|
|
782
|
+
local ____self_0 = adopt(nil, result)
|
|
783
|
+
____self_0["then"](____self_0, fulfilled, reject)
|
|
790
784
|
end
|
|
791
785
|
end
|
|
792
786
|
resolved = false
|
|
@@ -795,8 +789,8 @@ local function __TS__AsyncAwaiter(generator)
|
|
|
795
789
|
asyncCoroutine,
|
|
796
790
|
function(____, v)
|
|
797
791
|
resolved = true
|
|
798
|
-
local
|
|
799
|
-
|
|
792
|
+
local ____self_1 = adopt(nil, v)
|
|
793
|
+
____self_1["then"](____self_1, resolve, reject)
|
|
800
794
|
end
|
|
801
795
|
)
|
|
802
796
|
if success then
|
|
@@ -903,7 +897,7 @@ do
|
|
|
903
897
|
local descriptors = rawget(metatable, "_descriptors")
|
|
904
898
|
if descriptors then
|
|
905
899
|
local descriptor = descriptors[key]
|
|
906
|
-
if descriptor then
|
|
900
|
+
if descriptor ~= nil then
|
|
907
901
|
if descriptor.get then
|
|
908
902
|
return descriptor.get(self)
|
|
909
903
|
end
|
|
@@ -919,7 +913,7 @@ do
|
|
|
919
913
|
local descriptors = rawget(metatable, "_descriptors")
|
|
920
914
|
if descriptors then
|
|
921
915
|
local descriptor = descriptors[key]
|
|
922
|
-
if descriptor then
|
|
916
|
+
if descriptor ~= nil then
|
|
923
917
|
if descriptor.set then
|
|
924
918
|
descriptor.set(self, value)
|
|
925
919
|
else
|
|
@@ -972,7 +966,7 @@ local function __TS__Decorate(decorators, target, key, desc)
|
|
|
972
966
|
local i = #decorators
|
|
973
967
|
while i >= 0 do
|
|
974
968
|
local decorator = decorators[i + 1]
|
|
975
|
-
if decorator then
|
|
969
|
+
if decorator ~= nil then
|
|
976
970
|
local oldResult = result
|
|
977
971
|
if key == nil then
|
|
978
972
|
result = decorator(nil, result)
|
|
@@ -1045,7 +1039,7 @@ do
|
|
|
1045
1039
|
if isClassicLua or caller and caller.func ~= error then
|
|
1046
1040
|
return description
|
|
1047
1041
|
else
|
|
1048
|
-
return (
|
|
1042
|
+
return (description .. "\n") .. tostring(self.stack)
|
|
1049
1043
|
end
|
|
1050
1044
|
end
|
|
1051
1045
|
end
|
|
@@ -1056,7 +1050,7 @@ do
|
|
|
1056
1050
|
{__call = function(____, _self, message) return __TS__New(Type, message) end}
|
|
1057
1051
|
)
|
|
1058
1052
|
end
|
|
1059
|
-
local
|
|
1053
|
+
local ____initErrorClass_1 = initErrorClass
|
|
1060
1054
|
local ____class_0 = __TS__Class()
|
|
1061
1055
|
____class_0.name = ""
|
|
1062
1056
|
function ____class_0.prototype.____constructor(self, message)
|
|
@@ -1067,31 +1061,25 @@ do
|
|
|
1067
1061
|
self.name = "Error"
|
|
1068
1062
|
self.stack = getErrorStack(nil, self.constructor.new)
|
|
1069
1063
|
local metatable = getmetatable(self)
|
|
1070
|
-
if not metatable.__errorToStringPatched then
|
|
1064
|
+
if metatable and not metatable.__errorToStringPatched then
|
|
1071
1065
|
metatable.__errorToStringPatched = true
|
|
1072
1066
|
metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
|
|
1073
1067
|
end
|
|
1074
1068
|
end
|
|
1075
1069
|
function ____class_0.prototype.__tostring(self)
|
|
1076
|
-
|
|
1077
|
-
if self.message ~= "" then
|
|
1078
|
-
____temp_1 = (self.name .. ": ") .. self.message
|
|
1079
|
-
else
|
|
1080
|
-
____temp_1 = self.name
|
|
1081
|
-
end
|
|
1082
|
-
return ____temp_1
|
|
1070
|
+
return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
|
|
1083
1071
|
end
|
|
1084
|
-
Error =
|
|
1072
|
+
Error = ____initErrorClass_1(nil, ____class_0, "Error")
|
|
1085
1073
|
local function createErrorClass(self, name)
|
|
1086
|
-
local
|
|
1087
|
-
local
|
|
1088
|
-
|
|
1089
|
-
__TS__ClassExtends(
|
|
1090
|
-
function
|
|
1091
|
-
|
|
1074
|
+
local ____initErrorClass_3 = initErrorClass
|
|
1075
|
+
local ____class_2 = __TS__Class()
|
|
1076
|
+
____class_2.name = ____class_2.name
|
|
1077
|
+
__TS__ClassExtends(____class_2, Error)
|
|
1078
|
+
function ____class_2.prototype.____constructor(self, ...)
|
|
1079
|
+
____class_2.____super.prototype.____constructor(self, ...)
|
|
1092
1080
|
self.name = name
|
|
1093
1081
|
end
|
|
1094
|
-
return
|
|
1082
|
+
return ____initErrorClass_3(nil, ____class_2, name)
|
|
1095
1083
|
end
|
|
1096
1084
|
RangeError = createErrorClass(nil, "RangeError")
|
|
1097
1085
|
ReferenceError = createErrorClass(nil, "ReferenceError")
|
|
@@ -1261,13 +1249,13 @@ do
|
|
|
1261
1249
|
self.size = self.size - 1
|
|
1262
1250
|
local next = self.nextKey[key]
|
|
1263
1251
|
local previous = self.previousKey[key]
|
|
1264
|
-
if next and previous then
|
|
1252
|
+
if next ~= nil and previous ~= nil then
|
|
1265
1253
|
self.nextKey[previous] = next
|
|
1266
1254
|
self.previousKey[next] = previous
|
|
1267
|
-
elseif next then
|
|
1255
|
+
elseif next ~= nil then
|
|
1268
1256
|
self.firstKey = next
|
|
1269
1257
|
self.previousKey[next] = nil
|
|
1270
|
-
elseif previous then
|
|
1258
|
+
elseif previous ~= nil then
|
|
1271
1259
|
self.lastKey = previous
|
|
1272
1260
|
self.nextKey[previous] = nil
|
|
1273
1261
|
else
|
|
@@ -1453,13 +1441,7 @@ do
|
|
|
1453
1441
|
end
|
|
1454
1442
|
|
|
1455
1443
|
local function __TS__ObjectDefineProperty(target, key, desc)
|
|
1456
|
-
local
|
|
1457
|
-
if type(key) == "number" then
|
|
1458
|
-
____temp_0 = key + 1
|
|
1459
|
-
else
|
|
1460
|
-
____temp_0 = key
|
|
1461
|
-
end
|
|
1462
|
-
local luaKey = ____temp_0
|
|
1444
|
+
local luaKey = type(key) == "number" and key + 1 or key
|
|
1463
1445
|
local value = rawget(target, luaKey)
|
|
1464
1446
|
local hasGetterOrSetter = desc.get ~= nil or desc.set ~= nil
|
|
1465
1447
|
local descriptor
|
|
@@ -1473,39 +1455,39 @@ local function __TS__ObjectDefineProperty(target, key, desc)
|
|
|
1473
1455
|
descriptor = desc
|
|
1474
1456
|
else
|
|
1475
1457
|
local valueExists = value ~= nil
|
|
1476
|
-
local
|
|
1477
|
-
local
|
|
1478
|
-
local
|
|
1458
|
+
local ____desc_set_4 = desc.set
|
|
1459
|
+
local ____desc_get_5 = desc.get
|
|
1460
|
+
local ____temp_0
|
|
1479
1461
|
if desc.configurable ~= nil then
|
|
1480
|
-
|
|
1462
|
+
____temp_0 = desc.configurable
|
|
1481
1463
|
else
|
|
1482
|
-
|
|
1464
|
+
____temp_0 = valueExists
|
|
1483
1465
|
end
|
|
1484
|
-
local
|
|
1466
|
+
local ____temp_1
|
|
1485
1467
|
if desc.enumerable ~= nil then
|
|
1486
|
-
|
|
1468
|
+
____temp_1 = desc.enumerable
|
|
1487
1469
|
else
|
|
1488
|
-
|
|
1470
|
+
____temp_1 = valueExists
|
|
1489
1471
|
end
|
|
1490
|
-
local
|
|
1472
|
+
local ____temp_2
|
|
1491
1473
|
if desc.writable ~= nil then
|
|
1492
|
-
|
|
1474
|
+
____temp_2 = desc.writable
|
|
1493
1475
|
else
|
|
1494
|
-
|
|
1476
|
+
____temp_2 = valueExists
|
|
1495
1477
|
end
|
|
1496
|
-
local
|
|
1478
|
+
local ____temp_3
|
|
1497
1479
|
if desc.value ~= nil then
|
|
1498
|
-
|
|
1480
|
+
____temp_3 = desc.value
|
|
1499
1481
|
else
|
|
1500
|
-
|
|
1482
|
+
____temp_3 = value
|
|
1501
1483
|
end
|
|
1502
1484
|
descriptor = {
|
|
1503
|
-
set =
|
|
1504
|
-
get =
|
|
1505
|
-
configurable =
|
|
1506
|
-
enumerable =
|
|
1507
|
-
writable =
|
|
1508
|
-
value =
|
|
1485
|
+
set = ____desc_set_4,
|
|
1486
|
+
get = ____desc_get_5,
|
|
1487
|
+
configurable = ____temp_0,
|
|
1488
|
+
enumerable = ____temp_1,
|
|
1489
|
+
writable = ____temp_2,
|
|
1490
|
+
value = ____temp_3
|
|
1509
1491
|
}
|
|
1510
1492
|
end
|
|
1511
1493
|
__TS__SetDescriptor(target, luaKey, descriptor)
|
|
@@ -1575,14 +1557,8 @@ end
|
|
|
1575
1557
|
|
|
1576
1558
|
local function __TS__ParseFloat(numberString)
|
|
1577
1559
|
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1578
|
-
if infinityMatch then
|
|
1579
|
-
|
|
1580
|
-
if __TS__StringAccess(infinityMatch, 0) == "-" then
|
|
1581
|
-
____temp_0 = -math.huge
|
|
1582
|
-
else
|
|
1583
|
-
____temp_0 = math.huge
|
|
1584
|
-
end
|
|
1585
|
-
return ____temp_0
|
|
1560
|
+
if infinityMatch ~= nil then
|
|
1561
|
+
return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
|
|
1586
1562
|
end
|
|
1587
1563
|
local number = tonumber(__TS__Match(numberString, "^%s*(-?%d+%.?%d*)"))
|
|
1588
1564
|
return number or 0 / 0
|
|
@@ -1613,27 +1589,15 @@ do
|
|
|
1613
1589
|
if base == nil then
|
|
1614
1590
|
base = 10
|
|
1615
1591
|
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1616
|
-
if hexMatch then
|
|
1592
|
+
if hexMatch ~= nil then
|
|
1617
1593
|
base = 16
|
|
1618
|
-
|
|
1619
|
-
if __TS__Match(hexMatch, "-") then
|
|
1620
|
-
____TS__Match_result__0_0 = "-" .. __TS__StringSubstring(numberString, #hexMatch)
|
|
1621
|
-
else
|
|
1622
|
-
____TS__Match_result__0_0 = __TS__StringSubstring(numberString, #hexMatch)
|
|
1623
|
-
end
|
|
1624
|
-
numberString = ____TS__Match_result__0_0
|
|
1594
|
+
numberString = __TS__Match(hexMatch, "-") and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
1625
1595
|
end
|
|
1626
1596
|
end
|
|
1627
1597
|
if base < 2 or base > 36 then
|
|
1628
1598
|
return 0 / 0
|
|
1629
1599
|
end
|
|
1630
|
-
local
|
|
1631
|
-
if base <= 10 then
|
|
1632
|
-
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, base)
|
|
1633
|
-
else
|
|
1634
|
-
____temp_1 = __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1635
|
-
end
|
|
1636
|
-
local allowedDigits = ____temp_1
|
|
1600
|
+
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1637
1601
|
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1638
1602
|
local number = tonumber(
|
|
1639
1603
|
__TS__Match(numberString, pattern),
|
|
@@ -1872,13 +1836,13 @@ do
|
|
|
1872
1836
|
self.size = self.size - 1
|
|
1873
1837
|
local next = self.nextKey[value]
|
|
1874
1838
|
local previous = self.previousKey[value]
|
|
1875
|
-
if next and previous then
|
|
1839
|
+
if next ~= nil and previous ~= nil then
|
|
1876
1840
|
self.nextKey[previous] = next
|
|
1877
1841
|
self.previousKey[next] = previous
|
|
1878
|
-
elseif next then
|
|
1842
|
+
elseif next ~= nil then
|
|
1879
1843
|
self.firstKey = next
|
|
1880
1844
|
self.previousKey[next] = nil
|
|
1881
|
-
elseif previous then
|
|
1845
|
+
elseif previous ~= nil then
|
|
1882
1846
|
self.lastKey = previous
|
|
1883
1847
|
self.nextKey[previous] = nil
|
|
1884
1848
|
else
|
|
@@ -2066,7 +2030,7 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2066
2030
|
if thread == nil and message == nil and level == nil then
|
|
2067
2031
|
trace = originalTraceback()
|
|
2068
2032
|
elseif __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
|
2069
|
-
trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. message)
|
|
2033
|
+
trace = originalTraceback((("[Level " .. tostring(level)) .. "] ") .. tostring(message))
|
|
2070
2034
|
else
|
|
2071
2035
|
trace = originalTraceback(thread, message, level)
|
|
2072
2036
|
end
|
|
@@ -2075,12 +2039,12 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2075
2039
|
end
|
|
2076
2040
|
local function replacer(____, file, srcFile, line)
|
|
2077
2041
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2078
|
-
if fileSourceMap and fileSourceMap[line] then
|
|
2042
|
+
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
2079
2043
|
local data = fileSourceMap[line]
|
|
2080
2044
|
if type(data) == "number" then
|
|
2081
2045
|
return (srcFile .. ":") .. tostring(data)
|
|
2082
2046
|
end
|
|
2083
|
-
return (
|
|
2047
|
+
return (data.file .. ":") .. tostring(data.line)
|
|
2084
2048
|
end
|
|
2085
2049
|
return (file .. ":") .. line
|
|
2086
2050
|
end
|
|
@@ -2091,14 +2055,14 @@ local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
|
2091
2055
|
)
|
|
2092
2056
|
local function stringReplacer(____, file, line)
|
|
2093
2057
|
local fileSourceMap = _G.__TS__sourcemap[file]
|
|
2094
|
-
if fileSourceMap and fileSourceMap[line] then
|
|
2058
|
+
if fileSourceMap ~= nil and fileSourceMap[line] ~= nil then
|
|
2095
2059
|
local chunkName = __TS__Match(file, "%[string \"([^\"]+)\"%]")
|
|
2096
2060
|
local sourceName = string.gsub(chunkName, ".lua$", ".ts")
|
|
2097
2061
|
local data = fileSourceMap[line]
|
|
2098
2062
|
if type(data) == "number" then
|
|
2099
2063
|
return (sourceName .. ":") .. tostring(data)
|
|
2100
2064
|
end
|
|
2101
|
-
return (
|
|
2065
|
+
return (data.file .. ":") .. tostring(data.line)
|
|
2102
2066
|
end
|
|
2103
2067
|
return (file .. ":") .. line
|
|
2104
2068
|
end
|
|
@@ -2218,13 +2182,7 @@ do
|
|
|
2218
2182
|
return source
|
|
2219
2183
|
end
|
|
2220
2184
|
local before = sub(source, 1, startPos - 1)
|
|
2221
|
-
local
|
|
2222
|
-
if type(replaceValue) == "string" then
|
|
2223
|
-
____temp_0 = replaceValue
|
|
2224
|
-
else
|
|
2225
|
-
____temp_0 = replaceValue(nil, searchValue, startPos - 1, source)
|
|
2226
|
-
end
|
|
2227
|
-
local replacement = ____temp_0
|
|
2185
|
+
local replacement = type(replaceValue) == "string" and replaceValue or replaceValue(nil, searchValue, startPos - 1, source)
|
|
2228
2186
|
local after = sub(source, endPos + 1)
|
|
2229
2187
|
return (before .. replacement) .. after
|
|
2230
2188
|
end
|
|
@@ -2379,6 +2337,7 @@ do
|
|
|
2379
2337
|
return key
|
|
2380
2338
|
end
|
|
2381
2339
|
end
|
|
2340
|
+
return nil
|
|
2382
2341
|
end
|
|
2383
2342
|
end
|
|
2384
2343
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import * as lua from "../../LuaAST";
|
|
2
2
|
import { TransformationContext } from "../context";
|
|
3
|
-
export
|
|
3
|
+
export interface WithPrecedingStatements<T extends lua.Statement | lua.Statement[] | lua.Expression | lua.Expression[]> {
|
|
4
|
+
precedingStatements: lua.Statement[];
|
|
5
|
+
result: T;
|
|
6
|
+
}
|
|
7
|
+
export declare function transformInPrecedingStatementScope<TReturn extends lua.Statement | lua.Statement[] | lua.Expression | lua.Expression[]>(context: TransformationContext, transformer: () => TReturn): WithPrecedingStatements<TReturn>;
|
|
@@ -5,7 +5,7 @@ function transformInPrecedingStatementScope(context, transformer) {
|
|
|
5
5
|
context.pushPrecedingStatements();
|
|
6
6
|
const statementOrStatements = transformer();
|
|
7
7
|
const precedingStatements = context.popPrecedingStatements();
|
|
8
|
-
return
|
|
8
|
+
return { precedingStatements, result: statementOrStatements };
|
|
9
9
|
}
|
|
10
10
|
exports.transformInPrecedingStatementScope = transformInPrecedingStatementScope;
|
|
11
11
|
//# sourceMappingURL=preceding-statements.js.map
|
|
@@ -72,7 +72,7 @@ function transformAssignmentWithRightPrecedingStatements(context, lhs, right, ri
|
|
|
72
72
|
}
|
|
73
73
|
exports.transformAssignmentWithRightPrecedingStatements = transformAssignmentWithRightPrecedingStatements;
|
|
74
74
|
function transformDestructuredAssignmentExpression(context, expression) {
|
|
75
|
-
let
|
|
75
|
+
let { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
76
76
|
context.addPrecedingStatements(rightPrecedingStatements);
|
|
77
77
|
if ((0, multi_1.isMultiReturnCall)(context, expression.right)) {
|
|
78
78
|
right = (0, lua_ast_1.wrapInTable)(right);
|
|
@@ -96,7 +96,7 @@ function transformAssignmentExpression(context, expression) {
|
|
|
96
96
|
return result;
|
|
97
97
|
}
|
|
98
98
|
if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) {
|
|
99
|
-
const
|
|
99
|
+
const { precedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
100
100
|
const left = transformAssignmentLeftHandSideExpression(context, expression.left, precedingStatements.length > 0);
|
|
101
101
|
context.addPrecedingStatements(precedingStatements);
|
|
102
102
|
const rightExpr = (0, expression_list_1.moveToPrecedingTemp)(context, right, expression.right);
|
|
@@ -156,7 +156,7 @@ function transformAssignmentStatement(context, expression) {
|
|
|
156
156
|
return statements;
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
|
-
const
|
|
159
|
+
const { precedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(expression.right));
|
|
160
160
|
return transformAssignmentWithRightPrecedingStatements(context, expression.left, right, precedingStatements);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -4,13 +4,6 @@ import { TransformationContext } from "../../context";
|
|
|
4
4
|
type CompoundAssignmentToken = ts.SyntaxKind.BarToken | ts.SyntaxKind.PlusToken | ts.SyntaxKind.CaretToken | ts.SyntaxKind.MinusToken | ts.SyntaxKind.SlashToken | ts.SyntaxKind.PercentToken | ts.SyntaxKind.AsteriskToken | ts.SyntaxKind.AmpersandToken | ts.SyntaxKind.AsteriskAsteriskToken | ts.SyntaxKind.LessThanLessThanToken | ts.SyntaxKind.GreaterThanGreaterThanToken | ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.QuestionQuestionToken;
|
|
5
5
|
export declare const isCompoundAssignmentToken: (token: ts.BinaryOperator) => token is ts.CompoundAssignmentOperator;
|
|
6
6
|
export declare const unwrapCompoundAssignmentToken: (token: ts.CompoundAssignmentOperator) => CompoundAssignmentToken;
|
|
7
|
-
export declare function transformCompoundAssignment(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): {
|
|
8
|
-
statements: lua.Statement[];
|
|
9
|
-
result: lua.Identifier;
|
|
10
|
-
} | {
|
|
11
|
-
statements: lua.Statement[];
|
|
12
|
-
result: lua.TableIndexExpression;
|
|
13
|
-
};
|
|
14
7
|
export declare function transformCompoundAssignmentExpression(context: TransformationContext, expression: ts.Expression, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken, isPostfix: boolean): lua.Expression;
|
|
15
8
|
export declare function transformCompoundAssignmentStatement(context: TransformationContext, node: ts.Node, lhs: ts.Expression, rhs: ts.Expression, operator: CompoundAssignmentToken): lua.Statement[];
|
|
16
9
|
export {};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformCompoundAssignmentStatement = exports.transformCompoundAssignmentExpression = exports.
|
|
3
|
+
exports.transformCompoundAssignmentStatement = exports.transformCompoundAssignmentExpression = exports.unwrapCompoundAssignmentToken = exports.isCompoundAssignmentToken = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const preceding_statements_1 = require("../../utils/preceding-statements");
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
const assignments_1 = require("./assignments");
|
|
10
|
+
const destructuring_assignments_1 = require("./destructuring-assignments");
|
|
11
|
+
const lualib_1 = require("../../utils/lualib");
|
|
10
12
|
function isLuaExpressionWithSideEffect(expression) {
|
|
11
13
|
return !(lua.isLiteral(expression) || lua.isIdentifier(expression));
|
|
12
14
|
}
|
|
@@ -37,8 +39,12 @@ exports.isCompoundAssignmentToken = isCompoundAssignmentToken;
|
|
|
37
39
|
const unwrapCompoundAssignmentToken = (token) => compoundToAssignmentTokens[token];
|
|
38
40
|
exports.unwrapCompoundAssignmentToken = unwrapCompoundAssignmentToken;
|
|
39
41
|
function transformCompoundAssignment(context, expression, lhs, rhs, operator, isPostfix) {
|
|
42
|
+
if ((0, destructuring_assignments_1.isArrayLength)(context, lhs)) {
|
|
43
|
+
const { precedingStatements, result: lengthSetterStatement } = transformCompoundLengthSetter(context, expression, lhs, rhs, operator);
|
|
44
|
+
return { precedingStatements, result: lengthSetterStatement.expression };
|
|
45
|
+
}
|
|
40
46
|
const left = (0, utils_1.cast)(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);
|
|
41
|
-
const
|
|
47
|
+
const { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
|
|
42
48
|
if (lua.isTableIndexExpression(left)) {
|
|
43
49
|
// Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
|
|
44
50
|
// local __obj, __index = ${objExpression}, ${indexExpression};
|
|
@@ -52,17 +58,17 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
52
58
|
// ____obj[____index] = ____tmp ${replacementOperator} ${right};
|
|
53
59
|
// return ____tmp
|
|
54
60
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, accessExpression);
|
|
55
|
-
const
|
|
61
|
+
const { precedingStatements, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, tmp, right, rightPrecedingStatements, operator, expression);
|
|
56
62
|
const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
|
|
57
63
|
return {
|
|
58
|
-
|
|
64
|
+
precedingStatements: [objAndIndexDeclaration, ...precedingStatements, tmpDeclaration, assignStatement],
|
|
59
65
|
result: tmp,
|
|
60
66
|
};
|
|
61
67
|
}
|
|
62
68
|
else {
|
|
63
69
|
if (isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
64
70
|
return {
|
|
65
|
-
|
|
71
|
+
precedingStatements: [
|
|
66
72
|
objAndIndexDeclaration,
|
|
67
73
|
...transformSetterSkippingCompoundAssignment(accessExpression, operator, right, rightPrecedingStatements),
|
|
68
74
|
],
|
|
@@ -72,11 +78,11 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
72
78
|
// local ____tmp = ____obj[____index] ${replacementOperator} ${right};
|
|
73
79
|
// ____obj[____index] = ____tmp;
|
|
74
80
|
// return ____tmp
|
|
75
|
-
const
|
|
81
|
+
const { precedingStatements, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, expression);
|
|
76
82
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmp, operatorExpression);
|
|
77
83
|
const assignStatement = lua.createAssignmentStatement(accessExpression, tmp);
|
|
78
84
|
return {
|
|
79
|
-
|
|
85
|
+
precedingStatements: [objAndIndexDeclaration, ...precedingStatements, tmpDeclaration, assignStatement],
|
|
80
86
|
result: tmp,
|
|
81
87
|
};
|
|
82
88
|
}
|
|
@@ -88,36 +94,42 @@ function transformCompoundAssignment(context, expression, lhs, rhs, operator, is
|
|
|
88
94
|
// return ____tmp
|
|
89
95
|
const tmpIdentifier = context.createTempNameForLuaExpression(left);
|
|
90
96
|
const tmpDeclaration = lua.createVariableDeclarationStatement(tmpIdentifier, left);
|
|
91
|
-
const
|
|
97
|
+
const { precedingStatements, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, tmpIdentifier, right, rightPrecedingStatements, operator, expression);
|
|
92
98
|
const assignStatements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
|
|
93
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
precedingStatements: [tmpDeclaration, ...precedingStatements, ...assignStatements],
|
|
101
|
+
result: tmpIdentifier,
|
|
102
|
+
};
|
|
94
103
|
}
|
|
95
104
|
else {
|
|
96
105
|
if (rightPrecedingStatements.length > 0 && isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
97
106
|
return {
|
|
98
|
-
|
|
107
|
+
precedingStatements: transformSetterSkippingCompoundAssignment(left, operator, right, rightPrecedingStatements),
|
|
99
108
|
result: left,
|
|
100
109
|
};
|
|
101
110
|
}
|
|
102
111
|
// Simple expressions
|
|
103
112
|
// ${left} = ${left} ${operator} ${right}
|
|
104
|
-
const
|
|
113
|
+
const { precedingStatements, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, expression);
|
|
105
114
|
const statements = (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, precedingStatements);
|
|
106
|
-
return { statements, result: left };
|
|
115
|
+
return { precedingStatements: statements, result: left };
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
|
-
exports.transformCompoundAssignment = transformCompoundAssignment;
|
|
110
118
|
function transformCompoundAssignmentExpression(context, expression,
|
|
111
119
|
// TODO: Change type to ts.LeftHandSideExpression?
|
|
112
120
|
lhs, rhs, operator, isPostfix) {
|
|
113
|
-
const {
|
|
114
|
-
context.addPrecedingStatements(
|
|
121
|
+
const { precedingStatements, result } = transformCompoundAssignment(context, expression, lhs, rhs, operator, isPostfix);
|
|
122
|
+
context.addPrecedingStatements(precedingStatements);
|
|
115
123
|
return result;
|
|
116
124
|
}
|
|
117
125
|
exports.transformCompoundAssignmentExpression = transformCompoundAssignmentExpression;
|
|
118
126
|
function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator) {
|
|
127
|
+
if ((0, destructuring_assignments_1.isArrayLength)(context, lhs)) {
|
|
128
|
+
const { precedingStatements, result: lengthSetterStatement } = transformCompoundLengthSetter(context, node, lhs, rhs, operator);
|
|
129
|
+
return [...precedingStatements, lengthSetterStatement];
|
|
130
|
+
}
|
|
119
131
|
const left = (0, utils_1.cast)(context.transformExpression(lhs), lua.isAssignmentLeftHandSideExpression);
|
|
120
|
-
|
|
132
|
+
const { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
|
|
121
133
|
if (lua.isTableIndexExpression(left) && shouldCacheTableIndexExpressions(left, rightPrecedingStatements)) {
|
|
122
134
|
// Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
|
|
123
135
|
// local __obj, __index = ${objExpression}, ${indexExpression};
|
|
@@ -132,10 +144,9 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
|
|
|
132
144
|
...transformSetterSkippingCompoundAssignment(accessExpression, operator, right, rightPrecedingStatements, node),
|
|
133
145
|
];
|
|
134
146
|
}
|
|
135
|
-
|
|
136
|
-
[rightPrecedingStatements, operatorExpression] = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, node);
|
|
147
|
+
const { precedingStatements: rightPrecedingStatements2, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, accessExpression, right, rightPrecedingStatements, operator, node);
|
|
137
148
|
const assignStatement = lua.createAssignmentStatement(accessExpression, operatorExpression);
|
|
138
|
-
return [objAndIndexDeclaration, ...
|
|
149
|
+
return [objAndIndexDeclaration, ...rightPrecedingStatements2, assignStatement];
|
|
139
150
|
}
|
|
140
151
|
else {
|
|
141
152
|
if (isSetterSkippingCompoundAssignmentOperator(operator)) {
|
|
@@ -143,9 +154,8 @@ function transformCompoundAssignmentStatement(context, node, lhs, rhs, operator)
|
|
|
143
154
|
}
|
|
144
155
|
// Simple statements
|
|
145
156
|
// ${left} = ${left} ${replacementOperator} ${right}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements);
|
|
157
|
+
const { precedingStatements: rightPrecedingStatements2, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, left, right, rightPrecedingStatements, operator, node);
|
|
158
|
+
return (0, assignments_1.transformAssignmentWithRightPrecedingStatements)(context, lhs, operatorExpression, rightPrecedingStatements2);
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
161
|
exports.transformCompoundAssignmentStatement = transformCompoundAssignmentStatement;
|
|
@@ -174,4 +184,12 @@ function transformSetterSkippingCompoundAssignment(lhs, operator, right, rightPr
|
|
|
174
184
|
lua.createIfStatement(condition, lua.createBlock([...rightPrecedingStatements, lua.createAssignmentStatement(lhs, right, node)]), undefined, node),
|
|
175
185
|
];
|
|
176
186
|
}
|
|
187
|
+
function transformCompoundLengthSetter(context, node, lhs, rhs, operator) {
|
|
188
|
+
const { precedingStatements: rightPrecedingStatements, result: right } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => context.transformExpression(rhs));
|
|
189
|
+
const table = context.transformExpression(lhs.expression);
|
|
190
|
+
const lengthExpression = lua.createUnaryExpression(table, lua.SyntaxKind.LengthOperator, lhs);
|
|
191
|
+
const { precedingStatements, result: operatorExpression } = (0, index_1.transformBinaryOperation)(context, lengthExpression, right, rightPrecedingStatements, operator, node);
|
|
192
|
+
const arrayLengthAssignment = lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArraySetLength, node, table, operatorExpression));
|
|
193
|
+
return { precedingStatements, result: arrayLengthAssignment };
|
|
194
|
+
}
|
|
177
195
|
//# sourceMappingURL=compound.js.map
|