typescript-to-lua 1.19.2 → 1.20.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/dist/LuaLib.d.ts +2 -0
- package/dist/LuaLib.js +2 -0
- package/dist/lualib/5.0/Error.lua +3 -0
- package/dist/lualib/5.0/lualib_bundle.lua +67 -62
- package/dist/lualib/5.0/lualib_module_info.json +18 -18
- package/dist/lualib/universal/Error.lua +3 -0
- package/dist/lualib/universal/lualib_bundle.lua +61 -56
- package/dist/lualib/universal/lualib_module_info.json +18 -18
- package/dist/transformation/builtins/index.js +2 -0
- package/dist/transformation/builtins/number.d.ts +1 -0
- package/dist/transformation/builtins/number.js +53 -1
- package/dist/transpilation/resolve.js +4 -0
- package/package.json +1 -1
package/dist/LuaLib.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare enum LuaLibFeature {
|
|
|
60
60
|
Number = "Number",
|
|
61
61
|
NumberIsFinite = "NumberIsFinite",
|
|
62
62
|
NumberIsNaN = "NumberIsNaN",
|
|
63
|
+
NumberParseInt = "ParseInt",
|
|
64
|
+
NumberParseFloat = "ParseFloat",
|
|
63
65
|
NumberToString = "NumberToString",
|
|
64
66
|
NumberToFixed = "NumberToFixed",
|
|
65
67
|
ObjectAssign = "ObjectAssign",
|
package/dist/LuaLib.js
CHANGED
|
@@ -65,6 +65,8 @@ var LuaLibFeature;
|
|
|
65
65
|
LuaLibFeature["Number"] = "Number";
|
|
66
66
|
LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
|
|
67
67
|
LuaLibFeature["NumberIsNaN"] = "NumberIsNaN";
|
|
68
|
+
LuaLibFeature["NumberParseInt"] = "ParseInt";
|
|
69
|
+
LuaLibFeature["NumberParseFloat"] = "ParseFloat";
|
|
68
70
|
LuaLibFeature["NumberToString"] = "NumberToString";
|
|
69
71
|
LuaLibFeature["NumberToFixed"] = "NumberToFixed";
|
|
70
72
|
LuaLibFeature["ObjectAssign"] = "ObjectAssign";
|
|
@@ -1071,6 +1071,9 @@ end
|
|
|
1071
1071
|
local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
|
1072
1072
|
do
|
|
1073
1073
|
local function getErrorStack(self, constructor)
|
|
1074
|
+
if debug == nil then
|
|
1075
|
+
return nil
|
|
1076
|
+
end
|
|
1074
1077
|
local level = 1
|
|
1075
1078
|
while true do
|
|
1076
1079
|
local info = debug.getinfo(level, "f")
|
|
@@ -1508,6 +1511,68 @@ local function __TS__NumberIsNaN(value)
|
|
|
1508
1511
|
return value ~= value
|
|
1509
1512
|
end
|
|
1510
1513
|
|
|
1514
|
+
local function __TS__StringSubstring(self, start, ____end)
|
|
1515
|
+
if ____end ~= ____end then
|
|
1516
|
+
____end = 0
|
|
1517
|
+
end
|
|
1518
|
+
if ____end ~= nil and start > ____end then
|
|
1519
|
+
start, ____end = ____end, start
|
|
1520
|
+
end
|
|
1521
|
+
if start >= 0 then
|
|
1522
|
+
start = start + 1
|
|
1523
|
+
else
|
|
1524
|
+
start = 1
|
|
1525
|
+
end
|
|
1526
|
+
if ____end ~= nil and ____end < 0 then
|
|
1527
|
+
____end = 0
|
|
1528
|
+
end
|
|
1529
|
+
return string.sub(self, start, ____end)
|
|
1530
|
+
end
|
|
1531
|
+
|
|
1532
|
+
local __TS__ParseInt
|
|
1533
|
+
do
|
|
1534
|
+
local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
|
|
1535
|
+
function __TS__ParseInt(numberString, base)
|
|
1536
|
+
if base == nil then
|
|
1537
|
+
base = 10
|
|
1538
|
+
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1539
|
+
if hexMatch ~= nil then
|
|
1540
|
+
base = 16
|
|
1541
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(
|
|
1542
|
+
numberString,
|
|
1543
|
+
string.len(hexMatch)
|
|
1544
|
+
) or __TS__StringSubstring(
|
|
1545
|
+
numberString,
|
|
1546
|
+
string.len(hexMatch)
|
|
1547
|
+
)
|
|
1548
|
+
end
|
|
1549
|
+
end
|
|
1550
|
+
if base < 2 or base > 36 then
|
|
1551
|
+
return 0 / 0
|
|
1552
|
+
end
|
|
1553
|
+
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1554
|
+
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1555
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1556
|
+
if number == nil then
|
|
1557
|
+
return 0 / 0
|
|
1558
|
+
end
|
|
1559
|
+
if number >= 0 then
|
|
1560
|
+
return math.floor(number)
|
|
1561
|
+
else
|
|
1562
|
+
return math.ceil(number)
|
|
1563
|
+
end
|
|
1564
|
+
end
|
|
1565
|
+
end
|
|
1566
|
+
|
|
1567
|
+
local function __TS__ParseFloat(numberString)
|
|
1568
|
+
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1569
|
+
if infinityMatch ~= nil then
|
|
1570
|
+
return __TS__StringAccess(infinityMatch, 0) == "-" and -(1 / 0) or 1 / 0
|
|
1571
|
+
end
|
|
1572
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1573
|
+
return number or 0 / 0
|
|
1574
|
+
end
|
|
1575
|
+
|
|
1511
1576
|
local __TS__NumberToString
|
|
1512
1577
|
do
|
|
1513
1578
|
local radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
@@ -1685,68 +1750,6 @@ local function __TS__ObjectValues(obj)
|
|
|
1685
1750
|
return result
|
|
1686
1751
|
end
|
|
1687
1752
|
|
|
1688
|
-
local function __TS__ParseFloat(numberString)
|
|
1689
|
-
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1690
|
-
if infinityMatch ~= nil then
|
|
1691
|
-
return __TS__StringAccess(infinityMatch, 0) == "-" and -(1 / 0) or 1 / 0
|
|
1692
|
-
end
|
|
1693
|
-
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1694
|
-
return number or 0 / 0
|
|
1695
|
-
end
|
|
1696
|
-
|
|
1697
|
-
local function __TS__StringSubstring(self, start, ____end)
|
|
1698
|
-
if ____end ~= ____end then
|
|
1699
|
-
____end = 0
|
|
1700
|
-
end
|
|
1701
|
-
if ____end ~= nil and start > ____end then
|
|
1702
|
-
start, ____end = ____end, start
|
|
1703
|
-
end
|
|
1704
|
-
if start >= 0 then
|
|
1705
|
-
start = start + 1
|
|
1706
|
-
else
|
|
1707
|
-
start = 1
|
|
1708
|
-
end
|
|
1709
|
-
if ____end ~= nil and ____end < 0 then
|
|
1710
|
-
____end = 0
|
|
1711
|
-
end
|
|
1712
|
-
return string.sub(self, start, ____end)
|
|
1713
|
-
end
|
|
1714
|
-
|
|
1715
|
-
local __TS__ParseInt
|
|
1716
|
-
do
|
|
1717
|
-
local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
|
|
1718
|
-
function __TS__ParseInt(numberString, base)
|
|
1719
|
-
if base == nil then
|
|
1720
|
-
base = 10
|
|
1721
|
-
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1722
|
-
if hexMatch ~= nil then
|
|
1723
|
-
base = 16
|
|
1724
|
-
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(
|
|
1725
|
-
numberString,
|
|
1726
|
-
string.len(hexMatch)
|
|
1727
|
-
) or __TS__StringSubstring(
|
|
1728
|
-
numberString,
|
|
1729
|
-
string.len(hexMatch)
|
|
1730
|
-
)
|
|
1731
|
-
end
|
|
1732
|
-
end
|
|
1733
|
-
if base < 2 or base > 36 then
|
|
1734
|
-
return 0 / 0
|
|
1735
|
-
end
|
|
1736
|
-
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1737
|
-
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1738
|
-
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1739
|
-
if number == nil then
|
|
1740
|
-
return 0 / 0
|
|
1741
|
-
end
|
|
1742
|
-
if number >= 0 then
|
|
1743
|
-
return math.floor(number)
|
|
1744
|
-
else
|
|
1745
|
-
return math.ceil(number)
|
|
1746
|
-
end
|
|
1747
|
-
end
|
|
1748
|
-
end
|
|
1749
|
-
|
|
1750
1753
|
local function __TS__PromiseAll(iterable)
|
|
1751
1754
|
local results = {}
|
|
1752
1755
|
local toResolve = {}
|
|
@@ -2605,6 +2608,8 @@ return {
|
|
|
2605
2608
|
__TS__Number = __TS__Number,
|
|
2606
2609
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
2607
2610
|
__TS__NumberIsNaN = __TS__NumberIsNaN,
|
|
2611
|
+
__TS__ParseInt = __TS__ParseInt,
|
|
2612
|
+
__TS__ParseFloat = __TS__ParseFloat,
|
|
2608
2613
|
__TS__NumberToString = __TS__NumberToString,
|
|
2609
2614
|
__TS__NumberToFixed = __TS__NumberToFixed,
|
|
2610
2615
|
__TS__ObjectAssign = __TS__ObjectAssign,
|
|
@@ -381,6 +381,24 @@
|
|
|
381
381
|
"__TS__NumberIsNaN"
|
|
382
382
|
]
|
|
383
383
|
},
|
|
384
|
+
"ParseInt": {
|
|
385
|
+
"exports": [
|
|
386
|
+
"__TS__ParseInt"
|
|
387
|
+
],
|
|
388
|
+
"dependencies": [
|
|
389
|
+
"StringSubstring",
|
|
390
|
+
"Match"
|
|
391
|
+
]
|
|
392
|
+
},
|
|
393
|
+
"ParseFloat": {
|
|
394
|
+
"exports": [
|
|
395
|
+
"__TS__ParseFloat"
|
|
396
|
+
],
|
|
397
|
+
"dependencies": [
|
|
398
|
+
"StringAccess",
|
|
399
|
+
"Match"
|
|
400
|
+
]
|
|
401
|
+
},
|
|
384
402
|
"NumberToString": {
|
|
385
403
|
"exports": [
|
|
386
404
|
"__TS__NumberToString"
|
|
@@ -446,24 +464,6 @@
|
|
|
446
464
|
"__TS__ObjectValues"
|
|
447
465
|
]
|
|
448
466
|
},
|
|
449
|
-
"ParseFloat": {
|
|
450
|
-
"exports": [
|
|
451
|
-
"__TS__ParseFloat"
|
|
452
|
-
],
|
|
453
|
-
"dependencies": [
|
|
454
|
-
"StringAccess",
|
|
455
|
-
"Match"
|
|
456
|
-
]
|
|
457
|
-
},
|
|
458
|
-
"ParseInt": {
|
|
459
|
-
"exports": [
|
|
460
|
-
"__TS__ParseInt"
|
|
461
|
-
],
|
|
462
|
-
"dependencies": [
|
|
463
|
-
"StringSubstring",
|
|
464
|
-
"Match"
|
|
465
|
-
]
|
|
466
|
-
},
|
|
467
467
|
"Promise": {
|
|
468
468
|
"exports": [
|
|
469
469
|
"__TS__Promise"
|
|
@@ -1067,6 +1067,9 @@ end
|
|
|
1067
1067
|
local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
|
1068
1068
|
do
|
|
1069
1069
|
local function getErrorStack(self, constructor)
|
|
1070
|
+
if debug == nil then
|
|
1071
|
+
return nil
|
|
1072
|
+
end
|
|
1070
1073
|
local level = 1
|
|
1071
1074
|
while true do
|
|
1072
1075
|
local info = debug.getinfo(level, "f")
|
|
@@ -1448,6 +1451,62 @@ local function __TS__NumberIsNaN(value)
|
|
|
1448
1451
|
return value ~= value
|
|
1449
1452
|
end
|
|
1450
1453
|
|
|
1454
|
+
local function __TS__StringSubstring(self, start, ____end)
|
|
1455
|
+
if ____end ~= ____end then
|
|
1456
|
+
____end = 0
|
|
1457
|
+
end
|
|
1458
|
+
if ____end ~= nil and start > ____end then
|
|
1459
|
+
start, ____end = ____end, start
|
|
1460
|
+
end
|
|
1461
|
+
if start >= 0 then
|
|
1462
|
+
start = start + 1
|
|
1463
|
+
else
|
|
1464
|
+
start = 1
|
|
1465
|
+
end
|
|
1466
|
+
if ____end ~= nil and ____end < 0 then
|
|
1467
|
+
____end = 0
|
|
1468
|
+
end
|
|
1469
|
+
return string.sub(self, start, ____end)
|
|
1470
|
+
end
|
|
1471
|
+
|
|
1472
|
+
local __TS__ParseInt
|
|
1473
|
+
do
|
|
1474
|
+
local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
|
|
1475
|
+
function __TS__ParseInt(numberString, base)
|
|
1476
|
+
if base == nil then
|
|
1477
|
+
base = 10
|
|
1478
|
+
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1479
|
+
if hexMatch ~= nil then
|
|
1480
|
+
base = 16
|
|
1481
|
+
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
1482
|
+
end
|
|
1483
|
+
end
|
|
1484
|
+
if base < 2 or base > 36 then
|
|
1485
|
+
return 0 / 0
|
|
1486
|
+
end
|
|
1487
|
+
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1488
|
+
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1489
|
+
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1490
|
+
if number == nil then
|
|
1491
|
+
return 0 / 0
|
|
1492
|
+
end
|
|
1493
|
+
if number >= 0 then
|
|
1494
|
+
return math.floor(number)
|
|
1495
|
+
else
|
|
1496
|
+
return math.ceil(number)
|
|
1497
|
+
end
|
|
1498
|
+
end
|
|
1499
|
+
end
|
|
1500
|
+
|
|
1501
|
+
local function __TS__ParseFloat(numberString)
|
|
1502
|
+
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1503
|
+
if infinityMatch ~= nil then
|
|
1504
|
+
return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
|
|
1505
|
+
end
|
|
1506
|
+
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1507
|
+
return number or 0 / 0
|
|
1508
|
+
end
|
|
1509
|
+
|
|
1451
1510
|
local __TS__NumberToString
|
|
1452
1511
|
do
|
|
1453
1512
|
local radixChars = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
@@ -1622,62 +1681,6 @@ local function __TS__ObjectValues(obj)
|
|
|
1622
1681
|
return result
|
|
1623
1682
|
end
|
|
1624
1683
|
|
|
1625
|
-
local function __TS__ParseFloat(numberString)
|
|
1626
|
-
local infinityMatch = __TS__Match(numberString, "^%s*(-?Infinity)")
|
|
1627
|
-
if infinityMatch ~= nil then
|
|
1628
|
-
return __TS__StringAccess(infinityMatch, 0) == "-" and -math.huge or math.huge
|
|
1629
|
-
end
|
|
1630
|
-
local number = tonumber((__TS__Match(numberString, "^%s*(-?%d+%.?%d*)")))
|
|
1631
|
-
return number or 0 / 0
|
|
1632
|
-
end
|
|
1633
|
-
|
|
1634
|
-
local function __TS__StringSubstring(self, start, ____end)
|
|
1635
|
-
if ____end ~= ____end then
|
|
1636
|
-
____end = 0
|
|
1637
|
-
end
|
|
1638
|
-
if ____end ~= nil and start > ____end then
|
|
1639
|
-
start, ____end = ____end, start
|
|
1640
|
-
end
|
|
1641
|
-
if start >= 0 then
|
|
1642
|
-
start = start + 1
|
|
1643
|
-
else
|
|
1644
|
-
start = 1
|
|
1645
|
-
end
|
|
1646
|
-
if ____end ~= nil and ____end < 0 then
|
|
1647
|
-
____end = 0
|
|
1648
|
-
end
|
|
1649
|
-
return string.sub(self, start, ____end)
|
|
1650
|
-
end
|
|
1651
|
-
|
|
1652
|
-
local __TS__ParseInt
|
|
1653
|
-
do
|
|
1654
|
-
local parseIntBasePattern = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"
|
|
1655
|
-
function __TS__ParseInt(numberString, base)
|
|
1656
|
-
if base == nil then
|
|
1657
|
-
base = 10
|
|
1658
|
-
local hexMatch = __TS__Match(numberString, "^%s*-?0[xX]")
|
|
1659
|
-
if hexMatch ~= nil then
|
|
1660
|
-
base = 16
|
|
1661
|
-
numberString = (__TS__Match(hexMatch, "-")) and "-" .. __TS__StringSubstring(numberString, #hexMatch) or __TS__StringSubstring(numberString, #hexMatch)
|
|
1662
|
-
end
|
|
1663
|
-
end
|
|
1664
|
-
if base < 2 or base > 36 then
|
|
1665
|
-
return 0 / 0
|
|
1666
|
-
end
|
|
1667
|
-
local allowedDigits = base <= 10 and __TS__StringSubstring(parseIntBasePattern, 0, base) or __TS__StringSubstring(parseIntBasePattern, 0, 10 + 2 * (base - 10))
|
|
1668
|
-
local pattern = ("^%s*(-?[" .. allowedDigits) .. "]*)"
|
|
1669
|
-
local number = tonumber((__TS__Match(numberString, pattern)), base)
|
|
1670
|
-
if number == nil then
|
|
1671
|
-
return 0 / 0
|
|
1672
|
-
end
|
|
1673
|
-
if number >= 0 then
|
|
1674
|
-
return math.floor(number)
|
|
1675
|
-
else
|
|
1676
|
-
return math.ceil(number)
|
|
1677
|
-
end
|
|
1678
|
-
end
|
|
1679
|
-
end
|
|
1680
|
-
|
|
1681
1684
|
local function __TS__PromiseAll(iterable)
|
|
1682
1685
|
local results = {}
|
|
1683
1686
|
local toResolve = {}
|
|
@@ -2545,6 +2548,8 @@ return {
|
|
|
2545
2548
|
__TS__Number = __TS__Number,
|
|
2546
2549
|
__TS__NumberIsFinite = __TS__NumberIsFinite,
|
|
2547
2550
|
__TS__NumberIsNaN = __TS__NumberIsNaN,
|
|
2551
|
+
__TS__ParseInt = __TS__ParseInt,
|
|
2552
|
+
__TS__ParseFloat = __TS__ParseFloat,
|
|
2548
2553
|
__TS__NumberToString = __TS__NumberToString,
|
|
2549
2554
|
__TS__NumberToFixed = __TS__NumberToFixed,
|
|
2550
2555
|
__TS__ObjectAssign = __TS__ObjectAssign,
|
|
@@ -387,6 +387,24 @@
|
|
|
387
387
|
"__TS__NumberIsNaN"
|
|
388
388
|
]
|
|
389
389
|
},
|
|
390
|
+
"ParseInt": {
|
|
391
|
+
"exports": [
|
|
392
|
+
"__TS__ParseInt"
|
|
393
|
+
],
|
|
394
|
+
"dependencies": [
|
|
395
|
+
"StringSubstring",
|
|
396
|
+
"Match"
|
|
397
|
+
]
|
|
398
|
+
},
|
|
399
|
+
"ParseFloat": {
|
|
400
|
+
"exports": [
|
|
401
|
+
"__TS__ParseFloat"
|
|
402
|
+
],
|
|
403
|
+
"dependencies": [
|
|
404
|
+
"StringAccess",
|
|
405
|
+
"Match"
|
|
406
|
+
]
|
|
407
|
+
},
|
|
390
408
|
"NumberToString": {
|
|
391
409
|
"exports": [
|
|
392
410
|
"__TS__NumberToString"
|
|
@@ -452,24 +470,6 @@
|
|
|
452
470
|
"__TS__ObjectValues"
|
|
453
471
|
]
|
|
454
472
|
},
|
|
455
|
-
"ParseFloat": {
|
|
456
|
-
"exports": [
|
|
457
|
-
"__TS__ParseFloat"
|
|
458
|
-
],
|
|
459
|
-
"dependencies": [
|
|
460
|
-
"StringAccess",
|
|
461
|
-
"Match"
|
|
462
|
-
]
|
|
463
|
-
},
|
|
464
|
-
"ParseInt": {
|
|
465
|
-
"exports": [
|
|
466
|
-
"__TS__ParseInt"
|
|
467
|
-
],
|
|
468
|
-
"dependencies": [
|
|
469
|
-
"StringSubstring",
|
|
470
|
-
"Match"
|
|
471
|
-
]
|
|
472
|
-
},
|
|
473
473
|
"Promise": {
|
|
474
474
|
"exports": [
|
|
475
475
|
"__TS__Promise"
|
|
@@ -24,6 +24,8 @@ function transformBuiltinPropertyAccessExpression(context, node) {
|
|
|
24
24
|
const ownerType = context.checker.getTypeAtLocation(node.expression);
|
|
25
25
|
if (ts.isIdentifier(node.expression) && (0, typescript_1.isStandardLibraryType)(context, ownerType, undefined)) {
|
|
26
26
|
switch (ownerType.symbol.name) {
|
|
27
|
+
case "NumberConstructor":
|
|
28
|
+
return (0, number_1.transformNumberProperty)(context, node);
|
|
27
29
|
case "Math":
|
|
28
30
|
return (0, math_1.transformMathProperty)(context, node);
|
|
29
31
|
case "SymbolConstructor":
|
|
@@ -2,4 +2,5 @@ import ts = require("typescript");
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../context";
|
|
4
4
|
export declare function transformNumberPrototypeCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
|
+
export declare function transformNumberProperty(context: TransformationContext, node: ts.PropertyAccessExpression): lua.Expression | undefined;
|
|
5
6
|
export declare function transformNumberConstructorCall(context: TransformationContext, node: ts.CallExpression, calledMethod: ts.PropertyAccessExpression): lua.CallExpression | undefined;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformNumberConstructorCall = exports.transformNumberPrototypeCall = void 0;
|
|
3
|
+
exports.transformNumberConstructorCall = exports.transformNumberProperty = exports.transformNumberPrototypeCall = void 0;
|
|
4
4
|
const lua = require("../../LuaAST");
|
|
5
|
+
const lua_ast_1 = require("../utils/lua-ast");
|
|
5
6
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
6
7
|
const lualib_1 = require("../utils/lualib");
|
|
7
8
|
const call_1 = require("../visitors/call");
|
|
9
|
+
const CompilerOptions_1 = require("../../CompilerOptions");
|
|
8
10
|
function transformNumberPrototypeCall(context, node, calledMethod) {
|
|
9
11
|
const signature = context.checker.getResolvedSignature(node);
|
|
10
12
|
const params = (0, call_1.transformArguments)(context, node.arguments, signature);
|
|
@@ -22,6 +24,52 @@ function transformNumberPrototypeCall(context, node, calledMethod) {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
exports.transformNumberPrototypeCall = transformNumberPrototypeCall;
|
|
27
|
+
function transformNumberProperty(context, node) {
|
|
28
|
+
const name = node.name.text;
|
|
29
|
+
/*
|
|
30
|
+
Read the docs on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number for further info about what these numbers entail.
|
|
31
|
+
Most of them should be fairly straight forward base on their name(s) though.
|
|
32
|
+
*/
|
|
33
|
+
switch (name) {
|
|
34
|
+
case "POSITIVE_INFINITY":
|
|
35
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
36
|
+
const one = lua.createNumericLiteral(1);
|
|
37
|
+
const zero = lua.createNumericLiteral(0);
|
|
38
|
+
return lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const math = lua.createIdentifier("math");
|
|
42
|
+
const huge = lua.createStringLiteral("huge");
|
|
43
|
+
return lua.createTableIndexExpression(math, huge, node);
|
|
44
|
+
}
|
|
45
|
+
case "NEGATIVE_INFINITY":
|
|
46
|
+
if (context.luaTarget === CompilerOptions_1.LuaTarget.Lua50) {
|
|
47
|
+
const one = lua.createNumericLiteral(1);
|
|
48
|
+
const zero = lua.createNumericLiteral(0);
|
|
49
|
+
return lua.createUnaryExpression(lua.createBinaryExpression(one, zero, lua.SyntaxKind.DivisionOperator), lua.SyntaxKind.NegationOperator);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const math = lua.createIdentifier("math");
|
|
53
|
+
const huge = lua.createStringLiteral("huge");
|
|
54
|
+
return lua.createUnaryExpression(lua.createTableIndexExpression(math, huge, node), lua.SyntaxKind.NegationOperator);
|
|
55
|
+
}
|
|
56
|
+
case "NaN":
|
|
57
|
+
return (0, lua_ast_1.createNaN)(node);
|
|
58
|
+
case "EPSILON":
|
|
59
|
+
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(-52), lua.SyntaxKind.PowerOperator, node);
|
|
60
|
+
case "MIN_VALUE":
|
|
61
|
+
return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node);
|
|
62
|
+
case "MIN_SAFE_INTEGER":
|
|
63
|
+
return lua.createBinaryExpression(lua.createNumericLiteral(-2), lua.createNumericLiteral(1074), lua.SyntaxKind.PowerOperator, node);
|
|
64
|
+
case "MAX_SAFE_INTEGER":
|
|
65
|
+
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node);
|
|
66
|
+
case "MAX_VALUE":
|
|
67
|
+
return lua.createBinaryExpression(lua.createNumericLiteral(2), lua.createNumericLiteral(1024), lua.SyntaxKind.PowerOperator, node);
|
|
68
|
+
default:
|
|
69
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(node.name, "Number", name));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.transformNumberProperty = transformNumberProperty;
|
|
25
73
|
function transformNumberConstructorCall(context, node, calledMethod) {
|
|
26
74
|
const parameters = (0, call_1.transformArguments)(context, node.arguments);
|
|
27
75
|
const methodName = calledMethod.name.text;
|
|
@@ -30,6 +78,10 @@ function transformNumberConstructorCall(context, node, calledMethod) {
|
|
|
30
78
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsNaN, node, ...parameters);
|
|
31
79
|
case "isFinite":
|
|
32
80
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberIsFinite, node, ...parameters);
|
|
81
|
+
case "parseInt":
|
|
82
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberParseInt, node, ...parameters);
|
|
83
|
+
case "parseFloat":
|
|
84
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberParseFloat, node, ...parameters);
|
|
33
85
|
default:
|
|
34
86
|
context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "Number", methodName));
|
|
35
87
|
}
|
|
@@ -88,6 +88,10 @@ class ResolutionContext {
|
|
|
88
88
|
if (plugin.moduleResolution != null) {
|
|
89
89
|
const pluginResolvedPath = plugin.moduleResolution(dependency, requiringFile.fileName, this.options, this.emitHost);
|
|
90
90
|
if (pluginResolvedPath !== undefined) {
|
|
91
|
+
// If resolved path is absolute no need to further resolve it
|
|
92
|
+
if (path.isAbsolute(pluginResolvedPath)) {
|
|
93
|
+
return pluginResolvedPath;
|
|
94
|
+
}
|
|
91
95
|
// If lua file is in node_module
|
|
92
96
|
if (requiredFromLuaFile && isNodeModulesFile(requiringFile.fileName)) {
|
|
93
97
|
// If requiring file is in lua module, try to resolve sibling in that file first
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|