File size: 92,209 Bytes
369fac9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 |
/*
@license
Rollup.js v4.12.0
Fri, 16 Feb 2024 13:31:42 GMT - commit 0146b84be33a8416b4df4b9382549a7ca19dd64a
https://github.com/rollup/rollup
Released under the MIT License.
*/
'use strict';
const native_js = require('../native.js');
const node_path = require('node:path');
/** @typedef {import('./types').Location} Location */
/**
* @param {import('./types').Range} range
* @param {number} index
*/
function rangeContains(range, index) {
return range.start <= index && index < range.end;
}
/**
* @param {string} source
* @param {import('./types').Options} [options]
*/
function getLocator(source, options = {}) {
const { offsetLine = 0, offsetColumn = 0 } = options;
let start = 0;
const ranges = source.split('\n').map((line, i) => {
const end = start + line.length + 1;
/** @type {import('./types').Range} */
const range = { start, end, line: i };
start = end;
return range;
});
let i = 0;
/**
* @param {string | number} search
* @param {number} [index]
* @returns {Location | undefined}
*/
function locator(search, index) {
if (typeof search === 'string') {
search = source.indexOf(search, index ?? 0);
}
if (search === -1) return undefined;
let range = ranges[i];
const d = search >= range.end ? 1 : -1;
while (range) {
if (rangeContains(range, search)) {
return {
line: offsetLine + range.line,
column: offsetColumn + search - range.start,
character: search
};
}
i += d;
range = ranges[i];
}
}
return locator;
}
/**
* @param {string} source
* @param {string | number} search
* @param {import('./types').Options} [options]
* @returns {Location | undefined}
*/
function locate(source, search, options) {
return getLocator(source, options)(search, options && options.startIndex);
}
function spaces(index) {
let result = '';
while (index--)
result += ' ';
return result;
}
function tabsToSpaces(value) {
return value.replace(/^\t+/, match => match.split('\t').join(' '));
}
const LINE_TRUNCATE_LENGTH = 120;
const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
const ELLIPSIS = '...';
function getCodeFrame(source, line, column) {
let lines = source.split('\n');
// Needed if a plugin did not generate correct sourcemaps
if (line > lines.length)
return '';
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length +
MIN_CHARACTERS_SHOWN_AFTER_LOCATION +
ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
const frameStart = Math.max(0, line - 3);
let frameEnd = Math.min(line + 2, lines.length);
lines = lines.slice(frameStart, frameEnd);
while (!/\S/.test(lines[lines.length - 1])) {
lines.pop();
frameEnd -= 1;
}
const digits = String(frameEnd).length;
return lines
.map((sourceLine, index) => {
const isErrorLine = frameStart + index + 1 === line;
let lineNumber = String(index + frameStart + 1);
while (lineNumber.length < digits)
lineNumber = ` ${lineNumber}`;
let displayedLine = tabsToSpaces(sourceLine);
if (displayedLine.length > maxLineLength) {
displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
}
if (isErrorLine) {
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + '^';
return `${lineNumber}: ${displayedLine}\n${indicator}`;
}
return `${lineNumber}: ${displayedLine}`;
})
.join('\n');
}
const LOGLEVEL_SILENT = 'silent';
const LOGLEVEL_ERROR = 'error';
const LOGLEVEL_WARN = 'warn';
const LOGLEVEL_INFO = 'info';
const LOGLEVEL_DEBUG = 'debug';
const logLevelPriority = {
[LOGLEVEL_DEBUG]: 0,
[LOGLEVEL_INFO]: 1,
[LOGLEVEL_SILENT]: 3,
[LOGLEVEL_WARN]: 2
};
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Za-z]:)?[/\\|])/;
const RELATIVE_PATH_REGEX = /^\.?\.(\/|$)/;
function isAbsolute(path) {
return ABSOLUTE_PATH_REGEX.test(path);
}
function isRelative(path) {
return RELATIVE_PATH_REGEX.test(path);
}
const BACKSLASH_REGEX = /\\/g;
function normalize(path) {
return path.replace(BACKSLASH_REGEX, '/');
}
function printQuotedStringList(list, verbs) {
const isSingleItem = list.length <= 1;
const quotedList = list.map(item => `"${item}"`);
let output = isSingleItem
? quotedList[0]
: `${quotedList.slice(0, -1).join(', ')} and ${quotedList.slice(-1)[0]}`;
if (verbs) {
output += ` ${isSingleItem ? verbs[0] : verbs[1]}`;
}
return output;
}
const ANY_SLASH_REGEX = /[/\\]/;
function relative(from, to) {
const fromParts = from.split(ANY_SLASH_REGEX).filter(Boolean);
const toParts = to.split(ANY_SLASH_REGEX).filter(Boolean);
if (fromParts[0] === '.')
fromParts.shift();
if (toParts[0] === '.')
toParts.shift();
while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) {
fromParts.shift();
toParts.shift();
}
while (toParts[0] === '..' && fromParts.length > 0) {
toParts.shift();
fromParts.pop();
}
while (fromParts.pop()) {
toParts.unshift('..');
}
return toParts.join('/');
}
function getAliasName(id) {
const base = node_path.basename(id);
return base.slice(0, Math.max(0, base.length - node_path.extname(id).length));
}
function relativeId(id) {
if (!isAbsolute(id))
return id;
return relative(node_path.resolve(), id);
}
function isPathFragment(name) {
// starting with "/", "./", "../", "C:/"
return (name[0] === '/' || (name[0] === '.' && (name[1] === '/' || name[1] === '.')) || isAbsolute(name));
}
const UPPER_DIR_REGEX = /^(\.\.\/)*\.\.$/;
function getImportPath(importerId, targetPath, stripJsExtension, ensureFileName) {
while (targetPath.startsWith('../')) {
targetPath = targetPath.slice(3);
importerId = '_/' + importerId;
}
let relativePath = normalize(relative(node_path.dirname(importerId), targetPath));
if (stripJsExtension && relativePath.endsWith('.js')) {
relativePath = relativePath.slice(0, -3);
}
if (ensureFileName) {
if (relativePath === '')
return '../' + node_path.basename(targetPath);
if (UPPER_DIR_REGEX.test(relativePath)) {
return [...relativePath.split('/'), '..', node_path.basename(targetPath)].join('/');
}
}
return relativePath ? (relativePath.startsWith('..') ? relativePath : './' + relativePath) : '.';
}
function isValidUrl(url) {
try {
new URL(url);
}
catch {
return false;
}
return true;
}
function getRollupUrl(snippet) {
return `https://rollupjs.org/${snippet}`;
}
function addTrailingSlashIfMissed(url) {
if (!url.endsWith('/')) {
return url + '/';
}
return url;
}
// troubleshooting
const URL_AVOIDING_EVAL = 'troubleshooting/#avoiding-eval';
const URL_NAME_IS_NOT_EXPORTED = 'troubleshooting/#error-name-is-not-exported-by-module';
const URL_THIS_IS_UNDEFINED = 'troubleshooting/#error-this-is-undefined';
const URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY = 'troubleshooting/#warning-treating-module-as-external-dependency';
const URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT = 'troubleshooting/#warning-sourcemap-is-likely-to-be-incorrect';
const URL_OUTPUT_AMD_ID = 'configuration-options/#output-amd-id';
const URL_OUTPUT_AMD_BASEPATH = 'configuration-options/#output-amd-basepath';
const URL_OUTPUT_DIR = 'configuration-options/#output-dir';
const URL_OUTPUT_EXPORTS = 'configuration-options/#output-exports';
const URL_OUTPUT_EXTEND = 'configuration-options/#output-extend';
const URL_OUTPUT_EXTERNALIMPORTATTRIBUTES = 'configuration-options/#output-externalimportattributes';
const URL_OUTPUT_FORMAT = 'configuration-options/#output-format';
const URL_OUTPUT_GENERATEDCODE = 'configuration-options/#output-generatedcode';
const URL_OUTPUT_GLOBALS = 'configuration-options/#output-globals';
const URL_OUTPUT_INLINEDYNAMICIMPORTS = 'configuration-options/#output-inlinedynamicimports';
const URL_OUTPUT_INTEROP = 'configuration-options/#output-interop';
const URL_OUTPUT_MANUALCHUNKS = 'configuration-options/#output-manualchunks';
const URL_OUTPUT_NAME = 'configuration-options/#output-name';
const URL_OUTPUT_SOURCEMAPBASEURL = 'configuration-options/#output-sourcemapbaseurl';
const URL_OUTPUT_SOURCEMAPFILE = 'configuration-options/#output-sourcemapfile';
const URL_PRESERVEENTRYSIGNATURES = 'configuration-options/#preserveentrysignatures';
const URL_TREESHAKE = 'configuration-options/#treeshake';
const URL_TREESHAKE_PURE = 'configuration-options/#pure';
const URL_TREESHAKE_NOSIDEEFFECTS = 'configuration-options/#no-side-effects';
const URL_TREESHAKE_MODULESIDEEFFECTS = 'configuration-options/#treeshake-modulesideeffects';
const URL_WATCH = 'configuration-options/#watch';
// command-line-interface
const URL_BUNDLE_CONFIG_AS_CJS = 'command-line-interface/#bundleconfigascjs';
const URL_CONFIGURATION_FILES = 'command-line-interface/#configuration-files';
function error(base) {
throw base instanceof Error ? base : getRollupEror(base);
}
function getRollupEror(base) {
const errorInstance = Object.assign(new Error(base.message), base);
Object.defineProperty(errorInstance, 'name', { value: 'RollupError', writable: true });
return errorInstance;
}
function augmentCodeLocation(properties, pos, source, id) {
if (typeof pos === 'object') {
const { line, column } = pos;
properties.loc = { column, file: id, line };
}
else {
properties.pos = pos;
const location = locate(source, pos, { offsetLine: 1 });
if (!location) {
return;
}
const { line, column } = location;
properties.loc = { column, file: id, line };
}
if (properties.frame === undefined) {
const { line, column } = properties.loc;
properties.frame = getCodeFrame(source, line, column);
}
}
// Error codes should be sorted alphabetically while errors should be sorted by
// error code below
const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CONST_REASSIGN = 'CONST_REASSIGN', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_ARGUMENT_NAME = 'DUPLICATE_ARGUMENT_NAME', DUPLICATE_EXPORT = 'DUPLICATE_EXPORT', DUPLICATE_IMPORT_OPTIONS = 'DUPLICATE_IMPORT_OPTIONS', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS = 'EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS', EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES = 'EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FAIL_AFTER_WARNINGS = 'FAIL_AFTER_WARNINGS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', FIRST_SIDE_EFFECT = 'FIRST_SIDE_EFFECT', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INCONSISTENT_IMPORT_ATTRIBUTES = 'INCONSISTENT_IMPORT_ATTRIBUTES', INVALID_ANNOTATION = 'INVALID_ANNOTATION', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_CONFIG_MODULE_FORMAT = 'INVALID_CONFIG_MODULE_FORMAT', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_IMPORT_ATTRIBUTE = 'INVALID_IMPORT_ATTRIBUTE', INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_CONFIG = 'MISSING_CONFIG', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_EXTERNAL_CONFIG = 'MISSING_EXTERNAL_CONFIG', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', ONLY_INLINE_SOURCEMAPS = 'ONLY_INLINE_SOURCEMAPS', OPTIMIZE_CHUNK_STATUS = 'OPTIMIZE_CHUNK_STATUS', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', REDECLARATION_ERROR = 'REDECLARATION_ERROR', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
function logAddonNotGenerated(message, hook, plugin) {
return {
code: ADDON_ERROR,
message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}".
\tError Message: ${message}`
};
}
function logAlreadyClosed() {
return {
code: ALREADY_CLOSED,
message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
};
}
function logAmbiguousExternalNamespaces(binding, reexportingModule, usedModule, sources) {
return {
binding,
code: AMBIGUOUS_EXTERNAL_NAMESPACES,
ids: sources,
message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${binding}" from one of the external modules ${printQuotedStringList(sources.map(module => relativeId(module)))}, guessing "${relativeId(usedModule)}".`,
reexporter: reexportingModule
};
}
function logAnonymousPluginCache() {
return {
code: ANONYMOUS_PLUGIN_CACHE,
message: 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
};
}
function logAssetNotFinalisedForFileName(name) {
return {
code: ASSET_NOT_FINALISED,
message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_<referenceId>, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.`
};
}
function logAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
return {
code: ASSET_NOT_FOUND,
message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
};
}
function logAssetSourceAlreadySet(name) {
return {
code: ASSET_SOURCE_ALREADY_SET,
message: `Unable to set the source for asset "${name}", source already set.`
};
}
function logNoAssetSourceSet(assetName) {
return {
code: ASSET_SOURCE_MISSING,
message: `Plugin error creating asset "${assetName}" - no asset source set.`
};
}
function logBadLoader(id) {
return {
code: BAD_LOADER,
message: `Error loading "${relativeId(id)}": plugin load hook should return a string, a { code, map } object, or nothing/null.`
};
}
function logCannotCallNamespace(name) {
return {
code: CANNOT_CALL_NAMESPACE,
message: `Cannot call a namespace ("${name}").`
};
}
function logCannotEmitFromOptionsHook() {
return {
code: CANNOT_EMIT_FROM_OPTIONS_HOOK,
message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
};
}
function logChunkNotGeneratedForFileName(name) {
return {
code: CHUNK_NOT_GENERATED,
message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
};
}
function logChunkInvalid({ fileName, code }, { pos, message }) {
const errorProperties = {
code: CHUNK_INVALID,
message: `Chunk "${fileName}" is not valid JavaScript: ${message}.`
};
augmentCodeLocation(errorProperties, pos, code, fileName);
return errorProperties;
}
function logCircularDependency(cyclePath) {
return {
code: CIRCULAR_DEPENDENCY,
ids: cyclePath,
message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}`
};
}
function logCircularReexport(exportName, exporter) {
return {
code: CIRCULAR_REEXPORT,
exporter,
message: `"${exportName}" cannot be exported from "${relativeId(exporter)}" as it is a reexport that references itself.`
};
}
function logCyclicCrossChunkReexport(exportName, exporter, reexporter, importer, preserveModules) {
return {
code: CYCLIC_CROSS_CHUNK_REEXPORT,
exporter,
id: importer,
message: `Export "${exportName}" of module "${relativeId(exporter)}" was reexported through module "${relativeId(reexporter)}" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "${relativeId(importer)}" to point directly to the exporting module or ${preserveModules ? 'do not use "output.preserveModules"' : 'reconfigure "output.manualChunks"'} to ensure these modules end up in the same chunk.`,
reexporter
};
}
function logDeprecation(deprecation, urlSnippet, plugin) {
return {
code: DEPRECATED_FEATURE,
message: deprecation,
url: getRollupUrl(urlSnippet),
...(plugin ? { plugin } : {})
};
}
function logConstVariableReassignError() {
return {
code: CONST_REASSIGN,
message: 'Cannot reassign a variable declared with `const`'
};
}
function logDuplicateArgumentNameError(name) {
return { code: DUPLICATE_ARGUMENT_NAME, message: `Duplicate argument name "${name}"` };
}
function logDuplicateExportError(name) {
return { code: DUPLICATE_EXPORT, message: `Duplicate export "${name}"` };
}
function logDuplicateImportOptions() {
return {
code: DUPLICATE_IMPORT_OPTIONS,
message: 'Either use --input, or pass input path as argument'
};
}
function logDuplicatePluginName(plugin) {
return {
code: DUPLICATE_PLUGIN_NAME,
message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
};
}
function logEmptyChunk(chunkName) {
return {
code: EMPTY_BUNDLE,
message: `Generated an empty chunk: "${chunkName}".`,
names: [chunkName]
};
}
function logEval(id) {
return {
code: EVAL,
id,
message: `Use of eval in "${relativeId(id)}" is strongly discouraged as it poses security risks and may cause issues with minification.`,
url: getRollupUrl(URL_AVOIDING_EVAL)
};
}
function logExternalSyntheticExports(id, importer) {
return {
code: EXTERNAL_SYNTHETIC_EXPORTS,
exporter: id,
message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId(importer)}").`
};
}
function logFailAfterWarnings() {
return {
code: FAIL_AFTER_WARNINGS,
message: 'Warnings occurred and --failAfterWarnings flag present.'
};
}
function logFileNameConflict(fileName) {
return {
code: FILE_NAME_CONFLICT,
message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
};
}
function logFileReferenceIdNotFoundForFilename(assetReferenceId) {
return {
code: FILE_NOT_FOUND,
message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
};
}
function logFirstSideEffect(source, id, { line, column }) {
return {
code: FIRST_SIDE_EFFECT,
message: `First side effect in ${relativeId(id)} is at (${line}:${column})\n${getCodeFrame(source, line, column)}`
};
}
function logIllegalIdentifierAsName(name) {
return {
code: ILLEGAL_IDENTIFIER_AS_NAME,
message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`,
url: getRollupUrl(URL_OUTPUT_EXTEND)
};
}
function logIllegalImportReassignment(name, importingId) {
return {
code: ILLEGAL_REASSIGNMENT,
message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".`
};
}
function logInconsistentImportAttributes(existingAttributes, newAttributes, source, importer) {
return {
code: INCONSISTENT_IMPORT_ATTRIBUTES,
message: `Module "${relativeId(importer)}" tried to import "${relativeId(source)}" with ${formatAttributes(newAttributes)} attributes, but it was already imported elsewhere with ${formatAttributes(existingAttributes)} attributes. Please ensure that import attributes for the same module are always consistent.`
};
}
const formatAttributes = (attributes) => {
const entries = Object.entries(attributes);
if (entries.length === 0)
return 'no';
return entries.map(([key, value]) => `"${key}": "${value}"`).join(', ');
};
function logInvalidAnnotation(comment, id, type) {
return {
code: INVALID_ANNOTATION,
id,
message: `A comment\n\n"${comment}"\n\nin "${relativeId(id)}" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.`,
url: getRollupUrl(type === 'noSideEffects' ? URL_TREESHAKE_NOSIDEEFFECTS : URL_TREESHAKE_PURE)
};
}
function logInputHookInOutputPlugin(pluginName, hookName) {
return {
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
};
}
function logCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
return {
code: INVALID_CHUNK,
message: `Cannot assign "${relativeId(moduleId)}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
};
}
function logCannotBundleConfigAsEsm(originalError) {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Rollup transpiled your configuration to an ES module even though it appears to contain CommonJS elements. To resolve this, you can pass the "--bundleConfigAsCjs" flag to Rollup or change your configuration to only contain valid ESM code.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
};
}
function logCannotLoadConfigAsCjs(originalError) {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
};
}
function logCannotLoadConfigAsEsm(originalError) {
return {
cause: originalError,
code: INVALID_CONFIG_MODULE_FORMAT,
message: `Node tried to load your configuration as an ES module even though it is likely CommonJS. To resolve this, change the extension of your configuration to ".cjs" or pass the "--bundleConfigAsCjs" flag.\n\nOriginal error: ${originalError.message}`,
stack: originalError.stack,
url: getRollupUrl(URL_BUNDLE_CONFIG_AS_CJS)
};
}
function logInvalidExportOptionValue(optionValue) {
return {
code: INVALID_EXPORT_OPTION,
message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`,
url: getRollupUrl(URL_OUTPUT_EXPORTS)
};
}
function logIncompatibleExportOptionValue(optionValue, keys, entryModule) {
return {
code: INVALID_EXPORT_OPTION,
message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${printQuotedStringList(keys)}`,
url: getRollupUrl(URL_OUTPUT_EXPORTS)
};
}
function logInternalIdCannotBeExternal(source, importer) {
return {
code: INVALID_EXTERNAL_ID,
message: `"${source}" is imported as an external by "${relativeId(importer)}", but is already an existing non-external module id.`
};
}
function logImportOptionsAreInvalid(importer) {
return {
code: INVALID_IMPORT_ATTRIBUTE,
message: `Rollup could not statically analyze the options argument of a dynamic import in "${relativeId(importer)}". Dynamic import options need to be an object with a nested attributes object.`
};
}
function logImportAttributeIsInvalid(importer) {
return {
code: INVALID_IMPORT_ATTRIBUTE,
message: `Rollup could not statically analyze an import attribute of a dynamic import in "${relativeId(importer)}". Import attributes need to have string keys and values. The attribute will be removed.`
};
}
function logInvalidLogPosition(plugin) {
return {
code: INVALID_LOG_POSITION,
message: `Plugin "${plugin}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
};
}
function logInvalidOption(option, urlSnippet, explanation, value) {
return {
code: INVALID_OPTION,
message: `Invalid value ${value === undefined ? '' : `${JSON.stringify(value)} `}for option "${option}" - ${explanation}.`,
url: getRollupUrl(urlSnippet)
};
}
function logInvalidAddonPluginHook(hook, plugin) {
return {
code: INVALID_PLUGIN_HOOK,
hook,
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
plugin
};
}
function logInvalidFunctionPluginHook(hook, plugin) {
return {
code: INVALID_PLUGIN_HOOK,
hook,
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
plugin
};
}
function logInvalidRollupPhaseForChunkEmission() {
return {
code: INVALID_ROLLUP_PHASE,
message: `Cannot emit chunks after module loading has finished.`
};
}
function logInvalidSetAssetSourceCall() {
return {
code: INVALID_SETASSETSOURCE,
message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
};
}
function logInvalidFormatForTopLevelAwait(id, format) {
return {
code: INVALID_TLA_FORMAT,
id,
message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.`
};
}
function logMissingConfig() {
return {
code: MISSING_CONFIG,
message: 'Config file must export an options object, or an array of options objects',
url: getRollupUrl(URL_CONFIGURATION_FILES)
};
}
function logMissingEntryExport(binding, exporter) {
return {
binding,
code: MISSING_EXPORT,
exporter,
message: `Exported variable "${binding}" is not defined in "${relativeId(exporter)}".`,
url: getRollupUrl(URL_NAME_IS_NOT_EXPORTED)
};
}
function logMissingExport(binding, importingModule, exporter) {
const isJson = node_path.extname(exporter) === '.json';
return {
binding,
code: MISSING_EXPORT,
exporter,
id: importingModule,
message: `"${binding}" is not exported by "${relativeId(exporter)}", imported by "${relativeId(importingModule)}".${isJson ? ' (Note that you need @rollup/plugin-json to import JSON files)' : ''}`,
url: getRollupUrl(URL_NAME_IS_NOT_EXPORTED)
};
}
function logMissingExternalConfig(file) {
return {
code: MISSING_EXTERNAL_CONFIG,
message: `Could not resolve config file "${file}"`
};
}
function logMissingGlobalName(externalId, guess) {
return {
code: MISSING_GLOBAL_NAME,
id: externalId,
message: `No name was provided for external module "${externalId}" in "output.globals" – guessing "${guess}".`,
names: [guess],
url: getRollupUrl(URL_OUTPUT_GLOBALS)
};
}
function logImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
};
}
function logUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
};
}
function logImplicitDependantIsNotIncluded(module) {
const implicitDependencies = [...module.implicitlyLoadedBefore]
.map(dependency => relativeId(dependency.id))
.sort();
return {
code: MISSING_IMPLICIT_DEPENDANT,
message: `Module "${relativeId(module.id)}" that should be implicitly loaded before ${printQuotedStringList(implicitDependencies)} is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
};
}
function logMissingNameOptionForIifeExport() {
return {
code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`,
url: getRollupUrl(URL_OUTPUT_NAME)
};
}
function logMissingNameOptionForUmdExport() {
return {
code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
message: 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.',
url: getRollupUrl(URL_OUTPUT_NAME)
};
}
function logMissingNodeBuiltins(externalBuiltins) {
return {
code: MISSING_NODE_BUILTINS,
ids: externalBuiltins,
message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(externalBuiltins)}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`
};
}
// eslint-disable-next-line unicorn/prevent-abbreviations
function logMissingFileOrDirOption() {
return {
code: MISSING_OPTION,
message: 'You must specify "output.file" or "output.dir" for the build.',
url: getRollupUrl(URL_OUTPUT_DIR)
};
}
function logMixedExport(facadeModuleId, name) {
return {
code: MIXED_EXPORTS,
id: facadeModuleId,
message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}.default\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`,
url: getRollupUrl(URL_OUTPUT_EXPORTS)
};
}
function logModuleLevelDirective(directive, id) {
return {
code: MODULE_LEVEL_DIRECTIVE,
id,
message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId(id)}" was ignored.`
};
}
function logNamespaceConflict(binding, reexportingModuleId, sources) {
return {
binding,
code: NAMESPACE_CONFLICT,
ids: sources,
message: `Conflicting namespaces: "${relativeId(reexportingModuleId)}" re-exports "${binding}" from one of the modules ${printQuotedStringList(sources.map(moduleId => relativeId(moduleId)))} (will be ignored).`,
reexporter: reexportingModuleId
};
}
function logNoTransformMapOrAstWithoutCode(pluginName) {
return {
code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
'a "code". This will be ignored.'
};
}
function logOnlyInlineSourcemapsForStdout() {
return {
code: ONLY_INLINE_SOURCEMAPS,
message: 'Only inline sourcemaps are supported when bundling to stdout.'
};
}
function logOptimizeChunkStatus(chunks, smallChunks, pointInTime) {
return {
code: OPTIMIZE_CHUNK_STATUS,
message: `${pointInTime}, there are\n` +
`${chunks} chunks, of which\n` +
`${smallChunks} are below minChunkSize.`
};
}
function logParseError(message, pos) {
return { code: PARSE_ERROR, message, pos };
}
function logRedeclarationError(name) {
return { code: REDECLARATION_ERROR, message: `Identifier "${name}" has already been declared` };
}
function logModuleParseError(error, moduleId) {
let message = error.message.replace(/ \(\d+:\d+\)$/, '');
if (moduleId.endsWith('.json')) {
message += ' (Note that you need @rollup/plugin-json to import JSON files)';
}
else if (!moduleId.endsWith('.js')) {
message += ' (Note that you need plugins to import files that are not JavaScript)';
}
return {
cause: error,
code: PARSE_ERROR,
id: moduleId,
message,
stack: error.stack
};
}
function logPluginError(error, plugin, { hook, id } = {}) {
const code = error.code;
if (!error.pluginCode &&
code != null &&
(typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
error.pluginCode = code;
}
error.code = PLUGIN_ERROR;
error.plugin = plugin;
if (hook) {
error.hook = hook;
}
if (id) {
error.id = id;
}
return error;
}
function logShimmedExport(id, binding) {
return {
binding,
code: SHIMMED_EXPORT,
exporter: id,
message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".`
};
}
function logSourcemapBroken(plugin) {
return {
code: SOURCEMAP_BROKEN,
message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
plugin,
url: getRollupUrl(URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT)
};
}
function logConflictingSourcemapSources(filename) {
return {
code: SOURCEMAP_BROKEN,
message: `Multiple conflicting contents for sourcemap source ${filename}`
};
}
function logInvalidSourcemapForError(error, id, column, line, pos) {
return {
cause: error,
code: SOURCEMAP_ERROR,
id,
loc: {
column,
file: id,
line
},
message: `Error when using sourcemap for reporting an error: ${error.message}`,
pos
};
}
function logSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
return {
code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
exporter: id,
message: `Module "${relativeId(id)}" that is marked with \`syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}\` needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
? `an explicit export named "${syntheticNamedExportsOption}"`
: 'a default export'} that does not reexport an unresolved named export of the same module.`
};
}
function logThisIsUndefined() {
return {
code: THIS_IS_UNDEFINED,
message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
url: getRollupUrl(URL_THIS_IS_UNDEFINED)
};
}
function logUnexpectedNamedImport(id, imported, isReexport) {
const importType = isReexport ? 'reexport' : 'import';
return {
code: UNEXPECTED_NAMED_IMPORT,
exporter: id,
message: `The named export "${imported}" was ${importType}ed from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
url: getRollupUrl(URL_OUTPUT_INTEROP)
};
}
function logUnexpectedNamespaceReexport(id) {
return {
code: UNEXPECTED_NAMED_IMPORT,
exporter: id,
message: `There was a namespace "*" reexport from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
url: getRollupUrl(URL_OUTPUT_INTEROP)
};
}
function logUnknownOption(optionType, unknownOptions, validOptions) {
return {
code: UNKNOWN_OPTION,
message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${validOptions.join(', ')}`
};
}
function logEntryCannotBeExternal(unresolvedId) {
return {
code: UNRESOLVED_ENTRY,
message: `Entry module "${relativeId(unresolvedId)}" cannot be external.`
};
}
function logExternalModulesCannotBeIncludedInManualChunks(source) {
return {
code: EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS,
message: `"${source}" cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins.`
};
}
function logExternalModulesCannotBeTransformedToModules(source) {
return {
code: EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES,
message: `${source} is resolved as a module now, but it was an external module before. Please check whether there are conflicts in your Rollup options "external" and "manualChunks", manualChunks cannot include external modules.`
};
}
function logUnresolvedEntry(unresolvedId) {
return {
code: UNRESOLVED_ENTRY,
message: `Could not resolve entry module "${relativeId(unresolvedId)}".`
};
}
function logUnresolvedImport(source, importer) {
return {
code: UNRESOLVED_IMPORT,
exporter: source,
id: importer,
message: `Could not resolve "${source}" from "${relativeId(importer)}"`
};
}
function logUnresolvedImportTreatedAsExternal(source, importer) {
return {
code: UNRESOLVED_IMPORT,
exporter: source,
id: importer,
message: `"${source}" is imported by "${relativeId(importer)}", but could not be resolved – treating it as an external dependency.`,
url: getRollupUrl(URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY)
};
}
function logUnusedExternalImports(externalId, names, importers) {
return {
code: UNUSED_EXTERNAL_IMPORT,
exporter: externalId,
ids: importers,
message: `${printQuotedStringList(names, [
'is',
'are'
])} imported from external module "${externalId}" but never used in ${printQuotedStringList(importers.map(importer => relativeId(importer)))}.`,
names
};
}
function logFailedValidation(message) {
return {
code: VALIDATION_ERROR,
message
};
}
function warnDeprecation(deprecation, urlSnippet, activeDeprecation, options, plugin) {
warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, options.onLog, options.strictDeprecations, plugin);
}
function warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, log, strictDeprecations, plugin) {
if (activeDeprecation || strictDeprecations) {
const warning = logDeprecation(deprecation, urlSnippet, plugin);
if (strictDeprecations) {
return error(warning);
}
log(LOGLEVEL_WARN, warning);
}
}
const ArrowFunctionExpression = 'ArrowFunctionExpression';
const BlockStatement = 'BlockStatement';
const CallExpression = 'CallExpression';
const CatchClause = 'CatchClause';
const ExpressionStatement = 'ExpressionStatement';
const Identifier = 'Identifier';
const Literal = 'Literal';
const PanicError = 'PanicError';
const ParseError = 'ParseError';
const Program = 'Program';
const Property = 'Property';
const ReturnStatement = 'ReturnStatement';
const TemplateLiteral = 'TemplateLiteral';
const FIXED_STRINGS = [
'var',
'let',
'const',
'init',
'get',
'set',
'constructor',
'method',
'-',
'+',
'!',
'~',
'typeof',
'void',
'delete',
'++',
'--',
'==',
'!=',
'===',
'!==',
'<',
'<=',
'>',
'>=',
'<<',
'>>',
'>>>',
'+',
'-',
'*',
'/',
'%',
'|',
'^',
'&',
'||',
'&&',
'in',
'instanceof',
'**',
'??',
'=',
'+=',
'-=',
'*=',
'/=',
'%=',
'<<=',
'>>=',
'>>>=',
'|=',
'^=',
'&=',
'**=',
'&&=',
'||=',
'??=',
'pure',
'noSideEffects'
];
const ANNOTATION_KEY = '_rollupAnnotations';
const INVALID_ANNOTATION_KEY = '_rollupRemoved';
const convertAnnotations = (position, buffer) => {
const length = buffer[position++];
const list = [];
for (let index = 0; index < length; index++) {
list.push(convertAnnotation(buffer[position++], buffer));
}
return list;
};
const convertAnnotation = (position, buffer) => {
const start = buffer[position++];
const end = buffer[position++];
const type = FIXED_STRINGS[buffer[position]];
return { end, start, type };
};
const convertString = (position, buffer, readString) => {
const length = buffer[position++];
const bytePosition = position << 2;
return readString(bytePosition, length);
};
// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.
function convertProgram(buffer, readString) {
const node = convertNode(0, new Uint32Array(buffer), readString);
switch (node.type) {
case PanicError: {
return error(getRollupEror(logParseError(node.message)));
}
case ParseError: {
return error(getRollupEror(logParseError(node.message, node.start)));
}
default: {
return node;
}
}
}
/* eslint-disable sort-keys */
const nodeConverters = [
function panicError(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const message = convertString(position, buffer, readString);
return {
type: 'PanicError',
start,
end,
message
};
},
function parseError(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const message = convertString(position, buffer, readString);
return {
type: 'ParseError',
start,
end,
message
};
},
function arrayExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const elements = convertNodeList(position, buffer, readString);
return {
type: 'ArrayExpression',
start,
end,
elements
};
},
function arrayPattern(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const elements = convertNodeList(position, buffer, readString);
return {
type: 'ArrayPattern',
start,
end,
elements
};
},
function arrowFunctionExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const async = (flags & 1) === 1;
const expression = (flags & 2) === 2;
const generator = (flags & 4) === 4;
const parameters = convertNodeList(buffer[position++], buffer, readString);
const body = convertNode(buffer[position++], buffer, readString);
const annotations = convertAnnotations(position, buffer);
return {
type: 'ArrowFunctionExpression',
start,
end,
async,
expression,
generator,
...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
params: parameters,
body,
id: null
};
},
function assignmentExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const operator = FIXED_STRINGS[buffer[position++]];
const right = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'AssignmentExpression',
start,
end,
operator,
left,
right
};
},
function assignmentPattern(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const right = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'AssignmentPattern',
start,
end,
left,
right
};
},
function awaitExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const argument = convertNode(position, buffer, readString);
return {
type: 'AwaitExpression',
start,
end,
argument
};
},
function binaryExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const operator = FIXED_STRINGS[buffer[position++]];
const right = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'BinaryExpression',
start,
end,
operator,
left,
right
};
},
function blockStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const body = convertNodeList(position, buffer, readString);
return {
type: 'BlockStatement',
start,
end,
body
};
},
function breakStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const labelPosition = buffer[position];
const label = labelPosition === 0 ? null : convertNode(labelPosition, buffer, readString);
return {
type: 'BreakStatement',
start,
end,
label
};
},
function callExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const optional = (flags & 1) === 1;
const callee = convertNode(buffer[position++], buffer, readString);
const callArguments = convertNodeList(buffer[position++], buffer, readString);
const annotations = convertAnnotations(position, buffer);
return {
type: 'CallExpression',
start,
end,
optional,
...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
callee,
arguments: callArguments
};
},
function catchClause(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const parameterPosition = buffer[position++];
const parameter = parameterPosition === 0 ? null : convertNode(parameterPosition, buffer, readString);
const body = convertNode(buffer[position], buffer, readString);
return {
type: 'CatchClause',
start,
end,
param: parameter,
body
};
},
function chainExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const expression = convertNode(position, buffer, readString);
return {
type: 'ChainExpression',
start,
end,
expression
};
},
function classBody(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const body = convertNodeList(position, buffer, readString);
return {
type: 'ClassBody',
start,
end,
body
};
},
function classDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const idPosition = buffer[position++];
const id = idPosition === 0 ? null : convertNode(idPosition, buffer, readString);
const superClassPosition = buffer[position++];
const superClass = superClassPosition === 0 ? null : convertNode(superClassPosition, buffer, readString);
const body = convertNode(buffer[position], buffer, readString);
return {
type: 'ClassDeclaration',
start,
end,
id,
superClass,
body
};
},
function classExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const idPosition = buffer[position++];
const id = idPosition === 0 ? null : convertNode(idPosition, buffer, readString);
const superClassPosition = buffer[position++];
const superClass = superClassPosition === 0 ? null : convertNode(superClassPosition, buffer, readString);
const body = convertNode(buffer[position], buffer, readString);
return {
type: 'ClassExpression',
start,
end,
id,
superClass,
body
};
},
function conditionalExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const consequent = convertNode(buffer[position++], buffer, readString);
const alternate = convertNode(buffer[position++], buffer, readString);
const test = convertNode(position, buffer, readString);
return {
type: 'ConditionalExpression',
start,
end,
test,
consequent,
alternate
};
},
function continueStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const labelPosition = buffer[position];
const label = labelPosition === 0 ? null : convertNode(labelPosition, buffer, readString);
return {
type: 'ContinueStatement',
start,
end,
label
};
},
function debuggerStatement(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
return {
type: 'DebuggerStatement',
start,
end
};
},
function directive(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const expression = convertNode(buffer[position++], buffer, readString);
const directive = convertString(position, buffer, readString);
return {
type: 'ExpressionStatement',
start,
end,
directive,
expression
};
},
function doWhileStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const test = convertNode(buffer[position++], buffer, readString);
const body = convertNode(position, buffer, readString);
return {
type: 'DoWhileStatement',
start,
end,
body,
test
};
},
function emptyStatement(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
return {
type: 'EmptyStatement',
start,
end
};
},
function exportAllDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const exportedPosition = buffer[position++];
const exported = exportedPosition === 0 ? null : convertNode(exportedPosition, buffer, readString);
const source = convertNode(buffer[position++], buffer, readString);
const attributes = convertNodeList(buffer[position], buffer, readString);
return {
type: 'ExportAllDeclaration',
start,
end,
exported,
source,
attributes
};
},
function exportDefaultDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const declaration = convertNode(position, buffer, readString);
return {
type: 'ExportDefaultDeclaration',
start,
end,
declaration
};
},
function exportNamedDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const sourcePosition = buffer[position++];
const source = sourcePosition === 0 ? null : convertNode(sourcePosition, buffer, readString);
const attributes = convertNodeList(buffer[position++], buffer, readString);
const declarationPosition = buffer[position++];
const declaration = declarationPosition === 0 ? null : convertNode(declarationPosition, buffer, readString);
const specifiers = convertNodeList(position, buffer, readString);
return {
type: 'ExportNamedDeclaration',
start,
end,
specifiers,
source,
attributes,
declaration
};
},
function exportSpecifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const exportedPosition = buffer[position++];
const local = convertNode(position, buffer, readString);
return {
type: 'ExportSpecifier',
start,
end,
local,
exported: exportedPosition === 0 ? { ...local } : convertNode(exportedPosition, buffer, readString)
};
},
function expressionStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const expression = convertNode(position, buffer, readString);
return {
type: 'ExpressionStatement',
start,
end,
expression
};
},
function forInStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const right = convertNode(buffer[position++], buffer, readString);
const body = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'ForInStatement',
start,
end,
left,
right,
body
};
},
function forOfStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const awaited = (flags & 1) === 1;
const right = convertNode(buffer[position++], buffer, readString);
const body = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'ForOfStatement',
start,
end,
await: awaited,
left,
right,
body
};
},
function forStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const initPosition = buffer[position++];
const init = initPosition === 0 ? null : convertNode(initPosition, buffer, readString);
const testPosition = buffer[position++];
const test = testPosition === 0 ? null : convertNode(testPosition, buffer, readString);
const updatePosition = buffer[position++];
const update = updatePosition === 0 ? null : convertNode(updatePosition, buffer, readString);
const body = convertNode(buffer[position], buffer, readString);
return {
type: 'ForStatement',
start,
end,
init,
test,
update,
body
};
},
function functionDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const async = (flags & 1) === 1;
const generator = (flags & 2) === 2;
const idPosition = buffer[position++];
const id = idPosition === 0 ? null : convertNode(idPosition, buffer, readString);
const parameters = convertNodeList(buffer[position++], buffer, readString);
const body = convertNode(buffer[position++], buffer, readString);
const annotations = convertAnnotations(position, buffer);
return {
type: 'FunctionDeclaration',
start,
end,
async,
generator,
...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
id,
params: parameters,
body,
expression: false
};
},
function functionExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const async = (flags & 1) === 1;
const generator = (flags & 2) === 2;
const idPosition = buffer[position++];
const id = idPosition === 0 ? null : convertNode(idPosition, buffer, readString);
const parameters = convertNodeList(buffer[position++], buffer, readString);
const body = convertNode(buffer[position++], buffer, readString);
const annotations = convertAnnotations(position, buffer);
return {
type: 'FunctionExpression',
start,
end,
async,
generator,
...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
id,
params: parameters,
body,
expression: false
};
},
function identifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const name = convertString(position, buffer, readString);
return {
type: 'Identifier',
start,
end,
name
};
},
function ifStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const consequent = convertNode(buffer[position++], buffer, readString);
const alternatePosition = buffer[position++];
const alternate = alternatePosition === 0 ? null : convertNode(alternatePosition, buffer, readString);
const test = convertNode(position, buffer, readString);
return {
type: 'IfStatement',
start,
end,
test,
consequent,
alternate
};
},
function importAttribute(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const value = convertNode(buffer[position++], buffer, readString);
const key = convertNode(position, buffer, readString);
return {
type: 'ImportAttribute',
start,
end,
key,
value
};
},
function importDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const source = convertNode(buffer[position++], buffer, readString);
const attributes = convertNodeList(buffer[position++], buffer, readString);
const specifiers = convertNodeList(position, buffer, readString);
return {
type: 'ImportDeclaration',
start,
end,
specifiers,
source,
attributes
};
},
function importDefaultSpecifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const local = convertNode(position, buffer, readString);
return {
type: 'ImportDefaultSpecifier',
start,
end,
local
};
},
function importExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const optionsPosition = buffer[position++];
const options = optionsPosition === 0 ? null : convertNode(optionsPosition, buffer, readString);
const source = convertNode(position, buffer, readString);
return {
type: 'ImportExpression',
start,
end,
source,
options
};
},
function importNamespaceSpecifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const local = convertNode(position, buffer, readString);
return {
type: 'ImportNamespaceSpecifier',
start,
end,
local
};
},
function importSpecifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const importedPosition = buffer[position++];
const local = convertNode(buffer[position], buffer, readString);
return {
type: 'ImportSpecifier',
start,
end,
imported: importedPosition === 0 ? { ...local } : convertNode(importedPosition, buffer, readString),
local
};
},
function labeledStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const body = convertNode(buffer[position++], buffer, readString);
const label = convertNode(position, buffer, readString);
return {
type: 'LabeledStatement',
start,
end,
label,
body
};
},
function literalBigInt(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const raw = convertString(buffer[position++], buffer, readString);
const bigint = convertString(position, buffer, readString);
return {
type: 'Literal',
start,
end,
bigint,
raw,
value: BigInt(bigint)
};
},
function literalBoolean(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const value = (flags & 1) === 1;
return {
type: 'Literal',
start,
end,
value,
raw: value ? 'true' : 'false'
};
},
function literalNull(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
return {
type: 'Literal',
start,
end,
raw: 'null',
value: null
};
},
function literalNumber(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const rawPosition = buffer[position++];
const raw = rawPosition === 0 ? undefined : convertString(rawPosition, buffer, readString);
const value = new DataView(buffer.buffer).getFloat64(position << 2, true);
return {
type: 'Literal',
start,
end,
raw,
value
};
},
function literalRegExp(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const pattern = convertString(buffer[position++], buffer, readString);
const flags = convertString(position, buffer, readString);
return {
type: 'Literal',
start,
end,
raw: `/${pattern}/${flags}`,
regex: { flags, pattern },
value: new RegExp(pattern, flags)
};
},
function literalString(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const rawPosition = buffer[position++];
const raw = rawPosition === 0 ? undefined : convertString(rawPosition, buffer, readString);
const value = convertString(position, buffer, readString);
return {
type: 'Literal',
start,
end,
value,
raw
};
},
function logicalExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const operator = FIXED_STRINGS[buffer[position++]];
const right = convertNode(buffer[position++], buffer, readString);
const left = convertNode(position, buffer, readString);
return {
type: 'LogicalExpression',
start,
end,
operator,
left,
right
};
},
function memberExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const computed = (flags & 1) === 1;
const optional = (flags & 2) === 2;
const property = convertNode(buffer[position++], buffer, readString);
const object = convertNode(position, buffer, readString);
return {
type: 'MemberExpression',
start,
end,
computed,
optional,
object,
property
};
},
function metaProperty(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const property = convertNode(buffer[position++], buffer, readString);
const meta = convertNode(position, buffer, readString);
return {
type: 'MetaProperty',
start,
end,
meta,
property
};
},
function methodDefinition(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const isStatic = (flags & 1) === 1;
const computed = (flags & 2) === 2;
const value = convertNode(buffer[position++], buffer, readString);
const kind = FIXED_STRINGS[buffer[position++]];
const key = convertNode(position, buffer, readString);
return {
type: 'MethodDefinition',
start,
end,
static: isStatic,
computed,
key,
value,
kind
};
},
function newExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const callee = convertNode(buffer[position++], buffer, readString);
const callArguments = convertNodeList(buffer[position++], buffer, readString);
const annotations = convertAnnotations(position, buffer);
return {
type: 'NewExpression',
start,
end,
...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
callee,
arguments: callArguments
};
},
function objectExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const properties = convertNodeList(position, buffer, readString);
return {
type: 'ObjectExpression',
start,
end,
properties
};
},
function objectPattern(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const properties = convertNodeList(position, buffer, readString);
return {
type: 'ObjectPattern',
start,
end,
properties
};
},
function privateIdentifier(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const name = convertString(position, buffer, readString);
return {
type: 'PrivateIdentifier',
start,
end,
name
};
},
function program(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const invalidAnnotations = convertAnnotations(buffer[position++], buffer);
const body = convertNodeList(position, buffer, readString);
return {
type: 'Program',
start,
end,
body,
...(invalidAnnotations.length > 0 ? { [INVALID_ANNOTATION_KEY]: invalidAnnotations } : {}),
sourceType: 'module'
};
},
function property(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const method = (flags & 1) === 1;
const shorthand = (flags & 2) === 2;
const computed = (flags & 4) === 4;
const keyPosition = buffer[position++];
const value = convertNode(buffer[position++], buffer, readString);
const kind = FIXED_STRINGS[buffer[position]];
return {
type: 'Property',
start,
end,
method,
shorthand,
computed,
key: keyPosition === 0 ? { ...value } : convertNode(keyPosition, buffer, readString),
value,
kind
};
},
function propertyDefinition(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const isStatic = (flags & 1) === 1;
const computed = (flags & 2) === 2;
const valuePosition = buffer[position++];
const value = valuePosition === 0 ? null : convertNode(valuePosition, buffer, readString);
const key = convertNode(position, buffer, readString);
return {
type: 'PropertyDefinition',
start,
end,
static: isStatic,
computed,
key,
value
};
},
function restElement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const argument = convertNode(position, buffer, readString);
return {
type: 'RestElement',
start,
end,
argument
};
},
function returnStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const argumentPosition = buffer[position];
const argument = argumentPosition === 0 ? null : convertNode(argumentPosition, buffer, readString);
return {
type: 'ReturnStatement',
start,
end,
argument
};
},
function sequenceExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const expressions = convertNodeList(position, buffer, readString);
return {
type: 'SequenceExpression',
start,
end,
expressions
};
},
function spreadElement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const argument = convertNode(position, buffer, readString);
return {
type: 'SpreadElement',
start,
end,
argument
};
},
function staticBlock(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const body = convertNodeList(position, buffer, readString);
return {
type: 'StaticBlock',
start,
end,
body
};
},
function superElement(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
return {
type: 'Super',
start,
end
};
},
function switchCase(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const testPosition = buffer[position++];
const test = testPosition === 0 ? null : convertNode(testPosition, buffer, readString);
const consequent = convertNodeList(buffer[position], buffer, readString);
return {
type: 'SwitchCase',
start,
end,
test,
consequent
};
},
function switchStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const cases = convertNodeList(buffer[position++], buffer, readString);
const discriminant = convertNode(position, buffer, readString);
return {
type: 'SwitchStatement',
start,
end,
discriminant,
cases
};
},
function taggedTemplateExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const quasi = convertNode(buffer[position++], buffer, readString);
const tag = convertNode(position, buffer, readString);
return {
type: 'TaggedTemplateExpression',
start,
end,
tag,
quasi
};
},
function templateElement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const tail = (flags & 1) === 1;
const cookedPosition = buffer[position++];
const cooked = cookedPosition === 0 ? undefined : convertString(cookedPosition, buffer, readString);
const raw = convertString(position, buffer, readString);
return {
type: 'TemplateElement',
start,
end,
tail,
value: { cooked, raw }
};
},
function templateLiteral(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const expressions = convertNodeList(buffer[position++], buffer, readString);
const quasis = convertNodeList(position, buffer, readString);
return {
type: 'TemplateLiteral',
start,
end,
quasis,
expressions
};
},
function thisExpression(position, buffer) {
const start = buffer[position++];
const end = buffer[position++];
return {
type: 'ThisExpression',
start,
end
};
},
function throwStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const argument = convertNode(position, buffer, readString);
return {
type: 'ThrowStatement',
start,
end,
argument
};
},
function tryStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const handlerPosition = buffer[position++];
const handler = handlerPosition === 0 ? null : convertNode(handlerPosition, buffer, readString);
const finalizerPosition = buffer[position++];
const finalizer = finalizerPosition === 0 ? null : convertNode(finalizerPosition, buffer, readString);
const block = convertNode(position, buffer, readString);
return {
type: 'TryStatement',
start,
end,
block,
handler,
finalizer
};
},
function unaryExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const operator = FIXED_STRINGS[buffer[position++]];
const argument = convertNode(position, buffer, readString);
return {
type: 'UnaryExpression',
start,
end,
operator,
argument,
prefix: true
};
},
function updateExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const prefix = (flags & 1) === 1;
const operator = FIXED_STRINGS[buffer[position++]];
const argument = convertNode(position, buffer, readString);
return {
type: 'UpdateExpression',
start,
end,
prefix,
operator,
argument
};
},
function variableDeclaration(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const kind = FIXED_STRINGS[buffer[position++]];
const declarations = convertNodeList(position, buffer, readString);
return {
type: 'VariableDeclaration',
start,
end,
kind,
declarations
};
},
function variableDeclarator(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const initPosition = buffer[position++];
const init = initPosition === 0 ? null : convertNode(initPosition, buffer, readString);
const id = convertNode(position, buffer, readString);
return {
type: 'VariableDeclarator',
start,
end,
id,
init
};
},
function whileStatement(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const body = convertNode(buffer[position++], buffer, readString);
const test = convertNode(position, buffer, readString);
return {
type: 'WhileStatement',
start,
end,
test,
body
};
},
function yieldExpression(position, buffer, readString) {
const start = buffer[position++];
const end = buffer[position++];
const flags = buffer[position++];
const delegate = (flags & 1) === 1;
const argumentPosition = buffer[position];
const argument = argumentPosition === 0 ? null : convertNode(argumentPosition, buffer, readString);
return {
type: 'YieldExpression',
start,
end,
delegate,
argument
};
}
];
function convertNode(position, buffer, readString) {
const nodeType = buffer[position];
const converter = nodeConverters[nodeType];
/* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
if (!converter) {
console.trace();
throw new Error(`Unknown node type: ${nodeType}`);
}
return converter(position + 1, buffer, readString);
}
function convertNodeList(position, buffer, readString) {
const length = buffer[position++];
const list = [];
for (let index = 0; index < length; index++) {
const nodePosition = buffer[position++];
list.push(nodePosition ? convertNode(nodePosition, buffer, readString) : null);
}
return list;
}
function getReadStringFunction(astBuffer) {
if (typeof Buffer !== 'undefined' && astBuffer instanceof Buffer) {
return function readString(start, length) {
return astBuffer.toString('utf8', start, start + length);
};
}
else {
const textDecoder = new TextDecoder();
return function readString(start, length) {
return textDecoder.decode(astBuffer.subarray(start, start + length));
};
}
}
const parseAst = (input, { allowReturnOutsideFunction = false } = {}) => {
const astBuffer = native_js.parse(input, allowReturnOutsideFunction);
return convertProgram(astBuffer.buffer, getReadStringFunction(astBuffer));
};
const parseAstAsync = async (input, { allowReturnOutsideFunction = false, signal } = {}) => {
const astBuffer = await native_js.parseAsync(input, allowReturnOutsideFunction, signal);
return convertProgram(astBuffer.buffer, getReadStringFunction(astBuffer));
};
exports.ANNOTATION_KEY = ANNOTATION_KEY;
exports.ArrowFunctionExpression = ArrowFunctionExpression;
exports.BlockStatement = BlockStatement;
exports.CallExpression = CallExpression;
exports.CatchClause = CatchClause;
exports.ExpressionStatement = ExpressionStatement;
exports.FIXED_STRINGS = FIXED_STRINGS;
exports.INVALID_ANNOTATION_KEY = INVALID_ANNOTATION_KEY;
exports.Identifier = Identifier;
exports.LOGLEVEL_DEBUG = LOGLEVEL_DEBUG;
exports.LOGLEVEL_ERROR = LOGLEVEL_ERROR;
exports.LOGLEVEL_INFO = LOGLEVEL_INFO;
exports.LOGLEVEL_WARN = LOGLEVEL_WARN;
exports.Literal = Literal;
exports.Program = Program;
exports.Property = Property;
exports.ReturnStatement = ReturnStatement;
exports.TemplateLiteral = TemplateLiteral;
exports.URL_AVOIDING_EVAL = URL_AVOIDING_EVAL;
exports.URL_NAME_IS_NOT_EXPORTED = URL_NAME_IS_NOT_EXPORTED;
exports.URL_OUTPUT_AMD_BASEPATH = URL_OUTPUT_AMD_BASEPATH;
exports.URL_OUTPUT_AMD_ID = URL_OUTPUT_AMD_ID;
exports.URL_OUTPUT_DIR = URL_OUTPUT_DIR;
exports.URL_OUTPUT_EXPORTS = URL_OUTPUT_EXPORTS;
exports.URL_OUTPUT_EXTERNALIMPORTATTRIBUTES = URL_OUTPUT_EXTERNALIMPORTATTRIBUTES;
exports.URL_OUTPUT_FORMAT = URL_OUTPUT_FORMAT;
exports.URL_OUTPUT_GENERATEDCODE = URL_OUTPUT_GENERATEDCODE;
exports.URL_OUTPUT_GLOBALS = URL_OUTPUT_GLOBALS;
exports.URL_OUTPUT_INLINEDYNAMICIMPORTS = URL_OUTPUT_INLINEDYNAMICIMPORTS;
exports.URL_OUTPUT_INTEROP = URL_OUTPUT_INTEROP;
exports.URL_OUTPUT_MANUALCHUNKS = URL_OUTPUT_MANUALCHUNKS;
exports.URL_OUTPUT_SOURCEMAPBASEURL = URL_OUTPUT_SOURCEMAPBASEURL;
exports.URL_OUTPUT_SOURCEMAPFILE = URL_OUTPUT_SOURCEMAPFILE;
exports.URL_PRESERVEENTRYSIGNATURES = URL_PRESERVEENTRYSIGNATURES;
exports.URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT = URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT;
exports.URL_THIS_IS_UNDEFINED = URL_THIS_IS_UNDEFINED;
exports.URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY = URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY;
exports.URL_TREESHAKE = URL_TREESHAKE;
exports.URL_TREESHAKE_MODULESIDEEFFECTS = URL_TREESHAKE_MODULESIDEEFFECTS;
exports.URL_WATCH = URL_WATCH;
exports.addTrailingSlashIfMissed = addTrailingSlashIfMissed;
exports.augmentCodeLocation = augmentCodeLocation;
exports.convertAnnotations = convertAnnotations;
exports.convertNode = convertNode;
exports.convertString = convertString;
exports.error = error;
exports.getAliasName = getAliasName;
exports.getImportPath = getImportPath;
exports.getReadStringFunction = getReadStringFunction;
exports.getRollupEror = getRollupEror;
exports.getRollupUrl = getRollupUrl;
exports.isAbsolute = isAbsolute;
exports.isPathFragment = isPathFragment;
exports.isRelative = isRelative;
exports.isValidUrl = isValidUrl;
exports.locate = locate;
exports.logAddonNotGenerated = logAddonNotGenerated;
exports.logAlreadyClosed = logAlreadyClosed;
exports.logAmbiguousExternalNamespaces = logAmbiguousExternalNamespaces;
exports.logAnonymousPluginCache = logAnonymousPluginCache;
exports.logAssetNotFinalisedForFileName = logAssetNotFinalisedForFileName;
exports.logAssetReferenceIdNotFoundForSetSource = logAssetReferenceIdNotFoundForSetSource;
exports.logAssetSourceAlreadySet = logAssetSourceAlreadySet;
exports.logBadLoader = logBadLoader;
exports.logCannotAssignModuleToChunk = logCannotAssignModuleToChunk;
exports.logCannotBundleConfigAsEsm = logCannotBundleConfigAsEsm;
exports.logCannotCallNamespace = logCannotCallNamespace;
exports.logCannotEmitFromOptionsHook = logCannotEmitFromOptionsHook;
exports.logCannotLoadConfigAsCjs = logCannotLoadConfigAsCjs;
exports.logCannotLoadConfigAsEsm = logCannotLoadConfigAsEsm;
exports.logChunkInvalid = logChunkInvalid;
exports.logChunkNotGeneratedForFileName = logChunkNotGeneratedForFileName;
exports.logCircularDependency = logCircularDependency;
exports.logCircularReexport = logCircularReexport;
exports.logConflictingSourcemapSources = logConflictingSourcemapSources;
exports.logConstVariableReassignError = logConstVariableReassignError;
exports.logCyclicCrossChunkReexport = logCyclicCrossChunkReexport;
exports.logDuplicateArgumentNameError = logDuplicateArgumentNameError;
exports.logDuplicateExportError = logDuplicateExportError;
exports.logDuplicateImportOptions = logDuplicateImportOptions;
exports.logDuplicatePluginName = logDuplicatePluginName;
exports.logEmptyChunk = logEmptyChunk;
exports.logEntryCannotBeExternal = logEntryCannotBeExternal;
exports.logEval = logEval;
exports.logExternalModulesCannotBeIncludedInManualChunks = logExternalModulesCannotBeIncludedInManualChunks;
exports.logExternalModulesCannotBeTransformedToModules = logExternalModulesCannotBeTransformedToModules;
exports.logExternalSyntheticExports = logExternalSyntheticExports;
exports.logFailAfterWarnings = logFailAfterWarnings;
exports.logFailedValidation = logFailedValidation;
exports.logFileNameConflict = logFileNameConflict;
exports.logFileReferenceIdNotFoundForFilename = logFileReferenceIdNotFoundForFilename;
exports.logFirstSideEffect = logFirstSideEffect;
exports.logIllegalIdentifierAsName = logIllegalIdentifierAsName;
exports.logIllegalImportReassignment = logIllegalImportReassignment;
exports.logImplicitDependantCannotBeExternal = logImplicitDependantCannotBeExternal;
exports.logImplicitDependantIsNotIncluded = logImplicitDependantIsNotIncluded;
exports.logImportAttributeIsInvalid = logImportAttributeIsInvalid;
exports.logImportOptionsAreInvalid = logImportOptionsAreInvalid;
exports.logIncompatibleExportOptionValue = logIncompatibleExportOptionValue;
exports.logInconsistentImportAttributes = logInconsistentImportAttributes;
exports.logInputHookInOutputPlugin = logInputHookInOutputPlugin;
exports.logInternalIdCannotBeExternal = logInternalIdCannotBeExternal;
exports.logInvalidAddonPluginHook = logInvalidAddonPluginHook;
exports.logInvalidAnnotation = logInvalidAnnotation;
exports.logInvalidExportOptionValue = logInvalidExportOptionValue;
exports.logInvalidFormatForTopLevelAwait = logInvalidFormatForTopLevelAwait;
exports.logInvalidFunctionPluginHook = logInvalidFunctionPluginHook;
exports.logInvalidLogPosition = logInvalidLogPosition;
exports.logInvalidOption = logInvalidOption;
exports.logInvalidRollupPhaseForChunkEmission = logInvalidRollupPhaseForChunkEmission;
exports.logInvalidSetAssetSourceCall = logInvalidSetAssetSourceCall;
exports.logInvalidSourcemapForError = logInvalidSourcemapForError;
exports.logLevelPriority = logLevelPriority;
exports.logMissingConfig = logMissingConfig;
exports.logMissingEntryExport = logMissingEntryExport;
exports.logMissingExport = logMissingExport;
exports.logMissingExternalConfig = logMissingExternalConfig;
exports.logMissingFileOrDirOption = logMissingFileOrDirOption;
exports.logMissingGlobalName = logMissingGlobalName;
exports.logMissingNameOptionForIifeExport = logMissingNameOptionForIifeExport;
exports.logMissingNameOptionForUmdExport = logMissingNameOptionForUmdExport;
exports.logMissingNodeBuiltins = logMissingNodeBuiltins;
exports.logMixedExport = logMixedExport;
exports.logModuleLevelDirective = logModuleLevelDirective;
exports.logModuleParseError = logModuleParseError;
exports.logNamespaceConflict = logNamespaceConflict;
exports.logNoAssetSourceSet = logNoAssetSourceSet;
exports.logNoTransformMapOrAstWithoutCode = logNoTransformMapOrAstWithoutCode;
exports.logOnlyInlineSourcemapsForStdout = logOnlyInlineSourcemapsForStdout;
exports.logOptimizeChunkStatus = logOptimizeChunkStatus;
exports.logParseError = logParseError;
exports.logPluginError = logPluginError;
exports.logRedeclarationError = logRedeclarationError;
exports.logShimmedExport = logShimmedExport;
exports.logSourcemapBroken = logSourcemapBroken;
exports.logSyntheticNamedExportsNeedNamespaceExport = logSyntheticNamedExportsNeedNamespaceExport;
exports.logThisIsUndefined = logThisIsUndefined;
exports.logUnexpectedNamedImport = logUnexpectedNamedImport;
exports.logUnexpectedNamespaceReexport = logUnexpectedNamespaceReexport;
exports.logUnknownOption = logUnknownOption;
exports.logUnresolvedEntry = logUnresolvedEntry;
exports.logUnresolvedImplicitDependant = logUnresolvedImplicitDependant;
exports.logUnresolvedImport = logUnresolvedImport;
exports.logUnresolvedImportTreatedAsExternal = logUnresolvedImportTreatedAsExternal;
exports.logUnusedExternalImports = logUnusedExternalImports;
exports.normalize = normalize;
exports.parseAst = parseAst;
exports.parseAstAsync = parseAstAsync;
exports.printQuotedStringList = printQuotedStringList;
exports.relative = relative;
exports.relativeId = relativeId;
exports.warnDeprecation = warnDeprecation;
//# sourceMappingURL=parseAst.js.map
|