File size: 64,894 Bytes
6b62834 | 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 | //#region src/binding.d.cts
type MaybePromise<T> = T | Promise<T>;
type VoidNullable<T = void> = T | null | undefined | void;
type BindingStringOrRegex = string | RegExp;
interface CodegenOptions {
/**
* Remove whitespace.
*
* @default true
*/
removeWhitespace?: boolean;
/**
* How to handle legal comments (comments containing `@license`, `@preserve`, or starting with `//!`/`/*!`).
*
* * `"none"` - Do not preserve any legal comments.
* * `"inline"` - Preserve all legal comments inline.
* * `"eof"` - Move all legal comments to the end of the file.
* * `"external"` - Extract legal comments without linking.
* * `{ linked: "path/to/legal.txt" }` - Extract legal comments and add a link comment to the given path.
*
* @default "none" (when minifying)
*/
legalComments?: 'none' | 'inline' | 'eof' | 'external' | {
linked: string;
};
}
interface CompressOptions {
/**
* Set desired EcmaScript standard version for output.
*
* Set `esnext` to enable all target highering.
*
* Example:
*
* * `'es2015'`
* * `['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']`
*
* @default 'esnext'
*
* @see [oxc#target](https://oxc.rs/docs/guide/usage/transformer/lowering#target)
*/
target?: string | Array<string>;
/**
* Pass true to discard calls to `console.*`.
*
* @default false
*/
dropConsole?: boolean;
/**
* Remove `debugger;` statements.
*
* @default true
*/
dropDebugger?: boolean;
/**
* Pass `true` to drop unreferenced functions and variables.
*
* Simple direct variable assignments do not count as references unless set to `keep_assign`.
* @default true
*/
unused?: boolean | 'keep_assign';
/** Keep function / class names. */
keepNames?: CompressOptionsKeepNames;
/**
* Join consecutive var, let and const statements.
*
* @default true
*/
joinVars?: boolean;
/**
* Join consecutive simple statements using the comma operator.
*
* `a; b` -> `a, b`
*
* @default true
*/
sequences?: boolean;
/**
* Set of label names to drop from the code.
*
* Labeled statements matching these names will be removed during minification.
*
* @default []
*/
dropLabels?: Array<string>;
/** Limit the maximum number of iterations for debugging purpose. */
maxIterations?: number;
/** Treeshake options. */
treeshake?: TreeShakeOptions;
}
interface CompressOptionsKeepNames {
/**
* Keep function names so that `Function.prototype.name` is preserved.
*
* This does not guarantee that the `undefined` name is preserved.
*
* @default false
*/
function: boolean;
/**
* Keep class names so that `Class.prototype.name` is preserved.
*
* This does not guarantee that the `undefined` name is preserved.
*
* @default false
*/
class: boolean;
}
interface MangleOptions {
/**
* Pass `true` to mangle names declared in the top level scope.
*
* @default true for modules and commonjs, otherwise false
*/
toplevel?: boolean;
/**
* Preserve `name` property for functions and classes.
*
* @default false
*/
keepNames?: boolean | MangleOptionsKeepNames;
/**
* Names that bindings must not be renamed to, and that bindings already
* carrying them keep. Equivalent to terser's `mangle.reserved`.
*
* Pass `['exports', 'module']` when minifying prebuilt CommonJS / UMD files
* that Node consumers `import` directly, so Node's cjs-module-lexer can still
* detect the mangled module's named exports.
*
* @default []
*/
reserved?: Array<string>;
/** Debug mangled names. */
debug?: boolean;
}
interface MangleOptionsKeepNames {
/**
* Preserve `name` property for functions.
*
* @default false
*/
function: boolean;
/**
* Preserve `name` property for classes.
*
* @default false
*/
class: boolean;
}
interface MinifyOptions {
/** Use when minifying an ES module. */
module?: boolean;
compress?: boolean | CompressOptions;
mangle?: boolean | MangleOptions;
codegen?: boolean | CodegenOptions;
sourcemap?: boolean;
}
interface MinifyResult {
code: string;
map?: SourceMap;
errors: Array<OxcError>;
/**
* Legal comments extracted from the source code.
* Only populated when `codegen.legalComments` is `"linked"` or `"external"`.
*/
legalComments: Array<string>;
}
interface TreeShakeOptions {
/**
* Whether to respect the pure annotations.
*
* Pure annotations are comments that mark an expression as pure.
* For example: @__PURE__ or #__NO_SIDE_EFFECTS__.
*
* @default true
*/
annotations?: boolean;
/**
* Whether to treat this function call as pure.
*
* This function is called for normal function calls, new calls, and
* tagged template calls.
*/
manualPureFunctions?: Array<string>;
/**
* Whether property read accesses have side effects.
*
* @default 'always'
*/
propertyReadSideEffects?: boolean | 'always';
/**
* Whether property write accesses (assignments to member expressions) have side effects.
*
* When false, assignments like `obj.prop = value` are considered side-effect-free
* (assuming the object and value expressions themselves are side-effect-free).
*
* @default true
*/
propertyWriteSideEffects?: boolean;
/**
* Whether accessing a global variable has side effects.
*
* Accessing a non-existing global variable will throw an error.
* Global variable may be a getter that has side effects.
*
* @default true
*/
unknownGlobalSideEffects?: boolean;
/**
* Whether invalid import statements have side effects.
*
* Accessing a non-existing import name will throw an error.
* Also import statements that cannot be resolved will throw an error.
*
* @default true
*/
invalidImportSideEffects?: boolean;
}
interface Comment {
type: 'Line' | 'Block';
value: string;
start: number;
end: number;
}
interface ErrorLabel {
message: string | null;
start: number;
end: number;
}
interface OxcError {
severity: Severity;
message: string;
labels: Array<ErrorLabel>;
helpMessage: string | null;
codeframe: string | null;
}
type Severity = 'Error' | 'Warning' | 'Advice';
declare class ParseResult {
get program(): import("@oxc-project/types").Program;
get module(): EcmaScriptModule;
get comments(): Array<Comment>;
get errors(): Array<OxcError>;
}
interface DynamicImport {
start: number;
end: number;
moduleRequest: Span;
}
interface EcmaScriptModule {
/**
* Has ESM syntax.
*
* i.e. `import` and `export` statements, and `import.meta`.
*
* Dynamic imports `import('foo')` are ignored since they can be used in non-ESM files.
*/
hasModuleSyntax: boolean;
/** Import statements. */
staticImports: Array<StaticImport>;
/** Export statements. */
staticExports: Array<StaticExport>;
/** Dynamic import expressions. */
dynamicImports: Array<DynamicImport>;
/** Span positions` of `import.meta` */
importMetas: Array<Span>;
}
interface ExportExportName {
kind: ExportExportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
type ExportExportNameKind = /** `export { name } */'Name' | /** `export default expression` */'Default' | /** `export * from "mod" */'None';
interface ExportImportName {
kind: ExportImportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
type ExportImportNameKind = /** `export { name } */'Name' | /** `export * as ns from "mod"` */'All' | /** `export * from "mod"` */'AllButDefault' | /** Does not have a specifier. */'None';
interface ExportLocalName {
kind: ExportLocalNameKind;
name: string | null;
start: number | null;
end: number | null;
}
type ExportLocalNameKind = /** `export { name } */'Name' | /** `export default expression` */'Default' |
/**
* If the exported value is not locally accessible from within the module.
* `export default function () {}`
*/
'None';
interface ImportName {
kind: ImportNameKind;
name: string | null;
start: number | null;
end: number | null;
}
type ImportNameKind = /** `import { x } from "mod"` */'Name' | /** `import * as ns from "mod"` */'NamespaceObject' | /** `import defaultExport from "mod"` */'Default';
interface ParserOptions {
/** Treat the source text as `js`, `jsx`, `ts`, `tsx` or `dts`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts';
/** Treat the source text as `script` or `module` code. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined;
/**
* Return an AST which includes TypeScript-related properties, or excludes them.
*
* `'js'` is default for JS / JSX files.
* `'ts'` is default for TS / TSX files.
* The type of the file is determined from `lang` option, or extension of provided `filename`.
*/
astType?: 'js' | 'ts';
/**
* Controls whether the `range` property is included on AST nodes.
* The `range` property is a `[number, number]` which indicates the start/end offsets
* of the node in the file contents.
*
* @default false
*/
range?: boolean;
/**
* Emit `ParenthesizedExpression` and `TSParenthesizedType` in AST.
*
* If this option is true, parenthesized expressions are represented by
* (non-standard) `ParenthesizedExpression` and `TSParenthesizedType` nodes that
* have a single `expression` property containing the expression inside parentheses.
*
* @default true
*/
preserveParens?: boolean;
/**
* Produce semantic errors with an additional AST pass.
* Semantic errors depend on symbols and scopes, where the parser does not construct.
* This adds a small performance overhead.
*
* @default false
*/
showSemanticErrors?: boolean;
}
interface Span {
start: number;
end: number;
}
interface StaticExport {
start: number;
end: number;
entries: Array<StaticExportEntry>;
}
interface StaticExportEntry {
start: number;
end: number;
moduleRequest: ValueSpan | null;
/** The name under which the desired binding is exported by the module`. */
importName: ExportImportName;
/** The name used to export this binding by this module. */
exportName: ExportExportName;
/** The name that is used to locally access the exported value from within the importing module. */
localName: ExportLocalName;
/**
* Whether the export is a TypeScript `export type`.
*
* Examples:
*
* ```ts
* export type * from 'mod';
* export type * as ns from 'mod';
* export type { foo };
* export { type foo }:
* export type { foo } from 'mod';
* ```
*/
isType: boolean;
}
interface StaticImport {
/** Start of import statement. */
start: number;
/** End of import statement. */
end: number;
/**
* Import source.
*
* ```js
* import { foo } from "mod";
* // ^^^
* ```
*/
moduleRequest: ValueSpan;
/**
* Import specifiers.
*
* Empty for `import "mod"`.
*/
entries: Array<StaticImportEntry>;
}
interface StaticImportEntry {
/**
* The name under which the desired binding is exported by the module.
*
* ```js
* import { foo } from "mod";
* // ^^^
* import { foo as bar } from "mod";
* // ^^^
* ```
*/
importName: ImportName;
/**
* The name that is used to locally access the imported value from within the importing module.
* ```js
* import { foo } from "mod";
* // ^^^
* import { foo as bar } from "mod";
* // ^^^
* ```
*/
localName: ValueSpan;
/**
* Whether this binding is for a TypeScript type-only import.
*
* `true` for the following imports:
* ```ts
* import type { foo } from "mod";
* import { type foo } from "mod";
* ```
*/
isType: boolean;
}
interface ValueSpan {
value: string;
start: number;
end: number;
}
declare class ResolverFactory {
constructor(options?: NapiResolveOptions | undefined | null);
static default(): ResolverFactory;
/** Clone the resolver using the same underlying cache. */
cloneWithOptions(options: NapiResolveOptions): ResolverFactory;
/**
* Clear the underlying cache.
*
* Warning: The caller must ensure that there're no ongoing resolution operations when calling this method. Otherwise, it may cause those operations to return an incorrect result.
*/
clearCache(): void;
/** Synchronously resolve `specifier` at an absolute path to a `directory`. */
sync(directory: string, request: string): ResolveResult;
/** Asynchronously resolve `specifier` at an absolute path to a `directory`. */
async(directory: string, request: string): Promise<ResolveResult>;
/**
* Synchronously resolve `specifier` at an absolute path to a `file`.
*
* This method automatically discovers tsconfig.json by traversing parent directories.
*/
resolveFileSync(file: string, request: string): ResolveResult;
/**
* Asynchronously resolve `specifier` at an absolute path to a `file`.
*
* This method automatically discovers tsconfig.json by traversing parent directories.
*/
resolveFileAsync(file: string, request: string): Promise<ResolveResult>;
/**
* Synchronously resolve `specifier` for TypeScript declaration files.
*
* `file` is the absolute path to the containing file.
* Uses TypeScript's `moduleResolution: "bundler"` algorithm.
*/
resolveDtsSync(file: string, request: string): ResolveResult;
/**
* Asynchronously resolve `specifier` for TypeScript declaration files.
*
* `file` is the absolute path to the containing file.
* Uses TypeScript's `moduleResolution: "bundler"` algorithm.
*/
resolveDtsAsync(file: string, request: string): Promise<ResolveResult>;
}
/** Node.js builtin module when `Options::builtin_modules` is enabled. */
interface Builtin {
/**
* Resolved module.
*
* Always prefixed with "node:" in compliance with the ESM specification.
*/
resolved: string;
/**
* Whether the request was prefixed with `node:` or not.
* `fs` -> `false`.
* `node:fs` returns `true`.
*/
isRuntimeModule: boolean;
}
declare enum EnforceExtension {
Auto = 0,
Enabled = 1,
Disabled = 2
}
type ModuleType = 'module' | 'commonjs' | 'json' | 'wasm' | 'addon';
/**
* Module Resolution Options
*
* Options are directly ported from [enhanced-resolve](https://github.com/webpack/enhanced-resolve#resolver-options).
*
* See [webpack resolve](https://webpack.js.org/configuration/resolve/) for information and examples
*/
interface NapiResolveOptions {
/**
* Discover tsconfig automatically or use the specified tsconfig.json path.
*
* Default `None`
*/
tsconfig?: 'auto' | TsconfigOptions;
/**
* Alias for [ResolveOptions::alias] and [ResolveOptions::fallback].
*
* For the second value of the tuple, `None -> AliasValue::Ignore`, Some(String) ->
* AliasValue::Path(String)`
* Create aliases to import or require certain modules more easily.
* A trailing $ can also be added to the given object's keys to signify an exact match.
* Default `{}`
*/
alias?: Record<string, Array<string | undefined | null>>;
/**
* A list of alias fields in description files.
* Specify a field, such as `browser`, to be parsed according to [this specification](https://github.com/defunctzombie/package-browser-field-spec).
* Can be a path to json object such as `["path", "to", "exports"]`.
*
* Default `[]`
*/
aliasFields?: (string | string[])[];
/**
* Condition names for exports field which defines entry points of a package.
* The key order in the exports field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
*
* Default `[]`
*/
conditionNames?: Array<string>;
/**
* If true, it will not allow extension-less files.
* So by default `require('./foo')` works if `./foo` has a `.js` extension,
* but with this enabled only `require('./foo.js')` will work.
*
* Default to `true` when [ResolveOptions::extensions] contains an empty string.
* Use `Some(false)` to disable the behavior.
* See <https://github.com/webpack/enhanced-resolve/pull/285>
*
* Default None, which is the same as `Some(false)` when the above empty rule is not applied.
*/
enforceExtension?: EnforceExtension;
/**
* A list of exports fields in description files.
* Can be a path to json object such as `["path", "to", "exports"]`.
*
* Default `[["exports"]]`.
*/
exportsFields?: (string | string[])[];
/**
* Fields from `package.json` which are used to provide the internal requests of a package
* (requests starting with # are considered internal).
*
* Can be a path to a JSON object such as `["path", "to", "imports"]`.
*
* Default `[["imports"]]`.
*/
importsFields?: (string | string[])[];
/**
* An object which maps extension to extension aliases.
*
* Default `{}`
*/
extensionAlias?: Record<string, Array<string>>;
/**
* Attempt to resolve these extensions in order.
* If multiple files share the same name but have different extensions,
* will resolve the one with the extension listed first in the array and skip the rest.
*
* Default `[".js", ".json", ".node"]`
*/
extensions?: Array<string>;
/**
* Redirect module requests when normal resolving fails.
*
* Default `{}`
*/
fallback?: Record<string, Array<string | undefined | null>>;
/**
* Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests).
*
* See also webpack configuration [resolve.fullySpecified](https://webpack.js.org/configuration/module/#resolvefullyspecified)
*
* Default `false`
*/
fullySpecified?: boolean;
/**
* A list of main fields in description files
*
* Default `["main"]`.
*/
mainFields?: string | string[];
/**
* The filename to be used while resolving directories.
*
* Default `["index"]`
*/
mainFiles?: Array<string>;
/**
* A list of directories to resolve modules from, can be absolute path or folder name.
*
* Default `["node_modules"]`
*/
modules?: string | string[];
/**
* Resolve to a context instead of a file.
*
* Default `false`
*/
resolveToContext?: boolean;
/**
* Prefer to resolve module requests as relative requests instead of using modules from node_modules directories.
*
* Default `false`
*/
preferRelative?: boolean;
/**
* Prefer to resolve server-relative urls as absolute paths before falling back to resolve in ResolveOptions::roots.
*
* Default `false`
*/
preferAbsolute?: boolean;
/**
* A list of resolve restrictions to restrict the paths that a request can be resolved on.
*
* Default `[]`
*/
restrictions?: Array<Restriction>;
/**
* A list of directories where requests of server-relative URLs (starting with '/') are resolved.
* On non-Windows systems these requests are resolved as an absolute path first.
*
* Default `[]`
*/
roots?: Array<string>;
/**
* Whether to resolve symlinks to their symlinked location.
* When enabled, symlinked resources are resolved to their real path, not their symlinked location.
* Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).
*
* Default `true`
*/
symlinks?: boolean;
/**
* Whether to read the `NODE_PATH` environment variable and append its entries to `modules`.
*
* `NODE_PATH` is a deprecated Node.js feature that is not part of ESM resolution.
* Set this to `false` to disable the behavior.
*
* Default `true`
*/
nodePath?: boolean;
/**
* Whether to parse [module.builtinModules](https://nodejs.org/api/module.html#modulebuiltinmodules) or not.
* For example, "zlib" will throw [crate::ResolveError::Builtin] when set to true.
*
* Default `false`
*/
builtinModules?: boolean;
/**
* Resolve [ResolveResult::moduleType].
*
* Default `false`
*/
moduleType?: boolean;
/**
* Allow `exports` field in `require('../directory')`.
*
* This is not part of the spec but some vite projects rely on this behavior.
* See
* * <https://github.com/vitejs/vite/pull/20252>
* * <https://github.com/nodejs/node/issues/58827>
*
* Default: `false`
*/
allowPackageExportsInDirectoryResolve?: boolean;
}
interface ResolveResult {
path?: string;
error?: string;
builtin?: Builtin;
/**
* Module type for this path.
*
* Enable with `ResolveOptions#moduleType`.
*
* The module type is computed `ESM_FILE_FORMAT` from the [ESM resolution algorithm specification](https://nodejs.org/docs/latest/api/esm.html#resolution-algorithm-specification).
*
* The algorithm uses the file extension or finds the closest `package.json` with the `type` field.
*/
moduleType?: ModuleType;
/** `package.json` path for the given module. */
packageJsonPath?: string;
}
/**
* Alias Value for [ResolveOptions::alias] and [ResolveOptions::fallback].
* Use struct because napi don't support structured union now
*/
interface Restriction {
path?: string;
regex?: string;
}
/**
* Tsconfig Options
*
* Derived from [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin#options)
*/
interface TsconfigOptions {
/**
* Allows you to specify where to find the TypeScript configuration file.
* You may provide
* * a relative path to the configuration file. It will be resolved relative to cwd.
* * an absolute path to the configuration file.
*/
configFile: string;
/**
* Support for Typescript Project References.
*
* * `'auto'`: use the `references` field from tsconfig of `config_file`.
*/
references?: 'auto';
}
interface SourceMap {
file?: string;
mappings: string;
names: Array<string>;
sourceRoot?: string;
sources: Array<string>;
sourcesContent?: Array<string>;
version: number;
x_google_ignoreList?: Array<number>;
}
interface CompilerAssumptions {
ignoreFunctionLength?: boolean;
noDocumentAll?: boolean;
objectRestNoSymbols?: boolean;
pureGetters?: boolean;
/**
* When using public class fields, assume that they don't shadow any getter in the current class,
* in its subclasses or in its superclass. Thus, it's safe to assign them rather than using
* `Object.defineProperty`.
*
* For example:
*
* Input:
* ```js
* class Test {
* field = 2;
*
* static staticField = 3;
* }
* ```
*
* When `set_public_class_fields` is `true`, the output will be:
* ```js
* class Test {
* constructor() {
* this.field = 2;
* }
* }
* Test.staticField = 3;
* ```
*
* Otherwise, the output will be:
* ```js
* import _defineProperty from "@oxc-project/runtime/helpers/defineProperty";
* class Test {
* constructor() {
* _defineProperty(this, "field", 2);
* }
* }
* _defineProperty(Test, "staticField", 3);
* ```
*
* NOTE: For TypeScript, if you wanted behavior is equivalent to `useDefineForClassFields: false`, you should
* set both `set_public_class_fields` and [`crate::TypeScriptOptions::remove_class_fields_without_initializer`]
* to `true`.
*/
setPublicClassFields?: boolean;
}
interface DecoratorOptions {
/**
* Enables experimental support for decorators, which is a version of decorators that predates the TC39 standardization process.
*
* Decorators are a language feature which hasn’t yet been fully ratified into the JavaScript specification.
* This means that the implementation version in TypeScript may differ from the implementation in JavaScript when it it decided by TC39.
*
* @see https://www.typescriptlang.org/tsconfig/#experimentalDecorators
* @default false
*/
legacy?: boolean;
/**
* Enables emitting decorator metadata.
*
* This option the same as [emitDecoratorMetadata](https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata)
* in TypeScript, and it only works when `legacy` is true.
*
* @see https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata
* @default false
*/
emitDecoratorMetadata?: boolean;
/**
* Aligns nullable-union `design:type` emission with `--strictNullChecks`.
*
* When `true` (default), `T | null` and `T | undefined` emit `Object`, matching tsc strict.
* When `false`, `null` and `undefined` are elided from the union so the underlying
* primitive constructor is emitted, matching tsc with `--strictNullChecks=false`
* and `babel-plugin-transform-typescript-metadata`.
*
* @see https://www.typescriptlang.org/tsconfig/#strictNullChecks
* @default true
*/
strictNullChecks?: boolean;
}
type HelperMode =
/**
* Runtime mode (default): Helper functions are imported from a runtime package.
*
* Example:
*
* ```js
* import helperName from "@oxc-project/runtime/helpers/helperName";
* helperName(...arguments);
* ```
*/
'Runtime' |
/**
* External mode: Helper functions are accessed from a global `babelHelpers` object.
*
* Example:
*
* ```js
* babelHelpers.helperName(...arguments);
* ```
*/
'External';
interface Helpers {
mode?: HelperMode;
}
/**
* TypeScript Isolated Declarations for Standalone DTS Emit (async)
*
* Note: This function can be slower than `isolatedDeclarationSync` due to the overhead of spawning a thread.
*/
declare function isolatedDeclaration(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): Promise<IsolatedDeclarationsResult>;
interface IsolatedDeclarationsOptions {
/**
* Do not emit declarations for code that has an @internal annotation in its JSDoc comment.
* This is an internal compiler option; use at your own risk, because the compiler does not check that the result is valid.
*
* Default: `false`
*
* See <https://www.typescriptlang.org/tsconfig/#stripInternal>
*/
stripInternal?: boolean;
sourcemap?: boolean;
}
interface IsolatedDeclarationsResult {
code: string;
map?: SourceMap;
errors: Array<OxcError>;
}
/** TypeScript Isolated Declarations for Standalone DTS Emit */
declare function isolatedDeclarationSync(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): IsolatedDeclarationsResult;
/**
* Configure how TSX and JSX are transformed.
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/jsx}
*/
interface JsxOptions {
/**
* Decides which runtime to use.
*
* - 'automatic' - auto-import the correct JSX factories
* - 'classic' - no auto-import
*
* @default 'automatic'
*/
runtime?: 'classic' | 'automatic';
/**
* Emit development-specific information, such as `__source` and `__self`.
*
* @default false
*/
development?: boolean;
/**
* Toggles whether or not to throw an error if an XML namespaced tag name
* is used.
*
* Though the JSX spec allows this, it is disabled by default since React's
* JSX does not currently have support for it.
*
* @default true
*/
throwIfNamespace?: boolean;
/**
* Mark JSX elements and top-level React method calls as pure for tree shaking.
*
* @default true
*/
pure?: boolean;
/**
* Replaces the import source when importing functions.
*
* @default 'react'
*/
importSource?: string;
/**
* Replace the function used when compiling JSX expressions. It should be a
* qualified name (e.g. `React.createElement`) or an identifier (e.g.
* `createElement`).
*
* Only used for `classic` {@link runtime}.
*
* @default 'React.createElement'
*/
pragma?: string;
/**
* Replace the component used when compiling JSX fragments. It should be a
* valid JSX tag name.
*
* Only used for `classic` {@link runtime}.
*
* @default 'React.Fragment'
*/
pragmaFrag?: string;
/**
* Enable React Fast Refresh .
*
* Conforms to the implementation in {@link https://github.com/facebook/react/tree/v18.3.1/packages/react-refresh}
*
* @default false
*/
refresh?: boolean | ReactRefreshOptions;
}
/**
* Transform JavaScript code to a Vite Node runnable module.
*
* @param filename The name of the file being transformed.
* @param sourceText the source code itself
* @param options The options for the transformation. See {@link
* ModuleRunnerTransformOptions} for more information.
*
* @returns an object containing the transformed code, source maps, and any
* errors that occurred during parsing or transformation.
*
* Note: This function can be slower than `moduleRunnerTransformSync` due to the overhead of spawning a thread.
*
* @deprecated Only works for Vite.
*/
declare function moduleRunnerTransform(filename: string, sourceText: string, options?: ModuleRunnerTransformOptions | undefined | null): Promise<ModuleRunnerTransformResult>;
interface ModuleRunnerTransformOptions {
/**
* Enable source map generation.
*
* When `true`, the `sourceMap` field of transform result objects will be populated.
*
* @default false
*
* @see {@link SourceMap}
*/
sourcemap?: boolean;
}
interface ModuleRunnerTransformResult {
/**
* The transformed code.
*
* If parsing failed, this will be an empty string.
*/
code: string;
/**
* The source map for the transformed code.
*
* This will be set if {@link TransformOptions#sourcemap} is `true`.
*/
map?: SourceMap;
deps: Array<string>;
dynamicDeps: Array<string>;
/**
* Parse and transformation errors.
*
* Oxc's parser recovers from common syntax errors, meaning that
* transformed code may still be available even if there are errors in this
* list.
*/
errors: Array<OxcError>;
}
interface PluginsOptions {
styledComponents?: StyledComponentsOptions;
taggedTemplateEscape?: boolean;
}
interface ReactRefreshOptions {
/**
* Specify the identifier of the refresh registration variable.
*
* @default `$RefreshReg$`.
*/
refreshReg?: string;
/**
* Specify the identifier of the refresh signature variable.
*
* @default `$RefreshSig$`.
*/
refreshSig?: string;
emitFullSignatures?: boolean;
}
/**
* Configure how styled-components are transformed.
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/plugins#styled-components}
*/
interface StyledComponentsOptions {
/**
* Enhances the attached CSS class name on each component with richer output to help
* identify your components in the DOM without React DevTools.
*
* @default true
*/
displayName?: boolean;
/**
* Controls whether the `displayName` of a component will be prefixed with the filename
* to make the component name as unique as possible.
*
* @default true
*/
fileName?: boolean;
/**
* Adds a unique identifier to every styled component to avoid checksum mismatches
* due to different class generation on the client and server during server-side rendering.
*
* @default true
*/
ssr?: boolean;
/**
* Transpiles styled-components tagged template literals to a smaller representation
* than what Babel normally creates, helping to reduce bundle size.
*
* Disabled by default because Oxc does not down-level template literals, so this
* transform only increases output size.
*
* @default false
*/
transpileTemplateLiterals?: boolean;
/**
* Minifies CSS content by removing all whitespace and comments from your CSS,
* keeping valuable bytes out of your bundles.
*
* @default true
*/
minify?: boolean;
/**
* Enables transformation of JSX `css` prop when using styled-components.
*
* **Note: This feature is not yet implemented in oxc.**
*
* @default true
*/
cssProp?: boolean;
/**
* Enables "pure annotation" to aid dead code elimination by bundlers.
*
* @default false
*/
pure?: boolean;
/**
* Adds a namespace prefix to component identifiers to ensure class names are unique.
*
* Example: With `namespace: "my-app"`, generates `componentId: "my-app__sc-3rfj0a-1"`
*/
namespace?: string;
/**
* List of file names that are considered meaningless for component naming purposes.
*
* When the `fileName` option is enabled and a component is in a file with a name
* from this list, the directory name will be used instead of the file name for
* the component's display name.
*
* @default `["index"]`
*/
meaninglessFileNames?: Array<string>;
/**
* Import paths to be considered as styled-components imports at the top level.
*
* **Note: This feature is not yet implemented in oxc.**
*/
topLevelImportPaths?: Array<string>;
}
/**
* Options for transforming a JavaScript or TypeScript file.
*
* Options are listed in evaluation order: the source is parsed (`lang`,
* `sourceType`), declarations are emitted (`typescript.declaration`), then
* transforms run (`typescript`, `decorator`, `plugins`,
* `jsx`, `target`), followed by the `inject` and `define` plugins, and
* finally codegen (`sourcemap`). `helpers` configures the runtime helpers
* the transforms emit.
*
* @see {@link transform}
*/
interface TransformOptions {
/** Treat the source text as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts';
/** Treat the source text as `script` or `module` code. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined;
/**
* The current working directory. Used to resolve relative paths in other
* options.
*/
cwd?: string;
/** Set assumptions in order to produce smaller output. */
assumptions?: CompilerAssumptions;
/**
* Configure how TypeScript is transformed.
*
* `typescript.declaration` is evaluated before all transforms.
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/typescript}
*/
typescript?: TypeScriptOptions;
/** Decorator plugin */
decorator?: DecoratorOptions;
/**
* Third-party plugins to use.
* @see {@link https://oxc.rs/docs/guide/usage/transformer/plugins}
*/
plugins?: PluginsOptions;
/**
* Configure how TSX and JSX are transformed.
* @see {@link https://oxc.rs/docs/guide/usage/transformer/jsx}
*/
jsx?: 'preserve' | JsxOptions;
/**
* Sets the target environment for the generated JavaScript.
*
* The lowest target is `es2015`.
*
* Example:
*
* * `'es2015'`
* * `['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']`
*
* @default `esnext` (No transformation)
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/lowering#target}
*/
target?: string | Array<string>;
/** Behaviour for runtime helpers. */
helpers?: Helpers;
/**
* Inject Plugin
*
* Runs after all transforms.
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#inject}
*/
inject?: Record<string, string | [string, string]>;
/**
* Define Plugin
*
* Runs after the inject plugin.
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#define}
*/
define?: Record<string, string>;
/**
* Enable source map generation.
*
* When `true`, the `sourceMap` field of transform result objects will be populated.
*
* @default false
*
* @see {@link SourceMap}
*/
sourcemap?: boolean;
}
interface TypeScriptOptions {
jsxPragma?: string;
jsxPragmaFrag?: string;
onlyRemoveTypeImports?: boolean;
allowNamespaces?: boolean;
/**
* When enabled, type-only class fields are only removed if they are prefixed with the declare modifier:
*
* @deprecated
*
* Allowing `declare` fields is built-in support in Oxc without any option. If you want to remove class fields
* without initializer, you can use `remove_class_fields_without_initializer: true` instead.
*/
allowDeclareFields?: boolean;
/**
* When enabled, class fields without initializers are removed.
*
* For example:
* ```ts
* class Foo {
* x: number;
* y: number = 0;
* }
* ```
* // transform into
* ```js
* class Foo {
* x: number;
* }
* ```
*
* The option is used to align with the behavior of TypeScript's `useDefineForClassFields: false` option.
* When you want to enable this, you also need to set [`crate::CompilerAssumptions::set_public_class_fields`]
* to `true`. The `set_public_class_fields: true` + `remove_class_fields_without_initializer: true` is
* equivalent to `useDefineForClassFields: false` in TypeScript.
*
* When `set_public_class_fields` is true and class-properties plugin is enabled, the above example transforms into:
*
* ```js
* class Foo {
* constructor() {
* this.y = 0;
* }
* }
* ```
*
* Defaults to `false`.
*/
removeClassFieldsWithoutInitializer?: boolean;
/**
* When true, optimize const enums by inlining their values at usage sites
* and removing the enum declaration.
*
* @default false
*/
optimizeConstEnums?: boolean;
/**
* When true, optimize regular (non-const) enums by inlining their member
* accesses at usage sites when the member value is statically known.
*
* Non-exported enum declarations are also removed when all members are
* evaluable and no references to the enum as a runtime value exist
* (e.g., `console.log(Foo)`, `typeof Foo`, or passing the enum as an argument).
*
* @default false
*/
optimizeEnums?: boolean;
/**
* Also generate a `.d.ts` declaration file for TypeScript files.
*
* The source file must be compliant with all
* [`isolatedDeclarations`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations)
* requirements.
*
* @default false
*/
declaration?: IsolatedDeclarationsOptions;
/**
* Rewrite or remove TypeScript import/export declaration extensions.
*
* - When set to `rewrite`, it will change `.ts`, `.mts`, `.cts` extensions to `.js`, `.mjs`, `.cjs` respectively.
* - When set to `remove`, it will remove `.ts`/`.mts`/`.cts`/`.tsx` extension entirely.
* - When set to `true`, it's equivalent to `rewrite`.
* - When set to `false` or omitted, no changes will be made to the extensions.
*
* @default false
*/
rewriteImportExtensions?: 'rewrite' | 'remove' | boolean;
}
/** A decoded source map with mappings as an array of arrays instead of VLQ-encoded string. */
declare class BindingDecodedMap {
/** The source map version (always 3). */
get version(): number;
/** The generated file name. */
get file(): string | null;
/** The list of original source files. */
get sources(): Array<string>;
/** The original source contents (if `includeContent` was true). */
get sourcesContent(): Array<string | undefined | null>;
/** The list of symbol names used in mappings. */
get names(): Array<string>;
/**
* The decoded mappings as an array of line arrays.
* Each line is an array of segments, where each segment is [generatedColumn, sourceIndex, originalLine, originalColumn, nameIndex?].
*/
get mappings(): Array<Array<Array<number>>>;
/** The list of source indices that should be excluded from debugging. */
get x_google_ignoreList(): Array<number> | null;
}
declare class BindingMagicString {
constructor(source: string, options?: BindingMagicStringOptions | undefined | null);
get original(): string;
get filename(): string | null;
get indentExclusionRanges(): Array<Array<number>> | Array<number> | null;
get ignoreList(): boolean;
get offset(): number;
set offset(offset: number);
replace(from: string, to: string): this;
replaceAll(from: string, to: string): this;
/**
* Returns the UTF-16 offset past the last match, or -1 if no match was found.
* The JS wrapper uses this to update `lastIndex` on the caller's RegExp.
* Global/sticky behavior is derived from the regex's own flags.
*/
replaceRegex(from: RegExp, to: string): number;
prepend(content: string): this;
append(content: string): this;
prependLeft(index: number, content: string): this;
prependRight(index: number, content: string): this;
appendLeft(index: number, content: string): this;
appendRight(index: number, content: string): this;
overwrite(start: number, end: number, content: string, options?: BindingOverwriteOptions | undefined | null): this;
toString(): string;
hasChanged(): boolean;
length(): number;
isEmpty(): boolean;
remove(start: number, end: number): this;
update(start: number, end: number, content: string, options?: BindingUpdateOptions | undefined | null): this;
relocate(start: number, end: number, to: number): this;
/**
* Alias for `relocate` to match the original magic-string API.
* Moves the characters from `start` to `end` to `index`.
* Returns `this` for method chaining.
*/
move(start: number, end: number, index: number): this;
indent(indentor?: string | undefined | null, options?: BindingIndentOptions | undefined | null): this;
/** Trims whitespace or specified characters from the start and end. */
trim(charType?: string | undefined | null): this;
/** Trims whitespace or specified characters from the start. */
trimStart(charType?: string | undefined | null): this;
/** Trims whitespace or specified characters from the end. */
trimEnd(charType?: string | undefined | null): this;
/** Trims newlines from the start and end. */
trimLines(): this;
/**
* Deprecated method that throws an error directing users to use prependRight or appendLeft.
* This matches the original magic-string API which deprecated this method.
*/
insert(index: number, content: string): void;
/** Returns a clone of the MagicString instance. */
clone(): BindingMagicString;
/** Returns the last character of the generated string, or an empty string if empty. */
lastChar(): string;
/** Returns the content after the last newline in the generated string. */
lastLine(): string;
/** Returns the guessed indentation string, or `\t` if none is found. */
getIndentString(): string;
/** Returns a clone with content outside the specified range removed. */
snip(start: number, end: number): BindingMagicString;
/**
* Resets the portion of the string from `start` to `end` to its original content.
* This undoes any modifications made to that range.
* Supports negative indices (counting from the end).
*/
reset(start: number, end: number): this;
/**
* Returns the content between the specified UTF-16 code unit positions (JS string indices).
* Supports negative indices (counting from the end).
*
* When an index falls in the middle of a surrogate pair, the lone surrogate is
* included in the result (matching the original magic-string / JS behavior).
* This is done by returning a UTF-16 encoded JS string via `napi_create_string_utf16`.
*/
slice(start?: number | undefined | null, end?: number | undefined | null): string;
/**
* Generates a source map for the transformations applied to this MagicString.
* Returns a BindingSourceMap object with version, file, sources, sourcesContent, names, mappings.
*/
generateMap(options?: BindingSourceMapOptions | undefined | null): BindingSourceMap;
/**
* Generates a decoded source map for the transformations applied to this MagicString.
* Returns a BindingDecodedMap object with mappings as an array of arrays.
*/
generateDecodedMap(options?: BindingSourceMapOptions | undefined | null): BindingDecodedMap;
}
declare class BindingNormalizedOptions {
get input(): Array<string> | Record<string, string>;
get cwd(): string;
get platform(): 'node' | 'browser' | 'neutral';
get shimMissingExports(): boolean;
get name(): string | null;
get entryFilenames(): string | undefined;
get chunkFilenames(): string | undefined;
get sourcemapFilenames(): string | undefined;
get assetFilenames(): string | undefined;
get dir(): string | null;
get file(): string | null;
get format(): 'es' | 'cjs' | 'iife' | 'umd';
get exports(): 'default' | 'named' | 'none' | 'auto';
get esModule(): boolean | 'if-default-prop';
get codeSplitting(): boolean;
get dynamicImportInCjs(): boolean;
get sourcemap(): boolean | 'inline' | 'hidden';
get sourcemapBaseUrl(): string | null;
get banner(): string | undefined | null | undefined;
get footer(): string | undefined | null | undefined;
get intro(): string | undefined | null | undefined;
get outro(): string | undefined | null | undefined;
get postBanner(): string | undefined | null | undefined;
get postFooter(): string | undefined | null | undefined;
get externalLiveBindings(): boolean;
get extend(): boolean;
get globals(): Record<string, string> | undefined;
get hashCharacters(): 'base64' | 'base36' | 'hex';
get sourcemapDebugIds(): boolean;
get sourcemapExcludeSources(): boolean;
get polyfillRequire(): boolean;
get minify(): false | 'dce-only' | MinifyOptions;
get legalComments(): 'none' | 'inline';
get comments(): BindingCommentsOptions;
get preserveModules(): boolean;
get preserveModulesRoot(): string | undefined;
get virtualDirname(): string;
get topLevelVar(): boolean;
get minifyInternalExports(): boolean;
get context(): string;
}
declare class BindingRenderedChunk {
get name(): string;
get isEntry(): boolean;
get isDynamicEntry(): boolean;
get facadeModuleId(): string | null;
get moduleIds(): Array<string>;
get exports(): Array<string>;
get fileName(): string;
get modules(): BindingModules;
get imports(): Array<string>;
get dynamicImports(): Array<string>;
}
declare class BindingRenderedModule {
get code(): string | null;
get renderedExports(): Array<string>;
}
/** A source map object with properties matching the SourceMap V3 specification. */
declare class BindingSourceMap {
/** The source map version (always 3). */
get version(): number;
/** The generated file name. */
get file(): string | null;
/** The list of original source files. */
get sources(): Array<string>;
/** The original source contents (if `includeContent` was true). */
get sourcesContent(): Array<string | undefined | null>;
/** The list of symbol names used in mappings. */
get names(): Array<string>;
/** The VLQ-encoded mappings string. */
get mappings(): string;
/** The list of source indices that should be excluded from debugging. */
get x_google_ignoreList(): Array<number> | null;
/** Returns the source map as a JSON string. */
toString(): string;
/** Returns the source map as a base64-encoded data URL. */
toUrl(): string;
}
/**
* Minimal wrapper around a `BundleHandle` for watcher events.
* This is returned from watcher event data to allow calling `result.close()`.
*/
declare class BindingWatcherBundler {
close(): Promise<void>;
}
declare class TsconfigCache {
/** Create a new transform cache with auto tsconfig discovery enabled. */
constructor(yarnPnp: boolean);
/**
* Clear the cache.
*
* Call this when tsconfig files have changed to ensure fresh resolution.
*/
clear(): void;
/** Get the number of cached entries. */
size(): number;
}
type BindingBuiltinPluginName = 'builtin:bundle-analyzer' | 'builtin:esm-external-require' | 'builtin:isolated-declaration' | 'builtin:replace' | 'builtin:vite-alias' | 'builtin:vite-build-import-analysis' | 'builtin:vite-dynamic-import-vars' | 'builtin:vite-import-glob' | 'builtin:vite-json' | 'builtin:vite-load-fallback' | 'builtin:vite-manifest' | 'builtin:vite-module-preload-polyfill' | 'builtin:vite-react-refresh-wrapper' | 'builtin:vite-reporter' | 'builtin:vite-resolve' | 'builtin:vite-transform' | 'builtin:vite-web-worker-post' | 'builtin:oxc-runtime';
interface BindingBundleAnalyzerPluginConfig {
/** Output filename for the bundle analysis data (default: "analyze-data.json") */
fileName?: string;
/** Output format: "json" (default) or "md" for LLM-friendly markdown */
format?: 'json' | 'md';
}
interface BindingBundleState {
lastBuildErrored: boolean;
/**
* The stage of the last incremental failure, when `last_build_errored`
* is true and the engine is in an incremental-failure state. Absent on
* success and for an initial full-build failure (use
* `last_build_errored` to detect that). The consumer can force a full
* rebuild on the next page load when this is `Hmr`. See
* `internal-docs/dev-engine/implementation.md` §12.
*/
lastErrorStage?: BindingErrorStage;
hasStaleOutput: boolean;
}
interface BindingClientHmrUpdate {
clientId: string;
update: BindingHmrUpdate;
}
interface BindingCommentsOptions {
legal?: boolean;
annotation?: boolean;
jsdoc?: boolean;
}
interface BindingCompilerOptions {
baseUrl?: string;
paths?: Record<string, Array<string>>;
experimentalDecorators?: boolean;
emitDecoratorMetadata?: boolean;
useDefineForClassFields?: boolean;
rewriteRelativeImportExtensions?: boolean;
jsx?: string;
jsxFactory?: string;
jsxFragmentFactory?: string;
jsxImportSource?: string;
verbatimModuleSyntax?: boolean;
preserveValueImports?: boolean;
importsNotUsedAsValues?: string;
target?: string;
module?: string;
allowJs?: boolean;
rootDirs?: Array<string>;
}
/** Enhanced transform options with tsconfig and inputMap support. */
interface BindingEnhancedTransformOptions {
/** Treat the source text as 'js', 'jsx', 'ts', 'tsx', or 'dts'. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts';
/** Treat the source text as 'script', 'module', 'commonjs', or 'unambiguous'. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined;
/**
* The current working directory. Used to resolve relative paths in other
* options.
*/
cwd?: string;
/**
* Enable source map generation.
*
* When `true`, the `sourceMap` field of transform result objects will be populated.
*
* @default false
*/
sourcemap?: boolean;
/** Set assumptions in order to produce smaller output. */
assumptions?: CompilerAssumptions;
/**
* Configure how TypeScript is transformed.
* @see {@link https://oxc.rs/docs/guide/usage/transformer/typescript}
*/
typescript?: TypeScriptOptions;
/**
* Configure how TSX and JSX are transformed.
* @see {@link https://oxc.rs/docs/guide/usage/transformer/jsx}
*/
jsx?: 'preserve' | JsxOptions;
/**
* Sets the target environment for the generated JavaScript.
*
* The lowest target is `es2015`.
*
* Example:
*
* * `'es2015'`
* * `['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']`
*
* @default `esnext` (No transformation)
*
* @see {@link https://oxc.rs/docs/guide/usage/transformer/lowering#target}
*/
target?: string | Array<string>;
/** Behaviour for runtime helpers. */
helpers?: Helpers;
/**
* Define Plugin
* @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#define}
*/
define?: Record<string, string>;
/**
* Inject Plugin
* @see {@link https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#inject}
*/
inject?: Record<string, string | [string, string]>;
/** Decorator plugin */
decorator?: DecoratorOptions;
/**
* Third-party plugins to use.
* @see {@link https://oxc.rs/docs/guide/usage/transformer/plugins}
*/
plugins?: PluginsOptions;
/**
* Configure tsconfig handling.
* - true: Auto-discover and load the nearest tsconfig.json
* - TsconfigRawOptions: Use the provided inline tsconfig options
*/
tsconfig?: boolean | BindingTsconfigRawOptions;
/** An input source map to collapse with the output source map. */
inputMap?: SourceMap;
}
/** Result of the enhanced transform API. */
interface BindingEnhancedTransformResult {
/**
* The transformed code.
*
* If parsing failed, this will be an empty string.
*/
code: string;
/**
* The source map for the transformed code.
*
* This will be set if {@link BindingEnhancedTransformOptions#sourcemap} is `true`.
*/
map?: SourceMap;
/**
* The `.d.ts` declaration file for the transformed code. Declarations are
* only generated if `declaration` is set to `true` and a TypeScript file
* is provided.
*
* If parsing failed and `declaration` is set, this will be an empty string.
*
* @see {@link TypeScriptOptions#declaration}
* @see [declaration tsconfig option](https://www.typescriptlang.org/tsconfig/#declaration)
*/
declaration?: string;
/**
* Declaration source map. Only generated if both
* {@link TypeScriptOptions#declaration declaration} and
* {@link BindingEnhancedTransformOptions#sourcemap sourcemap} are set to `true`.
*/
declarationMap?: SourceMap;
/**
* Helpers used.
*
* @internal
*
* Example:
*
* ```text
* { "_objectSpread": "@oxc-project/runtime/helpers/objectSpread2" }
* ```
*/
helpersUsed: Record<string, string>;
/** Parse and transformation errors. */
errors: Array<BindingError>;
/** Parse and transformation warnings. */
warnings: Array<BindingError>;
/** Paths to tsconfig files that were loaded during transformation. */
tsconfigFilePaths: Array<string>;
}
type BindingError = {
type: 'JsError';
field0: Error;
} | {
type: 'NativeError';
field0: NativeError;
};
/**
* Which stage of an incremental dev build produced the last error.
*
* Mirrors `rolldown_dev::ErrorStage`. Surfaced on
* [`crate::binding_dev_engine::BindingBundleState`] so the consumer can
* treat an `Hmr`-stage failure as recoverable by forcing a full rebuild
* on the next page load (HMR generation may itself be buggy). See
* `internal-docs/dev-engine/implementation.md` §12.
*/
type BindingErrorStage = 'Hmr' | 'Rebuild';
interface BindingEsmExternalRequirePluginConfig {
external: Array<BindingStringOrRegex>;
skipDuplicateCheck?: boolean;
}
interface BindingHmrBoundaryOutput {
boundary: string;
acceptedVia: string;
}
type BindingHmrUpdate = {
type: 'Patch';
code: string;
filename: string;
sourcemap?: string;
sourcemapFilename?: string;
hmrBoundaries: Array<BindingHmrBoundaryOutput>;
} | {
type: 'FullReload';
reason?: string;
} | {
type: 'Noop';
};
interface BindingHookResolveIdExtraArgs {
custom?: number;
isEntry: boolean;
/**
* - `import-statement`: `import { foo } from './lib.js';`
* - `dynamic-import`: `import('./lib.js')`
* - `require-call`: `require('./lib.js')`
* - `import-rule`: `@import 'bg-color.css'`
* - `url-token`: `url('./icon.png')`
* - `new-url`: `new URL('./worker.js', import.meta.url)`
* - `hot-accept`: `import.meta.hot.accept('./lib.js', () => {})`
*/
kind: 'import-statement' | 'dynamic-import' | 'require-call' | 'import-rule' | 'url-token' | 'new-url' | 'hot-accept';
}
interface BindingIndentOptions {
exclude?: Array<Array<number>> | Array<number>;
}
interface BindingIsolatedDeclarationPluginConfig {
stripInternal?: boolean;
}
interface BindingLogLocation {
/** 1-based */
line: number;
/** 0-based position in the line in UTF-16 code units */
column: number;
file?: string;
}
interface BindingMagicStringOptions {
filename?: string;
offset?: number;
indentExclusionRanges?: Array<Array<number>> | Array<number>;
ignoreList?: boolean;
}
interface BindingModules {
values: Array<BindingRenderedModule>;
keys: Array<string>;
}
interface BindingOverwriteOptions {
contentOnly?: boolean;
}
interface BindingPluginContextResolveOptions {
/**
* - `import-statement`: `import { foo } from './lib.js';`
* - `dynamic-import`: `import('./lib.js')`
* - `require-call`: `require('./lib.js')`
* - `import-rule`: `@import 'bg-color.css'`
* - `url-token`: `url('./icon.png')`
* - `new-url`: `new URL('./worker.js', import.meta.url)`
* - `hot-accept`: `import.meta.hot.accept('./lib.js', () => {})`
*/
importKind?: 'import-statement' | 'dynamic-import' | 'require-call' | 'import-rule' | 'url-token' | 'new-url' | 'hot-accept';
isEntry?: boolean;
skipSelf?: boolean;
custom?: number;
vitePluginCustom?: BindingVitePluginCustom;
}
declare enum BindingRebuildStrategy {
Always = 0,
Auto = 1,
Never = 2
}
interface BindingReplacePluginConfig {
values: Record<string, string>;
delimiters?: [string, string];
preventAssignment?: boolean;
objectGuards?: boolean;
sourcemap?: boolean;
}
interface BindingSourceMapOptions {
/** The filename for the generated file (goes into `map.file`) */
file?: string;
/** The filename of the original source (goes into `map.sources`) */
source?: string;
includeContent?: boolean;
/**
* Accepts boolean or string: true, false, "boundary"
* - true: high-resolution sourcemaps (character-level)
* - false: low-resolution sourcemaps (line-level) - default
* - "boundary": high-resolution only at word boundaries
*/
hires?: boolean | string;
}
interface BindingTransformHookExtraArgs {
moduleType: string;
}
interface BindingTsconfig {
files?: Array<string>;
include?: Array<string>;
exclude?: Array<string>;
compilerOptions: BindingCompilerOptions;
}
/**
* TypeScript compiler options for inline tsconfig configuration.
*
* @category Utilities
*/
interface BindingTsconfigCompilerOptions {
/** Specifies the JSX factory function to use. */
jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' | 'react-native';
/** Specifies the JSX factory function. */
jsxFactory?: string;
/** Specifies the JSX fragment factory function. */
jsxFragmentFactory?: string;
/** Specifies the module specifier for JSX imports. */
jsxImportSource?: string;
/** Enables experimental decorators. */
experimentalDecorators?: boolean;
/** Enables decorator metadata emission. */
emitDecoratorMetadata?: boolean;
/** Enables all strict type-checking options. Used as the fallback for `strictNullChecks`. */
strict?: boolean;
/**
* Enables strict null checks. Controls whether `null`/`undefined` are elided from
* nullable-union `design:type` decorator metadata.
*/
strictNullChecks?: boolean;
/** Preserves module structure of imports/exports. */
verbatimModuleSyntax?: boolean;
/** Configures how class fields are emitted. */
useDefineForClassFields?: boolean;
/** The ECMAScript target version. */
target?: string;
/** @deprecated Use verbatimModuleSyntax instead. */
preserveValueImports?: boolean;
/** @deprecated Use verbatimModuleSyntax instead. */
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error';
}
/**
* Raw tsconfig options for inline configuration.
*
* @category Utilities
*/
interface BindingTsconfigRawOptions {
/** TypeScript compiler options. */
compilerOptions?: BindingTsconfigCompilerOptions;
}
interface BindingTsconfigResult {
tsconfig: BindingTsconfig;
tsconfigFilePaths: Array<string>;
}
interface BindingUpdateOptions {
overwrite?: boolean;
}
interface BindingViteBuildImportAnalysisPluginConfig {
preloadCode: string;
insertPreload: boolean;
optimizeModulePreloadRelativePaths: boolean;
renderBuiltUrl: boolean;
isRelativeBase: boolean;
}
interface BindingViteDynamicImportVarsPluginConfig {
sourcemap?: boolean;
include?: Array<BindingStringOrRegex>;
exclude?: Array<BindingStringOrRegex>;
resolver?: (id: string, importer: string) => MaybePromise<string | undefined>;
}
interface BindingViteImportGlobPluginConfig {
root?: string;
sourcemap?: boolean;
restoreQueryExtension?: boolean;
}
interface BindingViteJsonPluginConfig {
minify?: boolean;
namedExports?: boolean;
stringify?: BindingViteJsonPluginStringify;
}
type BindingViteJsonPluginStringify = boolean | string;
interface BindingViteManifestPluginConfig {
root: string;
outPath: string;
isLegacy?: (args: BindingNormalizedOptions) => boolean;
cssEntries: () => Record<string, string>;
}
interface BindingViteModulePreloadPolyfillPluginConfig {
isServer?: boolean;
}
interface BindingVitePluginCustom {
'vite:import-glob'?: ViteImportGlobMeta;
}
interface BindingViteReactRefreshWrapperPluginConfig {
cwd: string;
include?: Array<BindingStringOrRegex>;
exclude?: Array<BindingStringOrRegex>;
jsxImportSource: string;
reactRefreshHost: string;
}
interface BindingViteReporterPluginConfig {
root: string;
isTty: boolean;
isLib: boolean;
assetsDir: string;
chunkLimit: number;
warnLargeChunks: boolean;
reportCompressedSize: boolean;
logInfo?: (msg: string) => void;
}
interface BindingViteResolvePluginConfig {
resolveOptions: BindingViteResolvePluginResolveOptions;
environmentConsumer: string;
environmentName: string;
builtins: Array<BindingStringOrRegex>;
external: true | string[];
noExternal: true | Array<string | RegExp>;
dedupe: Array<string>;
disableCache?: boolean;
legacyInconsistentCjsInterop?: boolean;
finalizeBareSpecifier?: (resolvedId: string, rawId: string, importer: string | null | undefined) => VoidNullable<string>;
finalizeOtherSpecifiers?: (resolvedId: string, rawId: string) => VoidNullable<string>;
resolveSubpathImports: (id: string, importer: string, isRequire: boolean, scan: boolean) => VoidNullable<string>;
onWarn?: (message: string) => void;
onDebug?: (message: string) => void;
yarnPnp: boolean;
}
interface BindingViteResolvePluginResolveOptions {
isBuild: boolean;
isProduction: boolean;
asSrc: boolean;
preferRelative: boolean;
isRequire?: boolean;
root: string;
scan: boolean;
mainFields: Array<string>;
conditions: Array<string>;
externalConditions: Array<string>;
extensions: Array<string>;
tryIndex: boolean;
tryPrefix?: string;
preserveSymlinks: boolean;
tsconfigPaths: boolean;
}
interface BindingViteTransformPluginConfig {
root: string;
include?: Array<BindingStringOrRegex>;
exclude?: Array<BindingStringOrRegex>;
jsxRefreshInclude?: Array<BindingStringOrRegex>;
jsxRefreshExclude?: Array<BindingStringOrRegex>;
isServerConsumer?: boolean;
jsxInject?: string;
transformOptions?: TransformOptions;
yarnPnp?: boolean;
}
interface ExternalMemoryStatus {
freed: boolean;
reason?: string;
}
/** Error emitted from native side, it only contains kind and message, no stack trace. */
interface NativeError {
kind: string;
message: string;
/** The id of the file associated with the error */
id?: string;
/** The exporter associated with the error (for import/export errors) */
exporter?: string;
/** Location information (line, column, file) */
loc?: BindingLogLocation;
/** Position in the source file in UTF-16 code units */
pos?: number;
}
interface PreRenderedChunk {
/** The name of this chunk, which is used in naming patterns. */
name: string;
/** Whether this chunk is a static entry point. */
isEntry: boolean;
/** Whether this chunk is a dynamic entry point. */
isDynamicEntry: boolean;
/** The id of a module that this chunk corresponds to. */
facadeModuleId?: string;
/** The list of ids of modules included in this chunk. */
moduleIds: Array<string>;
/** Exported variable names from this chunk. */
exports: Array<string>;
}
interface ViteImportGlobMeta {
isSubImportsPattern?: boolean;
}
//#endregion
export { ExternalMemoryStatus as A, ResolveResult as B, BindingViteManifestPluginConfig as C, BindingViteResolvePluginConfig as D, BindingViteReporterPluginConfig as E, MinifyResult as F, isolatedDeclaration as G, SourceMap as H, NapiResolveOptions as I, isolatedDeclarationSync as K, ParseResult as L, IsolatedDeclarationsResult as M, JsxOptions as N, BindingViteTransformPluginConfig as O, MinifyOptions as P, ParserOptions as R, BindingViteJsonPluginConfig as S, BindingViteReactRefreshWrapperPluginConfig as T, TransformOptions as U, ResolverFactory as V, TsconfigCache as W, BindingTsconfigRawOptions as _, BindingEnhancedTransformOptions as a, BindingViteDynamicImportVarsPluginConfig as b, BindingHookResolveIdExtraArgs as c, BindingPluginContextResolveOptions as d, BindingRebuildStrategy as f, BindingTsconfigCompilerOptions as g, BindingTransformHookExtraArgs as h, BindingClientHmrUpdate as i, IsolatedDeclarationsOptions as j, BindingWatcherBundler as k, BindingIsolatedDeclarationPluginConfig as l, BindingReplacePluginConfig as m, BindingBundleAnalyzerPluginConfig as n, BindingEnhancedTransformResult as o, BindingRenderedChunk as p, moduleRunnerTransform as q, BindingBundleState as r, BindingEsmExternalRequirePluginConfig as s, BindingBuiltinPluginName as t, BindingMagicString as u, BindingTsconfigResult as v, BindingViteModulePreloadPolyfillPluginConfig as w, BindingViteImportGlobPluginConfig as x, BindingViteBuildImportAnalysisPluginConfig as y, PreRenderedChunk as z }; |