github.com/evanw/esbuild@v0.21.4/internal/bundler_tests/snapshots/snapshots_dce.txt (about) 1 TestBase64LoaderRemoveUnused 2 ---------- /out.js ---------- 3 // entry.js 4 console.log("unused import"); 5 6 ================================================================================ 7 TestConstValueInliningBundle 8 ---------- /out/exported-entry.js ---------- 9 // exported-entry.js 10 var y_keep = 2; 11 console.log( 12 1, 13 2 14 ); 15 export { 16 y_keep 17 }; 18 19 ---------- /out/re-exported-entry.js ---------- 20 // re-exported-constants.js 21 var y_keep = 2; 22 23 // re-exported-entry.js 24 console.log(1, 2); 25 export { 26 y_keep 27 }; 28 29 ---------- /out/re-exported-2-entry.js ---------- 30 // re-exported-2-constants.js 31 var y_keep = 2; 32 export { 33 y_keep 34 }; 35 36 ---------- /out/re-exported-star-entry.js ---------- 37 // re-exported-star-constants.js 38 var x_keep = 1, y_keep = 2; 39 export { 40 x_keep, 41 y_keep 42 }; 43 44 ---------- /out/cross-module-entry.js ---------- 45 // cross-module-constants.js 46 foo(); 47 var y_keep = 1; 48 function foo() { 49 return [1, y_keep]; 50 } 51 52 // cross-module-entry.js 53 console.log(1, y_keep); 54 55 ---------- /out/print-shorthand-entry.js ---------- 56 // print-shorthand-entry.js 57 console.log({ foo: 123, a: -321 }); 58 59 ---------- /out/circular-import-entry.js ---------- 60 // circular-import-cycle.js 61 console.log(bar()); 62 63 // circular-import-constants.js 64 var foo = 123; 65 function bar() { 66 return foo; 67 } 68 69 ---------- /out/circular-re-export-entry.js ---------- 70 // circular-re-export-cycle.js 71 var baz = 0; 72 console.log(bar()); 73 74 // circular-re-export-constants.js 75 var foo = 123; 76 function bar() { 77 return foo; 78 } 79 80 // circular-re-export-entry.js 81 console.log(baz); 82 83 ---------- /out/circular-re-export-star-entry.js ---------- 84 // circular-re-export-star-cycle.js 85 console.log(bar()); 86 87 // circular-re-export-star-constants.js 88 var foo = 123; 89 function bar() { 90 return foo; 91 } 92 93 ---------- /out/non-circular-export-entry.js ---------- 94 // non-circular-export-constants.js 95 function bar() { 96 return 123; 97 } 98 99 // non-circular-export-entry.js 100 console.log(123, bar()); 101 102 ================================================================================ 103 TestConstValueInliningDirectEval 104 ---------- /out/top-level-no-eval.js ---------- 105 const x = 1; 106 console.log(1, evil("x")); 107 108 ---------- /out/top-level-eval.js ---------- 109 const x = 1; 110 console.log(1, eval("x")); 111 112 ---------- /out/nested-no-eval.js ---------- 113 console.log(1, evil("x")); 114 115 ---------- /out/nested-eval.js ---------- 116 (() => { 117 const x = 1; 118 console.log(1, eval("x")); 119 })(); 120 121 ---------- /out/ts-namespace-no-eval.js ---------- 122 var y; 123 ((y2) => (y2.x = 1, console.log(1, evil("x"))))(y ||= {}); 124 125 ---------- /out/ts-namespace-eval.js ---------- 126 var z; 127 ((z) => (z.x = 1, console.log(1, eval("x"))))(z ||= {}); 128 129 ================================================================================ 130 TestConstValueInliningNoBundle 131 ---------- /out/top-level.js ---------- 132 const n_keep = null, u_keep = void 0, i_keep = 1234567, f_keep = 123.456, s_keep = ""; 133 console.log( 134 // These are doubled to avoid the "inline const/let into next statement if used once" optimization 135 null, 136 null, 137 void 0, 138 void 0, 139 1234567, 140 1234567, 141 123.456, 142 123.456, 143 s_keep, 144 s_keep 145 ); 146 147 ---------- /out/nested-block.js ---------- 148 { 149 const s_keep = ""; 150 console.log( 151 // These are doubled to avoid the "inline const/let into next statement if used once" optimization 152 null, 153 null, 154 void 0, 155 void 0, 156 1234567, 157 1234567, 158 123.456, 159 123.456, 160 s_keep, 161 s_keep 162 ); 163 } 164 165 ---------- /out/nested-function.js ---------- 166 function nested() { 167 const s_keep = ""; 168 console.log( 169 // These are doubled to avoid the "inline const/let into next statement if used once" optimization 170 null, 171 null, 172 void 0, 173 void 0, 174 1234567, 175 1234567, 176 123.456, 177 123.456, 178 s_keep, 179 s_keep 180 ); 181 } 182 183 ---------- /out/namespace-export.js ---------- 184 var ns; 185 ((ns2) => (ns2.y_keep = 2, console.log( 186 1, 187 1, 188 2, 189 2 190 )))(ns ||= {}); 191 192 ---------- /out/comment-before.js ---------- 193 { 194 //! comment 195 x = [1, 1]; 196 } 197 198 ---------- /out/directive-before.js ---------- 199 function nested() { 200 "directive"; 201 x = [1, 1]; 202 } 203 204 ---------- /out/semicolon-before.js ---------- 205 x = [1, 1]; 206 207 ---------- /out/debugger-before.js ---------- 208 { 209 debugger; 210 x = [1, 1]; 211 } 212 213 ---------- /out/type-before.js ---------- 214 x = [1, 1]; 215 216 ---------- /out/exprs-before.js ---------- 217 function nested() { 218 const x = [, "", {}, 0n, /./, function() { 219 }, () => { 220 }]; 221 function foo() { 222 return 1; 223 } 224 } 225 226 ---------- /out/disabled-tdz.js ---------- 227 foo(); 228 const x_keep = 1; 229 function foo() { 230 return x_keep; 231 } 232 233 ---------- /out/backwards-reference-top-level.js ---------- 234 const x = y, y = 1; 235 console.log( 236 x, 237 x, 238 y, 239 y 240 ); 241 242 ---------- /out/backwards-reference-nested-function.js ---------- 243 function foo() { 244 const x = y, y = 1; 245 console.log( 246 x, 247 x, 248 y, 249 y 250 ); 251 } 252 253 ---------- /out/issue-3125.js ---------- 254 function foo() { 255 const f = () => x, x = 0; 256 return f(); 257 } 258 259 ================================================================================ 260 TestCrossModuleConstantFoldingNumber 261 ---------- /out/enum-entry.js ---------- 262 // enum-entry.ts 263 console.log([ 264 6, 265 -6, 266 -7, 267 !6 /* b */, 268 typeof 6 /* b */ 269 ], [ 270 9, 271 -3, 272 3 /* a */ * 6 /* b */, 273 3 /* a */ / 6 /* b */, 274 3 /* a */ % 6 /* b */, 275 3 /* a */ ** 6 /* b */ 276 ], [ 277 !0, 278 !1, 279 !0, 280 !1, 281 !1, 282 !0, 283 !1, 284 !0 285 ], [ 286 12, 287 3, 288 3 289 ], [ 290 2, 291 7, 292 5 293 ], [ 294 6 /* b */, 295 3 /* a */, 296 3 /* a */, 297 "y", 298 "n" 299 ]); 300 301 ---------- /out/const-entry.js ---------- 302 // const-entry.js 303 console.log([ 304 6, 305 -6, 306 -7, 307 !6, 308 typeof 6 309 ], [ 310 9, 311 -3, 312 3 * 6, 313 3 / 6, 314 3 % 6, 315 3 ** 6 316 ], [ 317 !0, 318 !1, 319 !0, 320 !1, 321 !1, 322 !0, 323 !1, 324 !0 325 ], [ 326 12, 327 3, 328 3 329 ], [ 330 2, 331 7, 332 5 333 ], [ 334 6, 335 3, 336 3, 337 "y", 338 "n" 339 ]); 340 341 ---------- /out/nested-entry.js ---------- 342 // nested-entry.ts 343 console.log({ 344 "should be 4": 4, 345 "should be 32": 32 346 }); 347 348 ================================================================================ 349 TestCrossModuleConstantFoldingString 350 ---------- /out/enum-entry.js ---------- 351 // enum-entry.ts 352 console.log([ 353 typeof "bar" /* b */ 354 ], [ 355 "foobar" 356 ], [ 357 !1, 358 !0, 359 !1, 360 !0, 361 !1, 362 !0, 363 !1, 364 !0 365 ], [ 366 "bar" /* b */, 367 "foo" /* a */, 368 "foo" /* a */, 369 "y", 370 "n" 371 ]); 372 373 ---------- /out/const-entry.js ---------- 374 // const-constants.js 375 var a = "foo", b = "bar"; 376 377 // const-entry.js 378 console.log([ 379 typeof b 380 ], [ 381 a + b 382 ], [ 383 a < b, 384 a > b, 385 a <= b, 386 a >= b, 387 a == b, 388 a != b, 389 a === b, 390 a !== b 391 ], [ 392 a && b, 393 a || b, 394 a ?? b, 395 a ? "y" : "n", 396 b ? "n" : "y" 397 ]); 398 399 ---------- /out/nested-entry.js ---------- 400 // nested-constants.ts 401 var a = "foo", b = "bar", c = "baz"; 402 403 // nested-entry.ts 404 console.log({ 405 "should be foobarbaz": a + b + c, 406 "should be FOOBARBAZ": "FOOBARBAZ" 407 }); 408 409 ================================================================================ 410 TestDCEClassStaticBlocks 411 ---------- /out.js ---------- 412 // entry.ts 413 var A_keep = class { 414 static { 415 foo; 416 } 417 }; 418 var B_keep = class { 419 static { 420 this.foo; 421 } 422 }; 423 var C_keep = class { 424 static { 425 try { 426 foo; 427 } catch { 428 } 429 } 430 }; 431 var D_keep = class { 432 static { 433 try { 434 } finally { 435 foo; 436 } 437 } 438 }; 439 440 ================================================================================ 441 TestDCEClassStaticBlocksMinifySyntax 442 ---------- /out.js ---------- 443 // entry.ts 444 var A_keep = class { 445 static { 446 foo; 447 } 448 }, B_keep = class { 449 static { 450 this.foo; 451 } 452 }, C_keep = class { 453 static { 454 try { 455 foo; 456 } catch { 457 } 458 } 459 }, D_keep = class { 460 static { 461 try { 462 } finally { 463 foo; 464 } 465 } 466 }; 467 468 ================================================================================ 469 TestDCEOfDecorators 470 ---------- /out/keep-these.js ---------- 471 // decorator.js 472 var fn = () => { 473 console.log("side effect"); 474 }; 475 476 // keep-these.js 477 var Class = @fn class { 478 }; 479 var Field = class { 480 @fn field; 481 }; 482 var Method = class { 483 @fn method() { 484 } 485 }; 486 var Accessor = class { 487 @fn accessor accessor; 488 }; 489 var StaticField = class { 490 @fn static field; 491 }; 492 var StaticMethod = class { 493 @fn static method() { 494 } 495 }; 496 var StaticAccessor = class { 497 @fn static accessor accessor; 498 }; 499 500 ================================================================================ 501 TestDCEOfDestructuring 502 ---------- /out/entry.js ---------- 503 // entry.js 504 var KEEP1 = x; 505 var [KEEP2] = [x]; 506 var [KEEP3] = [...{}]; 507 var { KEEP4 } = {}; 508 509 ================================================================================ 510 TestDCEOfExperimentalDecorators 511 ---------- /out/keep-these.js ---------- 512 // decorator.ts 513 var fn = () => { 514 console.log("side effect"); 515 }; 516 517 // keep-these.ts 518 var Class = class { 519 }; 520 Class = __decorateClass([ 521 fn 522 ], Class); 523 var Field = class { 524 field; 525 }; 526 __decorateClass([ 527 fn 528 ], Field.prototype, "field", 2); 529 var Method = class { 530 method() { 531 } 532 }; 533 __decorateClass([ 534 fn 535 ], Method.prototype, "method", 1); 536 var Accessor = class { 537 accessor accessor; 538 }; 539 __decorateClass([ 540 fn 541 ], Accessor.prototype, "accessor", 1); 542 var Parameter = class { 543 foo(bar) { 544 } 545 }; 546 __decorateClass([ 547 __decorateParam(0, fn) 548 ], Parameter.prototype, "foo", 1); 549 var StaticField = class { 550 static field; 551 }; 552 __decorateClass([ 553 fn 554 ], StaticField, "field", 2); 555 var StaticMethod = class { 556 static method() { 557 } 558 }; 559 __decorateClass([ 560 fn 561 ], StaticMethod, "method", 1); 562 var StaticAccessor = class { 563 static accessor accessor; 564 }; 565 __decorateClass([ 566 fn 567 ], StaticAccessor, "accessor", 1); 568 var StaticParameter = class { 569 static foo(bar) { 570 } 571 }; 572 __decorateClass([ 573 __decorateParam(0, fn) 574 ], StaticParameter, "foo", 1); 575 576 ================================================================================ 577 TestDCEOfExprAfterKeepNamesIssue3195 578 ---------- /out.js ---------- 579 (() => { 580 function f() { 581 } 582 __name(f, "f"), firstImportantSideEffect(void 0); 583 })(), (() => { 584 function g() { 585 } 586 __name(g, "g"); 587 debugger; 588 secondImportantSideEffect(void 0); 589 })(); 590 591 ================================================================================ 592 TestDCEOfIIFE 593 ---------- /out/remove-these.js ---------- 594 keepThisButRemoveTheIIFE; 595 596 ---------- /out/keep-these.js ---------- 597 undef = void 0; 598 keepMe(); 599 ((x = keepMe()) => { 600 })(); 601 var someVar; 602 (([y]) => { 603 })(someVar); 604 (({ z }) => { 605 })(someVar); 606 var keepThis = stuff(); 607 keepThis(); 608 ((_ = keepMe()) => { 609 })(); 610 var isPure = /* @__PURE__ */ ((x, y) => 123)(); 611 use(isPure); 612 var isNotPure = ((x = foo, y = bar) => 123)(); 613 use(isNotPure); 614 (async () => ({ get then() { 615 notPure(); 616 } }))(); 617 (async function() { 618 return { get then() { 619 notPure(); 620 } }; 621 })(); 622 623 ================================================================================ 624 TestDCEOfSymbolInstances 625 ---------- /out/class.js ---------- 626 // class.js 627 var Keep1 = class { 628 *[Symbol.iterator]() { 629 } 630 [keep]; 631 }; 632 var Keep2 = class { 633 [keep]; 634 *[Symbol.iterator]() { 635 } 636 }; 637 var Keep3 = class { 638 *[Symbol.wtf]() { 639 } 640 }; 641 642 ---------- /out/object.js ---------- 643 // object.js 644 var keep1 = { *[Symbol.iterator]() { 645 }, [keep]: null }; 646 var keep2 = { [keep]: null, *[Symbol.iterator]() { 647 } }; 648 var keep3 = { *[Symbol.wtf]() { 649 } }; 650 651 ================================================================================ 652 TestDCEOfUsingDeclarations 653 ---------- /out/entry.js ---------- 654 // entry.js 655 using null_keep = null; 656 await using await_null_keep = null; 657 using throw_keep = {}; 658 using dispose_keep = { [Symbol.dispose]() { 659 console.log("side effect"); 660 } }; 661 await using await_asyncDispose_keep = { [Symbol.asyncDispose]() { 662 console.log("side effect"); 663 } }; 664 using undef_keep = void 0; 665 await using await_undef_keep = void 0; 666 console.log( 667 null_keep, 668 undef_keep 669 ); 670 671 ================================================================================ 672 TestDCETemplateLiteral 673 ---------- /out/entry.js ---------- 674 // entry.js 675 var alsoKeep; 676 var a = `${keep}`; 677 var c = `${keep ? 1 : 2n}`; 678 var e = `${alsoKeep}`; 679 680 ================================================================================ 681 TestDCETypeOf 682 ---------- /out.js ---------- 683 684 ================================================================================ 685 TestDCETypeOfCompareStringGuardCondition 686 ---------- /out.js ---------- 687 (() => { 688 // entry.js 689 var keep_1 = typeof x <= "u" ? y : null; 690 var keep_1 = typeof x < "u" ? y : null; 691 var keep_1 = typeof x >= "u" ? null : y; 692 var keep_1 = typeof x > "u" ? null : y; 693 var keep_1 = typeof x <= "u" && y; 694 var keep_1 = typeof x < "u" && y; 695 var keep_1 = typeof x >= "u" || y; 696 var keep_1 = typeof x > "u" || y; 697 var keep_1 = "u" >= typeof x ? y : null; 698 var keep_1 = "u" > typeof x ? y : null; 699 var keep_1 = "u" <= typeof x ? null : y; 700 var keep_1 = "u" < typeof x ? null : y; 701 var keep_1 = "u" >= typeof x && y; 702 var keep_1 = "u" > typeof x && y; 703 var keep_1 = "u" <= typeof x || y; 704 var keep_1 = "u" < typeof x || y; 705 var keep_2 = typeof x <= "u" ? null : x; 706 var keep_2 = typeof x < "u" ? null : x; 707 var keep_2 = typeof x >= "u" ? x : null; 708 var keep_2 = typeof x > "u" ? x : null; 709 var keep_2 = typeof x <= "u" || x; 710 var keep_2 = typeof x < "u" || x; 711 var keep_2 = typeof x >= "u" && x; 712 var keep_2 = typeof x > "u" && x; 713 var keep_2 = "u" >= typeof x ? null : x; 714 var keep_2 = "u" > typeof x ? null : x; 715 var keep_2 = "u" <= typeof x ? x : null; 716 var keep_2 = "u" < typeof x ? x : null; 717 var keep_2 = "u" >= typeof x || x; 718 var keep_2 = "u" > typeof x || x; 719 var keep_2 = "u" <= typeof x && x; 720 var keep_2 = "u" < typeof x && x; 721 })(); 722 723 ================================================================================ 724 TestDCETypeOfEqualsString 725 ---------- /out.js ---------- 726 (() => { 727 // entry.js 728 if (false) console.log(hasBar); 729 })(); 730 731 ================================================================================ 732 TestDCETypeOfEqualsStringGuardCondition 733 ---------- /out.js ---------- 734 (() => { 735 // entry.js 736 var keep_1 = typeof x !== "object" ? x : null; 737 var keep_1 = typeof x != "object" ? x : null; 738 var keep_1 = typeof x === "object" ? null : x; 739 var keep_1 = typeof x == "object" ? null : x; 740 var keep_1 = typeof x !== "object" && x; 741 var keep_1 = typeof x != "object" && x; 742 var keep_1 = typeof x === "object" || x; 743 var keep_1 = typeof x == "object" || x; 744 var keep_1 = "object" !== typeof x ? x : null; 745 var keep_1 = "object" != typeof x ? x : null; 746 var keep_1 = "object" === typeof x ? null : x; 747 var keep_1 = "object" == typeof x ? null : x; 748 var keep_1 = "object" !== typeof x && x; 749 var keep_1 = "object" != typeof x && x; 750 var keep_1 = "object" === typeof x || x; 751 var keep_1 = "object" == typeof x || x; 752 var keep_2 = typeof x !== "undefined" ? y : null; 753 var keep_2 = typeof x != "undefined" ? y : null; 754 var keep_2 = typeof x === "undefined" ? null : y; 755 var keep_2 = typeof x == "undefined" ? null : y; 756 var keep_2 = typeof x !== "undefined" && y; 757 var keep_2 = typeof x != "undefined" && y; 758 var keep_2 = typeof x === "undefined" || y; 759 var keep_2 = typeof x == "undefined" || y; 760 var keep_2 = "undefined" !== typeof x ? y : null; 761 var keep_2 = "undefined" != typeof x ? y : null; 762 var keep_2 = "undefined" === typeof x ? null : y; 763 var keep_2 = "undefined" == typeof x ? null : y; 764 var keep_2 = "undefined" !== typeof x && y; 765 var keep_2 = "undefined" != typeof x && y; 766 var keep_2 = "undefined" === typeof x || y; 767 var keep_2 = "undefined" == typeof x || y; 768 var keep_3 = typeof x !== "undefined" ? null : x; 769 var keep_3 = typeof x != "undefined" ? null : x; 770 var keep_3 = typeof x === "undefined" ? x : null; 771 var keep_3 = typeof x == "undefined" ? x : null; 772 var keep_3 = typeof x !== "undefined" || x; 773 var keep_3 = typeof x != "undefined" || x; 774 var keep_3 = typeof x === "undefined" && x; 775 var keep_3 = typeof x == "undefined" && x; 776 var keep_3 = "undefined" !== typeof x ? null : x; 777 var keep_3 = "undefined" != typeof x ? null : x; 778 var keep_3 = "undefined" === typeof x ? x : null; 779 var keep_3 = "undefined" == typeof x ? x : null; 780 var keep_3 = "undefined" !== typeof x || x; 781 var keep_3 = "undefined" != typeof x || x; 782 var keep_3 = "undefined" === typeof x && x; 783 var keep_3 = "undefined" == typeof x && x; 784 })(); 785 786 ================================================================================ 787 TestDCETypeOfEqualsStringMangle 788 ---------- /out.js ---------- 789 (() => { 790 })(); 791 792 ================================================================================ 793 TestDCEVarExports 794 ---------- /out/a.js ---------- 795 // a.js 796 var require_a = __commonJS({ 797 "a.js"(exports, module) { 798 var foo = { bar: 123 }; 799 module.exports = foo; 800 } 801 }); 802 export default require_a(); 803 804 ---------- /out/b.js ---------- 805 // b.js 806 var require_b = __commonJS({ 807 "b.js"(exports, module) { 808 var exports = { bar: 123 }; 809 module.exports = exports; 810 } 811 }); 812 export default require_b(); 813 814 ---------- /out/c.js ---------- 815 // c.js 816 var require_c = __commonJS({ 817 "c.js"(exports, module) { 818 var module = { bar: 123 }; 819 exports.foo = module; 820 } 821 }); 822 export default require_c(); 823 824 ================================================================================ 825 TestDataURLLoaderRemoveUnused 826 ---------- /out.js ---------- 827 // entry.js 828 console.log("unused import"); 829 830 ================================================================================ 831 TestDeadCodeFollowingJump 832 ---------- /out.js ---------- 833 // entry.js 834 function testReturn() { 835 return y + z(); 836 if (x) 837 var y; 838 function z() { 839 KEEP_ME(); 840 } 841 } 842 function testThrow() { 843 throw y + z(); 844 if (x) 845 var y; 846 function z() { 847 KEEP_ME(); 848 } 849 } 850 function testBreak() { 851 for (; ; ) { 852 let z2 = function() { 853 KEEP_ME(); 854 }; 855 var z = z2; 856 y + z2(); 857 break; 858 if (x) 859 var y; 860 } 861 } 862 function testContinue() { 863 for (; ; ) { 864 let z2 = function() { 865 KEEP_ME(); 866 }; 867 var z = z2; 868 y + z2(); 869 continue; 870 if (x) 871 var y; 872 } 873 } 874 function testStmts() { 875 return [a, b, c, d, e, f, g, h, i]; 876 for (; x; ) 877 var a; 878 do 879 var b; 880 while (x); 881 for (var c; ; ) ; 882 for (var d in x) ; 883 for (var e of x) ; 884 if (x) 885 var f; 886 if (!x) var g; 887 var h, i; 888 } 889 testReturn(); 890 testThrow(); 891 testBreak(); 892 testContinue(); 893 testStmts(); 894 895 ================================================================================ 896 TestDisableTreeShaking 897 ---------- /out.js ---------- 898 // keep-me/index.js 899 console.log("side effects"); 900 901 // entry.jsx 902 function KeepMe1() { 903 } 904 var keepMe2 = React.createElement(KeepMe1, null); 905 function keepMe3() { 906 console.log("side effects"); 907 } 908 var keepMe4 = keepMe3(); 909 var keepMe5 = pure(); 910 var keepMe6 = some.fn(); 911 912 ================================================================================ 913 TestDropLabelTreeShakingBugIssue3311 914 ---------- /out.js ---------- 915 // entry.js 916 var myFunc = () => { 917 console.log("keep"); 918 }; 919 var entry_default = myFunc; 920 export { 921 entry_default as default 922 }; 923 924 ================================================================================ 925 TestDropLabels 926 ---------- /out.js ---------- 927 // entry.js 928 keep_1: require("foo1"); 929 exports.bar = function() { 930 if (x) ; 931 if (y) keep_2: require("bar2"); 932 }; 933 934 ================================================================================ 935 TestFileLoaderRemoveUnused 936 ---------- /out.js ---------- 937 // entry.js 938 console.log("unused import"); 939 940 ================================================================================ 941 TestImportReExportOfNamespaceImport 942 ---------- /out.js ---------- 943 // Users/user/project/node_modules/pkg/foo.js 944 var require_foo = __commonJS({ 945 "Users/user/project/node_modules/pkg/foo.js"(exports, module) { 946 module.exports = 123; 947 } 948 }); 949 950 // Users/user/project/node_modules/pkg/index.js 951 var import_foo = __toESM(require_foo()); 952 953 // Users/user/project/entry.js 954 console.log(import_foo.default); 955 956 ================================================================================ 957 TestInlineEmptyFunctionCalls 958 ---------- /out/empty.js ---------- 959 // empty.js 960 console.log((foo(), bar(), void 0)); 961 console.log((foo(), void 0)); 962 console.log((foo(), void 0)); 963 console.log(void 0); 964 console.log(void 0); 965 foo(), bar(); 966 foo(); 967 foo(); 968 969 ---------- /out/empty-comma.js ---------- 970 // empty-comma.js 971 console.log(foo()); 972 console.log((foo(), void 0)); 973 console.log((foo(), void 0)); 974 for (; void 0; ) ; 975 foo(); 976 foo(); 977 foo(); 978 979 ---------- /out/empty-if-else.js ---------- 980 // empty-if-else.js 981 if (foo) { 982 let bar = baz(); 983 bar(), bar(); 984 } 985 986 ---------- /out/empty-last.js ---------- 987 // empty-last.js 988 console.log(void 0); 989 990 ---------- /out/empty-cross-module.js ---------- 991 // empty-cross-module.js 992 console.log(void 0); 993 994 ---------- /out/empty-first.js ---------- 995 // empty-first.js 996 function keep() { 997 return x; 998 } 999 console.log(keep()); 1000 keep(foo()); 1001 keep(1); 1002 1003 ---------- /out/empty-generator.js ---------- 1004 // empty-generator.js 1005 function* keep() { 1006 } 1007 console.log(keep()); 1008 keep(foo()); 1009 keep(1); 1010 1011 ---------- /out/empty-async.js ---------- 1012 // empty-async.js 1013 async function keep() { 1014 } 1015 console.log(keep()); 1016 keep(foo()); 1017 keep(1); 1018 1019 ---------- /out/reassign.js ---------- 1020 // reassign.js 1021 function keep() { 1022 } 1023 keep = reassigned; 1024 console.log(keep()); 1025 keep(foo()); 1026 keep(1); 1027 1028 ---------- /out/reassign-inc.js ---------- 1029 // reassign-inc.js 1030 function keep() { 1031 } 1032 keep++; 1033 console.log(keep(1)); 1034 keep(foo()); 1035 keep(1); 1036 1037 ---------- /out/reassign-div.js ---------- 1038 // reassign-div.js 1039 function keep() { 1040 } 1041 keep /= reassigned; 1042 console.log(keep(1)); 1043 keep(foo()); 1044 keep(1); 1045 1046 ---------- /out/reassign-array.js ---------- 1047 // reassign-array.js 1048 function keep() { 1049 } 1050 [keep] = reassigned; 1051 console.log(keep(1)); 1052 keep(foo()); 1053 keep(1); 1054 1055 ---------- /out/reassign-object.js ---------- 1056 // reassign-object.js 1057 function keep() { 1058 } 1059 ({ keep } = reassigned); 1060 console.log(keep(1)); 1061 keep(foo()); 1062 keep(1); 1063 1064 ================================================================================ 1065 TestInlineFunctionCallBehaviorChanges 1066 ---------- /out/entry.js ---------- 1067 function empty() { 1068 } 1069 function id(x) { 1070 return x; 1071 } 1072 export let shouldBeWrapped = [ 1073 (0, foo.bar)(), 1074 (0, foo[bar])(), 1075 (0, foo?.bar)(), 1076 (0, foo?.[bar])(), 1077 (0, foo.bar)(), 1078 (0, foo[bar])(), 1079 (0, foo?.bar)(), 1080 (0, foo?.[bar])(), 1081 (0, eval)(), 1082 (0, eval)?.(), 1083 (0, eval)(), 1084 (0, eval)?.(), 1085 (0, foo.bar)``, 1086 (0, foo[bar])``, 1087 (0, foo?.bar)``, 1088 (0, foo?.[bar])``, 1089 (0, foo.bar)``, 1090 (0, foo[bar])``, 1091 (0, foo?.bar)``, 1092 (0, foo?.[bar])``, 1093 delete (0, foo), 1094 delete (0, foo.bar), 1095 delete (0, foo[bar]), 1096 delete (0, foo?.bar), 1097 delete (0, foo?.[bar]), 1098 delete (0, foo), 1099 delete (0, foo.bar), 1100 delete (0, foo[bar]), 1101 delete (0, foo?.bar), 1102 delete (0, foo?.[bar]), 1103 delete (0, void 0) 1104 ], shouldNotBeWrapped = [ 1105 foo(), 1106 foo(), 1107 foo``, 1108 foo`` 1109 ], shouldNotBeDoubleWrapped = [ 1110 delete (foo(), bar()), 1111 delete (foo(), bar()) 1112 ]; 1113 1114 ================================================================================ 1115 TestInlineFunctionCallForInitDecl 1116 ---------- /out/entry.js ---------- 1117 // entry.js 1118 for (y = void 0; !1; ) ; 1119 var y; 1120 for (z = 123; !1; ) ; 1121 var z; 1122 1123 ================================================================================ 1124 TestInlineIdentityFunctionCalls 1125 ---------- /out/identity.js ---------- 1126 // identity.js 1127 console.log(1); 1128 foo(); 1129 1130 ---------- /out/identity-last.js ---------- 1131 // identity-last.js 1132 console.log(1); 1133 foo(); 1134 1135 ---------- /out/identity-first.js ---------- 1136 // identity-first.js 1137 function keep(x) { 1138 return [x]; 1139 } 1140 console.log(keep(1)); 1141 keep(foo()); 1142 keep(1); 1143 1144 ---------- /out/identity-generator.js ---------- 1145 // identity-generator.js 1146 function* keep(x) { 1147 return x; 1148 } 1149 console.log(keep(1)); 1150 keep(foo()); 1151 keep(1); 1152 1153 ---------- /out/identity-async.js ---------- 1154 // identity-async.js 1155 async function keep(x) { 1156 return x; 1157 } 1158 console.log(keep(1)); 1159 keep(foo()); 1160 keep(1); 1161 1162 ---------- /out/identity-cross-module.js ---------- 1163 // identity-cross-module.js 1164 console.log(1); 1165 foo(); 1166 1167 ---------- /out/identity-no-args.js ---------- 1168 // identity-no-args.js 1169 function keep(x) { 1170 return x; 1171 } 1172 console.log(keep()); 1173 keep(); 1174 1175 ---------- /out/identity-two-args.js ---------- 1176 // identity-two-args.js 1177 function keep(x) { 1178 return x; 1179 } 1180 console.log(keep(1, 2)); 1181 keep(1, 2); 1182 1183 ---------- /out/reassign.js ---------- 1184 // reassign.js 1185 function keep(x) { 1186 return x; 1187 } 1188 keep = reassigned; 1189 console.log(keep(1)); 1190 keep(foo()); 1191 keep(1); 1192 1193 ---------- /out/reassign-inc.js ---------- 1194 // reassign-inc.js 1195 function keep(x) { 1196 return x; 1197 } 1198 keep++; 1199 console.log(keep(1)); 1200 keep(foo()); 1201 keep(1); 1202 1203 ---------- /out/reassign-div.js ---------- 1204 // reassign-div.js 1205 function keep(x) { 1206 return x; 1207 } 1208 keep /= reassigned; 1209 console.log(keep(1)); 1210 keep(foo()); 1211 keep(1); 1212 1213 ---------- /out/reassign-array.js ---------- 1214 // reassign-array.js 1215 function keep(x) { 1216 return x; 1217 } 1218 [keep] = reassigned; 1219 console.log(keep(1)); 1220 keep(foo()); 1221 keep(1); 1222 1223 ---------- /out/reassign-object.js ---------- 1224 // reassign-object.js 1225 function keep(x) { 1226 return x; 1227 } 1228 ({ keep } = reassigned); 1229 console.log(keep(1)); 1230 keep(foo()); 1231 keep(1); 1232 1233 ---------- /out/not-identity-two-args.js ---------- 1234 // not-identity-two-args.js 1235 function keep(x, y) { 1236 return x; 1237 } 1238 console.log(keep(1)); 1239 keep(foo()); 1240 keep(1); 1241 1242 ---------- /out/not-identity-default.js ---------- 1243 // not-identity-default.js 1244 function keep(x = foo()) { 1245 return x; 1246 } 1247 console.log(keep(1)); 1248 keep(foo()); 1249 keep(1); 1250 1251 ---------- /out/not-identity-array.js ---------- 1252 // not-identity-array.js 1253 function keep([x]) { 1254 return x; 1255 } 1256 console.log(keep(1)); 1257 keep(foo()); 1258 keep(1); 1259 1260 ---------- /out/not-identity-object.js ---------- 1261 // not-identity-object.js 1262 function keep({ x }) { 1263 return x; 1264 } 1265 console.log(keep(1)); 1266 keep(foo()); 1267 keep(1); 1268 1269 ---------- /out/not-identity-rest.js ---------- 1270 // not-identity-rest.js 1271 function keep(...x) { 1272 return x; 1273 } 1274 console.log(keep(1)); 1275 keep(foo()); 1276 keep(1); 1277 1278 ---------- /out/not-identity-return.js ---------- 1279 // not-identity-return.js 1280 function keep(x) { 1281 return [x]; 1282 } 1283 console.log(keep(1)); 1284 keep(foo()); 1285 keep(1); 1286 1287 ================================================================================ 1288 TestJSONLoaderRemoveUnused 1289 ---------- /out.js ---------- 1290 // entry.js 1291 console.log("unused import"); 1292 1293 ================================================================================ 1294 TestMultipleDeclarationTreeShaking 1295 ---------- /out/var2.js ---------- 1296 // var2.js 1297 var x = 1; 1298 console.log(x); 1299 var x = 2; 1300 1301 ---------- /out/var3.js ---------- 1302 // var3.js 1303 var x = 1; 1304 console.log(x); 1305 var x = 2; 1306 console.log(x); 1307 var x = 3; 1308 1309 ---------- /out/function2.js ---------- 1310 // function2.js 1311 function x() { 1312 return 1; 1313 } 1314 console.log(x()); 1315 function x() { 1316 return 2; 1317 } 1318 1319 ---------- /out/function3.js ---------- 1320 // function3.js 1321 function x() { 1322 return 1; 1323 } 1324 console.log(x()); 1325 function x() { 1326 return 2; 1327 } 1328 console.log(x()); 1329 function x() { 1330 return 3; 1331 } 1332 1333 ================================================================================ 1334 TestMultipleDeclarationTreeShakingMinifySyntax 1335 ---------- /out/var2.js ---------- 1336 // var2.js 1337 var x = 1; 1338 console.log(x); 1339 var x = 2; 1340 1341 ---------- /out/var3.js ---------- 1342 // var3.js 1343 var x = 1; 1344 console.log(x); 1345 var x = 2; 1346 console.log(x); 1347 var x = 3; 1348 1349 ---------- /out/function2.js ---------- 1350 // function2.js 1351 console.log(x()); 1352 function x() { 1353 return 2; 1354 } 1355 1356 ---------- /out/function3.js ---------- 1357 // function3.js 1358 console.log(x()); 1359 console.log(x()); 1360 function x() { 1361 return 3; 1362 } 1363 1364 ================================================================================ 1365 TestNestedFunctionInliningWithSpread 1366 ---------- /out/entry.js ---------- 1367 // entry.js 1368 function identity1(x) { 1369 return x; 1370 } 1371 function identity3(x) { 1372 return x; 1373 } 1374 check( 1375 void 0, 1376 (args, void 0), 1377 ([...args], void 0), 1378 identity1(), 1379 args, 1380 identity3(...args) 1381 ); 1382 1383 ---------- /out/entry-outer.js ---------- 1384 // inner.js 1385 function identity1(x) { 1386 return x; 1387 } 1388 function identity3(x) { 1389 return x; 1390 } 1391 1392 // entry-outer.js 1393 check( 1394 void 0, 1395 (args, void 0), 1396 ([...args], void 0), 1397 identity1(), 1398 args, 1399 identity3(...args) 1400 ); 1401 1402 ================================================================================ 1403 TestNoSideEffectsComment 1404 ---------- /out/expr-fn.js ---------- 1405 //! These should all have "no side effects" 1406 x([ 1407 /* @__NO_SIDE_EFFECTS__ */ function() { 1408 }, 1409 /* @__NO_SIDE_EFFECTS__ */ function y() { 1410 }, 1411 /* @__NO_SIDE_EFFECTS__ */ function* () { 1412 }, 1413 /* @__NO_SIDE_EFFECTS__ */ function* y2() { 1414 }, 1415 /* @__NO_SIDE_EFFECTS__ */ async function() { 1416 }, 1417 /* @__NO_SIDE_EFFECTS__ */ async function y3() { 1418 }, 1419 /* @__NO_SIDE_EFFECTS__ */ async function* () { 1420 }, 1421 /* @__NO_SIDE_EFFECTS__ */ async function* y4() { 1422 } 1423 ]); 1424 1425 ---------- /out/expr-arrow.js ---------- 1426 //! These should all have "no side effects" 1427 x([ 1428 /* @__NO_SIDE_EFFECTS__ */ (y) => y, 1429 /* @__NO_SIDE_EFFECTS__ */ () => { 1430 }, 1431 /* @__NO_SIDE_EFFECTS__ */ (y) => y, 1432 /* @__NO_SIDE_EFFECTS__ */ async (y) => y, 1433 /* @__NO_SIDE_EFFECTS__ */ async () => { 1434 }, 1435 /* @__NO_SIDE_EFFECTS__ */ async (y) => y 1436 ]); 1437 1438 ---------- /out/stmt-fn.js ---------- 1439 //! These should all have "no side effects" 1440 // @__NO_SIDE_EFFECTS__ 1441 function a() { 1442 } 1443 // @__NO_SIDE_EFFECTS__ 1444 function* b() { 1445 } 1446 // @__NO_SIDE_EFFECTS__ 1447 async function c() { 1448 } 1449 // @__NO_SIDE_EFFECTS__ 1450 async function* d() { 1451 } 1452 1453 ---------- /out/stmt-export-fn.js ---------- 1454 //! These should all have "no side effects" 1455 // @__NO_SIDE_EFFECTS__ 1456 export function a() { 1457 } 1458 // @__NO_SIDE_EFFECTS__ 1459 export function* b() { 1460 } 1461 // @__NO_SIDE_EFFECTS__ 1462 export async function c() { 1463 } 1464 // @__NO_SIDE_EFFECTS__ 1465 export async function* d() { 1466 } 1467 1468 ---------- /out/stmt-local.js ---------- 1469 //! Only "c0" and "c2" should have "no side effects" (Rollup only respects "const" and only for the first one) 1470 var v0 = function() { 1471 }, v1 = function() { 1472 }; 1473 let l0 = function() { 1474 }, l1 = function() { 1475 }; 1476 const c0 = /* @__NO_SIDE_EFFECTS__ */ function() { 1477 }, c1 = function() { 1478 }; 1479 var v2 = () => { 1480 }, v3 = () => { 1481 }; 1482 let l2 = () => { 1483 }, l3 = () => { 1484 }; 1485 const c2 = /* @__NO_SIDE_EFFECTS__ */ () => { 1486 }, c3 = () => { 1487 }; 1488 1489 ---------- /out/stmt-export-local.js ---------- 1490 //! Only "c0" and "c2" should have "no side effects" (Rollup only respects "const" and only for the first one) 1491 export var v0 = function() { 1492 }, v1 = function() { 1493 }; 1494 export let l0 = function() { 1495 }, l1 = function() { 1496 }; 1497 export const c0 = /* @__NO_SIDE_EFFECTS__ */ function() { 1498 }, c1 = function() { 1499 }; 1500 export var v2 = () => { 1501 }, v3 = () => { 1502 }; 1503 export let l2 = () => { 1504 }, l3 = () => { 1505 }; 1506 export const c2 = /* @__NO_SIDE_EFFECTS__ */ () => { 1507 }, c3 = () => { 1508 }; 1509 1510 ---------- /out/ns-export-fn.js ---------- 1511 var ns; 1512 ((ns2) => { 1513 //! These should all have "no side effects" 1514 // @__NO_SIDE_EFFECTS__ 1515 function a() { 1516 } 1517 ns2.a = a; 1518 // @__NO_SIDE_EFFECTS__ 1519 function* b() { 1520 } 1521 ns2.b = b; 1522 // @__NO_SIDE_EFFECTS__ 1523 async function c() { 1524 } 1525 ns2.c = c; 1526 // @__NO_SIDE_EFFECTS__ 1527 async function* d() { 1528 } 1529 ns2.d = d; 1530 })(ns || (ns = {})); 1531 1532 ---------- /out/ns-export-local.js ---------- 1533 var ns; 1534 ((ns2) => { 1535 //! Only "c0" and "c2" should have "no side effects" (Rollup only respects "const" and only for the first one) 1536 ns2.v0 = function() { 1537 }; 1538 ns2.v1 = function() { 1539 }; 1540 ns2.l0 = function() { 1541 }; 1542 ns2.l1 = function() { 1543 }; 1544 ns2.c0 = /* @__NO_SIDE_EFFECTS__ */ function() { 1545 }; 1546 ns2.c1 = function() { 1547 }; 1548 ns2.v2 = () => { 1549 }; 1550 ns2.v3 = () => { 1551 }; 1552 ns2.l2 = () => { 1553 }; 1554 ns2.l3 = () => { 1555 }; 1556 ns2.c2 = /* @__NO_SIDE_EFFECTS__ */ () => { 1557 }; 1558 ns2.c3 = () => { 1559 }; 1560 })(ns || (ns = {})); 1561 1562 ---------- /out/stmt-export-default-before-fn-anon.js ---------- 1563 /*! This should have "no side effects" */ 1564 // @__NO_SIDE_EFFECTS__ 1565 export default function() { 1566 } 1567 1568 ---------- /out/stmt-export-default-before-fn-name.js ---------- 1569 /*! This should have "no side effects" */ 1570 // @__NO_SIDE_EFFECTS__ 1571 export default function f() { 1572 } 1573 1574 ---------- /out/stmt-export-default-before-gen-fn-anon.js ---------- 1575 /*! This should have "no side effects" */ 1576 // @__NO_SIDE_EFFECTS__ 1577 export default function* () { 1578 } 1579 1580 ---------- /out/stmt-export-default-before-gen-fn-name.js ---------- 1581 /*! This should have "no side effects" */ 1582 // @__NO_SIDE_EFFECTS__ 1583 export default function* f() { 1584 } 1585 1586 ---------- /out/stmt-export-default-before-async-fn-anon.js ---------- 1587 /*! This should have "no side effects" */ 1588 // @__NO_SIDE_EFFECTS__ 1589 export default async function() { 1590 } 1591 1592 ---------- /out/stmt-export-default-before-async-fn-name.js ---------- 1593 /*! This should have "no side effects" */ 1594 // @__NO_SIDE_EFFECTS__ 1595 export default async function f() { 1596 } 1597 1598 ---------- /out/stmt-export-default-before-async-gen-fn-anon.js ---------- 1599 /*! This should have "no side effects" */ 1600 // @__NO_SIDE_EFFECTS__ 1601 export default async function* () { 1602 } 1603 1604 ---------- /out/stmt-export-default-before-async-gen-fn-name.js ---------- 1605 /*! This should have "no side effects" */ 1606 // @__NO_SIDE_EFFECTS__ 1607 export default async function* f() { 1608 } 1609 1610 ---------- /out/stmt-export-default-after-fn-anon.js ---------- 1611 /*! This should have "no side effects" */ 1612 // @__NO_SIDE_EFFECTS__ 1613 export default function() { 1614 } 1615 1616 ---------- /out/stmt-export-default-after-fn-name.js ---------- 1617 /*! This should have "no side effects" */ 1618 // @__NO_SIDE_EFFECTS__ 1619 export default function f() { 1620 } 1621 1622 ---------- /out/stmt-export-default-after-gen-fn-anon.js ---------- 1623 /*! This should have "no side effects" */ 1624 // @__NO_SIDE_EFFECTS__ 1625 export default function* () { 1626 } 1627 1628 ---------- /out/stmt-export-default-after-gen-fn-name.js ---------- 1629 /*! This should have "no side effects" */ 1630 // @__NO_SIDE_EFFECTS__ 1631 export default function* f() { 1632 } 1633 1634 ---------- /out/stmt-export-default-after-async-fn-anon.js ---------- 1635 /*! This should have "no side effects" */ 1636 // @__NO_SIDE_EFFECTS__ 1637 export default async function() { 1638 } 1639 1640 ---------- /out/stmt-export-default-after-async-fn-name.js ---------- 1641 /*! This should have "no side effects" */ 1642 // @__NO_SIDE_EFFECTS__ 1643 export default async function f() { 1644 } 1645 1646 ---------- /out/stmt-export-default-after-async-gen-fn-anon.js ---------- 1647 /*! This should have "no side effects" */ 1648 // @__NO_SIDE_EFFECTS__ 1649 export default async function* () { 1650 } 1651 1652 ---------- /out/stmt-export-default-after-async-gen-fn-name.js ---------- 1653 /*! This should have "no side effects" */ 1654 // @__NO_SIDE_EFFECTS__ 1655 export default async function* f() { 1656 } 1657 1658 ================================================================================ 1659 TestNoSideEffectsCommentIgnoreAnnotations 1660 ---------- /out/expr-fn.js ---------- 1661 x([ 1662 function() { 1663 }, 1664 function y() { 1665 }, 1666 function* () { 1667 }, 1668 function* y2() { 1669 }, 1670 async function() { 1671 }, 1672 async function y3() { 1673 }, 1674 async function* () { 1675 }, 1676 async function* y4() { 1677 } 1678 ]); 1679 1680 ---------- /out/expr-arrow.js ---------- 1681 x([ 1682 (y) => y, 1683 () => { 1684 }, 1685 (y) => y, 1686 async (y) => y, 1687 async () => { 1688 }, 1689 async (y) => y 1690 ]); 1691 1692 ---------- /out/stmt-fn.js ---------- 1693 function a() { 1694 } 1695 function* b() { 1696 } 1697 async function c() { 1698 } 1699 async function* d() { 1700 } 1701 1702 ---------- /out/stmt-export-fn.js ---------- 1703 export function a() { 1704 } 1705 export function* b() { 1706 } 1707 export async function c() { 1708 } 1709 export async function* d() { 1710 } 1711 1712 ---------- /out/stmt-local.js ---------- 1713 var v0 = function() { 1714 }, v1 = function() { 1715 }; 1716 let l0 = function() { 1717 }, l1 = function() { 1718 }; 1719 const c0 = function() { 1720 }, c1 = function() { 1721 }; 1722 var v2 = () => { 1723 }, v3 = () => { 1724 }; 1725 let l2 = () => { 1726 }, l3 = () => { 1727 }; 1728 const c2 = () => { 1729 }, c3 = () => { 1730 }; 1731 1732 ---------- /out/stmt-export-local.js ---------- 1733 export var v0 = function() { 1734 }, v1 = function() { 1735 }; 1736 export let l0 = function() { 1737 }, l1 = function() { 1738 }; 1739 export const c0 = function() { 1740 }, c1 = function() { 1741 }; 1742 export var v2 = () => { 1743 }, v3 = () => { 1744 }; 1745 export let l2 = () => { 1746 }, l3 = () => { 1747 }; 1748 export const c2 = () => { 1749 }, c3 = () => { 1750 }; 1751 1752 ---------- /out/ns-export-fn.js ---------- 1753 var ns; 1754 ((ns2) => { 1755 function a() { 1756 } 1757 ns2.a = a; 1758 function* b() { 1759 } 1760 ns2.b = b; 1761 async function c() { 1762 } 1763 ns2.c = c; 1764 async function* d() { 1765 } 1766 ns2.d = d; 1767 })(ns || (ns = {})); 1768 1769 ---------- /out/ns-export-local.js ---------- 1770 var ns; 1771 ((ns2) => { 1772 ns2.v0 = function() { 1773 }; 1774 ns2.v1 = function() { 1775 }; 1776 ns2.l0 = function() { 1777 }; 1778 ns2.l1 = function() { 1779 }; 1780 ns2.c0 = function() { 1781 }; 1782 ns2.c1 = function() { 1783 }; 1784 ns2.v2 = () => { 1785 }; 1786 ns2.v3 = () => { 1787 }; 1788 ns2.l2 = () => { 1789 }; 1790 ns2.l3 = () => { 1791 }; 1792 ns2.c2 = () => { 1793 }; 1794 ns2.c3 = () => { 1795 }; 1796 })(ns || (ns = {})); 1797 1798 ---------- /out/stmt-export-default-before-fn-anon.js ---------- 1799 export default function() { 1800 } 1801 1802 ---------- /out/stmt-export-default-before-fn-name.js ---------- 1803 export default function f() { 1804 } 1805 1806 ---------- /out/stmt-export-default-before-gen-fn-anon.js ---------- 1807 export default function* () { 1808 } 1809 1810 ---------- /out/stmt-export-default-before-gen-fn-name.js ---------- 1811 export default function* f() { 1812 } 1813 1814 ---------- /out/stmt-export-default-before-async-fn-anon.js ---------- 1815 export default async function() { 1816 } 1817 1818 ---------- /out/stmt-export-default-before-async-fn-name.js ---------- 1819 export default async function f() { 1820 } 1821 1822 ---------- /out/stmt-export-default-before-async-gen-fn-anon.js ---------- 1823 export default async function* () { 1824 } 1825 1826 ---------- /out/stmt-export-default-before-async-gen-fn-name.js ---------- 1827 export default async function* f() { 1828 } 1829 1830 ---------- /out/stmt-export-default-after-fn-anon.js ---------- 1831 export default function() { 1832 } 1833 1834 ---------- /out/stmt-export-default-after-fn-name.js ---------- 1835 export default function f() { 1836 } 1837 1838 ---------- /out/stmt-export-default-after-gen-fn-anon.js ---------- 1839 export default function* () { 1840 } 1841 1842 ---------- /out/stmt-export-default-after-gen-fn-name.js ---------- 1843 export default function* f() { 1844 } 1845 1846 ---------- /out/stmt-export-default-after-async-fn-anon.js ---------- 1847 export default async function() { 1848 } 1849 1850 ---------- /out/stmt-export-default-after-async-fn-name.js ---------- 1851 export default async function f() { 1852 } 1853 1854 ---------- /out/stmt-export-default-after-async-gen-fn-anon.js ---------- 1855 export default async function* () { 1856 } 1857 1858 ---------- /out/stmt-export-default-after-async-gen-fn-name.js ---------- 1859 export default async function* f() { 1860 } 1861 1862 ================================================================================ 1863 TestNoSideEffectsCommentMinifyWhitespace 1864 ---------- /out/expr-fn.js ---------- 1865 x([function(){},function y(){},function*(){},function*y2(){},async function(){},async function y3(){},async function*(){},async function*y4(){}]); 1866 1867 ---------- /out/expr-arrow.js ---------- 1868 x([y=>y,()=>{},y=>y,async y=>y,async()=>{},async y=>y]); 1869 1870 ---------- /out/stmt-fn.js ---------- 1871 function a(){}function*b(){}async function c(){}async function*d(){} 1872 1873 ---------- /out/stmt-export-fn.js ---------- 1874 export function a(){}export function*b(){}export async function c(){}export async function*d(){} 1875 1876 ---------- /out/stmt-local.js ---------- 1877 var v0=function(){},v1=function(){};let l0=function(){},l1=function(){};const c0=function(){},c1=function(){};var v2=()=>{},v3=()=>{};let l2=()=>{},l3=()=>{};const c2=()=>{},c3=()=>{}; 1878 1879 ---------- /out/stmt-export-local.js ---------- 1880 export var v0=function(){},v1=function(){};export let l0=function(){},l1=function(){};export const c0=function(){},c1=function(){};export var v2=()=>{},v3=()=>{};export let l2=()=>{},l3=()=>{};export const c2=()=>{},c3=()=>{}; 1881 1882 ---------- /out/ns-export-fn.js ---------- 1883 var ns;(ns2=>{function a(){}ns2.a=a;function*b(){}ns2.b=b;async function c(){}ns2.c=c;async function*d(){}ns2.d=d})(ns||(ns={})); 1884 1885 ---------- /out/ns-export-local.js ---------- 1886 var ns;(ns2=>{ns2.v0=function(){};ns2.v1=function(){};ns2.l0=function(){};ns2.l1=function(){};ns2.c0=function(){};ns2.c1=function(){};ns2.v2=()=>{};ns2.v3=()=>{};ns2.l2=()=>{};ns2.l3=()=>{};ns2.c2=()=>{};ns2.c3=()=>{}})(ns||(ns={})); 1887 1888 ---------- /out/stmt-export-default-before-fn-anon.js ---------- 1889 export default function(){} 1890 1891 ---------- /out/stmt-export-default-before-fn-name.js ---------- 1892 export default function f(){} 1893 1894 ---------- /out/stmt-export-default-before-gen-fn-anon.js ---------- 1895 export default function*(){} 1896 1897 ---------- /out/stmt-export-default-before-gen-fn-name.js ---------- 1898 export default function*f(){} 1899 1900 ---------- /out/stmt-export-default-before-async-fn-anon.js ---------- 1901 export default async function(){} 1902 1903 ---------- /out/stmt-export-default-before-async-fn-name.js ---------- 1904 export default async function f(){} 1905 1906 ---------- /out/stmt-export-default-before-async-gen-fn-anon.js ---------- 1907 export default async function*(){} 1908 1909 ---------- /out/stmt-export-default-before-async-gen-fn-name.js ---------- 1910 export default async function*f(){} 1911 1912 ---------- /out/stmt-export-default-after-fn-anon.js ---------- 1913 export default function(){} 1914 1915 ---------- /out/stmt-export-default-after-fn-name.js ---------- 1916 export default function f(){} 1917 1918 ---------- /out/stmt-export-default-after-gen-fn-anon.js ---------- 1919 export default function*(){} 1920 1921 ---------- /out/stmt-export-default-after-gen-fn-name.js ---------- 1922 export default function*f(){} 1923 1924 ---------- /out/stmt-export-default-after-async-fn-anon.js ---------- 1925 export default async function(){} 1926 1927 ---------- /out/stmt-export-default-after-async-fn-name.js ---------- 1928 export default async function f(){} 1929 1930 ---------- /out/stmt-export-default-after-async-gen-fn-anon.js ---------- 1931 export default async function*(){} 1932 1933 ---------- /out/stmt-export-default-after-async-gen-fn-name.js ---------- 1934 export default async function*f(){} 1935 1936 ================================================================================ 1937 TestNoSideEffectsCommentTypeScriptDeclare 1938 ---------- /out/entry.js ---------- 1939 var ns; 1940 ((ns2) => { 1941 })(ns || (ns = {})); 1942 1943 ================================================================================ 1944 TestNoSideEffectsCommentUnusedCalls 1945 ---------- /out/stmt-fn.js ---------- 1946 // @__NO_SIDE_EFFECTS__ 1947 function f(y) { 1948 sideEffect(y); 1949 } 1950 // @__NO_SIDE_EFFECTS__ 1951 function* g(y) { 1952 sideEffect(y); 1953 } 1954 onlyKeepThisIdentifier; 1955 onlyKeepThisIdentifier; 1956 x(/* @__PURE__ */ f("keepThisCall")); 1957 x(/* @__PURE__ */ g("keepThisCall")); 1958 1959 ---------- /out/stmt-local.js ---------- 1960 const f = /* @__NO_SIDE_EFFECTS__ */ function(y) { 1961 sideEffect(y); 1962 }, g = /* @__NO_SIDE_EFFECTS__ */ function* (y) { 1963 sideEffect(y); 1964 }; 1965 onlyKeepThisIdentifier; 1966 onlyKeepThisIdentifier; 1967 x(/* @__PURE__ */ f("keepThisCall")); 1968 x(/* @__PURE__ */ g("keepThisCall")); 1969 1970 ---------- /out/expr-fn.js ---------- 1971 const f = /* @__NO_SIDE_EFFECTS__ */ function(y) { 1972 sideEffect(y); 1973 }, g = /* @__NO_SIDE_EFFECTS__ */ function* (y) { 1974 sideEffect(y); 1975 }; 1976 onlyKeepThisIdentifier; 1977 onlyKeepThisIdentifier; 1978 x(/* @__PURE__ */ f("keepThisCall")); 1979 x(/* @__PURE__ */ g("keepThisCall")); 1980 1981 ---------- /out/stmt-export-default-fn.js ---------- 1982 // @__NO_SIDE_EFFECTS__ 1983 export default function f(y) { 1984 sideEffect(y); 1985 } 1986 onlyKeepThisIdentifier; 1987 x(/* @__PURE__ */ f("keepThisCall")); 1988 1989 ================================================================================ 1990 TestPackageJsonSideEffectsArrayGlob 1991 ---------- /out.js ---------- 1992 // Users/user/project/node_modules/demo-pkg/keep/this/file.js 1993 console.log("this should be kept"); 1994 1995 ================================================================================ 1996 TestPackageJsonSideEffectsArrayKeep 1997 ---------- /out.js ---------- 1998 // Users/user/project/node_modules/demo-pkg/index.js 1999 console.log("hello"); 2000 2001 // Users/user/project/src/entry.js 2002 console.log("unused import"); 2003 2004 ================================================================================ 2005 TestPackageJsonSideEffectsArrayKeepMainImplicitMain 2006 ---------- /out.js ---------- 2007 // Users/user/project/node_modules/demo-pkg/index-main.js 2008 var index_main_exports = {}; 2009 __export(index_main_exports, { 2010 foo: () => foo 2011 }); 2012 var foo; 2013 var init_index_main = __esm({ 2014 "Users/user/project/node_modules/demo-pkg/index-main.js"() { 2015 foo = 123; 2016 console.log("this should be kept"); 2017 } 2018 }); 2019 2020 // Users/user/project/src/entry.js 2021 init_index_main(); 2022 2023 // Users/user/project/src/require-demo-pkg.js 2024 init_index_main(); 2025 2026 // Users/user/project/src/entry.js 2027 console.log("unused import"); 2028 2029 ================================================================================ 2030 TestPackageJsonSideEffectsArrayKeepMainImplicitModule 2031 ---------- /out.js ---------- 2032 // Users/user/project/src/entry.js 2033 console.log("unused import"); 2034 2035 ================================================================================ 2036 TestPackageJsonSideEffectsArrayKeepMainUseMain 2037 ---------- /out.js ---------- 2038 // Users/user/project/node_modules/demo-pkg/index-main.js 2039 console.log("this should be kept"); 2040 2041 // Users/user/project/src/entry.js 2042 console.log("unused import"); 2043 2044 ================================================================================ 2045 TestPackageJsonSideEffectsArrayKeepMainUseModule 2046 ---------- /out.js ---------- 2047 // Users/user/project/src/entry.js 2048 console.log("unused import"); 2049 2050 ================================================================================ 2051 TestPackageJsonSideEffectsArrayKeepModuleImplicitMain 2052 ---------- /out.js ---------- 2053 // Users/user/project/node_modules/demo-pkg/index-main.js 2054 var index_main_exports = {}; 2055 __export(index_main_exports, { 2056 foo: () => foo 2057 }); 2058 var foo; 2059 var init_index_main = __esm({ 2060 "Users/user/project/node_modules/demo-pkg/index-main.js"() { 2061 foo = 123; 2062 console.log("this should be kept"); 2063 } 2064 }); 2065 2066 // Users/user/project/src/require-demo-pkg.js 2067 init_index_main(); 2068 2069 // Users/user/project/src/entry.js 2070 console.log("unused import"); 2071 2072 ================================================================================ 2073 TestPackageJsonSideEffectsArrayKeepModuleImplicitModule 2074 ---------- /out.js ---------- 2075 // Users/user/project/node_modules/demo-pkg/index-module.js 2076 console.log("this should be kept"); 2077 2078 // Users/user/project/src/entry.js 2079 console.log("unused import"); 2080 2081 ================================================================================ 2082 TestPackageJsonSideEffectsArrayKeepModuleUseMain 2083 ---------- /out.js ---------- 2084 // Users/user/project/src/entry.js 2085 console.log("unused import"); 2086 2087 ================================================================================ 2088 TestPackageJsonSideEffectsArrayKeepModuleUseModule 2089 ---------- /out.js ---------- 2090 // Users/user/project/node_modules/demo-pkg/index-module.js 2091 console.log("this should be kept"); 2092 2093 // Users/user/project/src/entry.js 2094 console.log("unused import"); 2095 2096 ================================================================================ 2097 TestPackageJsonSideEffectsArrayRemove 2098 ---------- /out.js ---------- 2099 // Users/user/project/src/entry.js 2100 console.log("unused import"); 2101 2102 ================================================================================ 2103 TestPackageJsonSideEffectsFalseAllFork 2104 ---------- /out.js ---------- 2105 // Users/user/project/node_modules/c/index.js 2106 var foo; 2107 var init_c = __esm({ 2108 "Users/user/project/node_modules/c/index.js"() { 2109 foo = "foo"; 2110 } 2111 }); 2112 2113 // Users/user/project/node_modules/b/index.js 2114 var init_b = __esm({ 2115 "Users/user/project/node_modules/b/index.js"() { 2116 init_c(); 2117 } 2118 }); 2119 2120 // Users/user/project/node_modules/a/index.js 2121 var a_exports = {}; 2122 __export(a_exports, { 2123 foo: () => foo 2124 }); 2125 var init_a = __esm({ 2126 "Users/user/project/node_modules/a/index.js"() { 2127 init_b(); 2128 } 2129 }); 2130 2131 // Users/user/project/src/entry.js 2132 Promise.resolve().then(() => (init_a(), a_exports)).then((x) => assert(x.foo === "foo")); 2133 2134 ================================================================================ 2135 TestPackageJsonSideEffectsFalseCrossPlatformSlash 2136 ---------- /out.js ---------- 2137 // Users/user/project/node_modules/demo-pkg/foo.js 2138 console.log("foo"); 2139 2140 // Users/user/project/node_modules/demo-pkg/bar/index.js 2141 console.log("bar"); 2142 2143 ================================================================================ 2144 TestPackageJsonSideEffectsFalseIntermediateFilesChainAll 2145 ---------- /out.js ---------- 2146 // Users/user/project/node_modules/d/index.js 2147 var foo = 123; 2148 2149 // Users/user/project/node_modules/b/index.js 2150 throw "keep this"; 2151 2152 // Users/user/project/src/entry.js 2153 console.log(foo); 2154 2155 ================================================================================ 2156 TestPackageJsonSideEffectsFalseIntermediateFilesChainOne 2157 ---------- /out.js ---------- 2158 // Users/user/project/node_modules/d/index.js 2159 var foo = 123; 2160 2161 // Users/user/project/node_modules/b/index.js 2162 throw "keep this"; 2163 2164 // Users/user/project/src/entry.js 2165 console.log(foo); 2166 2167 ================================================================================ 2168 TestPackageJsonSideEffectsFalseIntermediateFilesDiamond 2169 ---------- /out.js ---------- 2170 // Users/user/project/node_modules/d/index.js 2171 var foo = 123; 2172 2173 // Users/user/project/node_modules/b1/index.js 2174 throw "keep this 1"; 2175 2176 // Users/user/project/node_modules/b2/index.js 2177 throw "keep this 2"; 2178 2179 // Users/user/project/src/entry.js 2180 console.log(foo); 2181 2182 ================================================================================ 2183 TestPackageJsonSideEffectsFalseIntermediateFilesUnused 2184 ---------- /out.js ---------- 2185 2186 ================================================================================ 2187 TestPackageJsonSideEffectsFalseIntermediateFilesUsed 2188 ---------- /out.js ---------- 2189 // Users/user/project/node_modules/demo-pkg/foo.js 2190 var foo = 123; 2191 2192 // Users/user/project/node_modules/demo-pkg/index.js 2193 throw "keep this"; 2194 2195 // Users/user/project/src/entry.js 2196 console.log(foo); 2197 2198 ================================================================================ 2199 TestPackageJsonSideEffectsFalseKeepBareImportAndRequireCommonJS 2200 ---------- /out.js ---------- 2201 // Users/user/project/node_modules/demo-pkg/index.js 2202 var require_demo_pkg = __commonJS({ 2203 "Users/user/project/node_modules/demo-pkg/index.js"(exports) { 2204 exports.foo = 123; 2205 console.log("hello"); 2206 } 2207 }); 2208 2209 // Users/user/project/src/entry.js 2210 require_demo_pkg(); 2211 console.log("unused import"); 2212 2213 ================================================================================ 2214 TestPackageJsonSideEffectsFalseKeepBareImportAndRequireES6 2215 ---------- /out.js ---------- 2216 // Users/user/project/node_modules/demo-pkg/index.js 2217 var demo_pkg_exports = {}; 2218 __export(demo_pkg_exports, { 2219 foo: () => foo 2220 }); 2221 var foo; 2222 var init_demo_pkg = __esm({ 2223 "Users/user/project/node_modules/demo-pkg/index.js"() { 2224 foo = 123; 2225 console.log("hello"); 2226 } 2227 }); 2228 2229 // Users/user/project/src/entry.js 2230 init_demo_pkg(); 2231 console.log("unused import"); 2232 2233 ================================================================================ 2234 TestPackageJsonSideEffectsFalseKeepNamedImportCommonJS 2235 ---------- /out.js ---------- 2236 // Users/user/project/node_modules/demo-pkg/index.js 2237 var require_demo_pkg = __commonJS({ 2238 "Users/user/project/node_modules/demo-pkg/index.js"(exports) { 2239 exports.foo = 123; 2240 console.log("hello"); 2241 } 2242 }); 2243 2244 // Users/user/project/src/entry.js 2245 var import_demo_pkg = __toESM(require_demo_pkg()); 2246 console.log(import_demo_pkg.foo); 2247 2248 ================================================================================ 2249 TestPackageJsonSideEffectsFalseKeepNamedImportES6 2250 ---------- /out.js ---------- 2251 // Users/user/project/node_modules/demo-pkg/index.js 2252 var foo = 123; 2253 console.log("hello"); 2254 2255 // Users/user/project/src/entry.js 2256 console.log(foo); 2257 2258 ================================================================================ 2259 TestPackageJsonSideEffectsFalseKeepStarImportCommonJS 2260 ---------- /out.js ---------- 2261 // Users/user/project/node_modules/demo-pkg/index.js 2262 var require_demo_pkg = __commonJS({ 2263 "Users/user/project/node_modules/demo-pkg/index.js"(exports) { 2264 exports.foo = 123; 2265 console.log("hello"); 2266 } 2267 }); 2268 2269 // Users/user/project/src/entry.js 2270 var ns = __toESM(require_demo_pkg()); 2271 console.log(ns); 2272 2273 ================================================================================ 2274 TestPackageJsonSideEffectsFalseKeepStarImportES6 2275 ---------- /out.js ---------- 2276 // Users/user/project/node_modules/demo-pkg/index.js 2277 var demo_pkg_exports = {}; 2278 __export(demo_pkg_exports, { 2279 foo: () => foo 2280 }); 2281 var foo = 123; 2282 console.log("hello"); 2283 2284 // Users/user/project/src/entry.js 2285 console.log(demo_pkg_exports); 2286 2287 ================================================================================ 2288 TestPackageJsonSideEffectsFalseNoWarningInNodeModulesIssue999 2289 ---------- /out.js ---------- 2290 // Users/user/project/node_modules/demo-pkg/index.js 2291 console.log("unused import"); 2292 2293 // Users/user/project/src/entry.js 2294 console.log("used import"); 2295 2296 ================================================================================ 2297 TestPackageJsonSideEffectsFalseOneFork 2298 ---------- /out.js ---------- 2299 // Users/user/project/node_modules/c/index.js 2300 var foo; 2301 var init_c = __esm({ 2302 "Users/user/project/node_modules/c/index.js"() { 2303 foo = "foo"; 2304 } 2305 }); 2306 2307 // Users/user/project/node_modules/d/index.js 2308 var init_d = __esm({ 2309 "Users/user/project/node_modules/d/index.js"() { 2310 } 2311 }); 2312 2313 // Users/user/project/node_modules/b/index.js 2314 var init_b = __esm({ 2315 "Users/user/project/node_modules/b/index.js"() { 2316 init_c(); 2317 init_d(); 2318 } 2319 }); 2320 2321 // Users/user/project/node_modules/a/index.js 2322 var a_exports = {}; 2323 __export(a_exports, { 2324 foo: () => foo 2325 }); 2326 var init_a = __esm({ 2327 "Users/user/project/node_modules/a/index.js"() { 2328 init_b(); 2329 } 2330 }); 2331 2332 // Users/user/project/src/entry.js 2333 Promise.resolve().then(() => (init_a(), a_exports)).then((x) => assert(x.foo === "foo")); 2334 2335 ================================================================================ 2336 TestPackageJsonSideEffectsFalseRemoveBareImportCommonJS 2337 ---------- /out.js ---------- 2338 // Users/user/project/src/entry.js 2339 console.log("unused import"); 2340 2341 ================================================================================ 2342 TestPackageJsonSideEffectsFalseRemoveBareImportES6 2343 ---------- /out.js ---------- 2344 // Users/user/project/src/entry.js 2345 console.log("unused import"); 2346 2347 ================================================================================ 2348 TestPackageJsonSideEffectsFalseRemoveNamedImportCommonJS 2349 ---------- /out.js ---------- 2350 // Users/user/project/src/entry.js 2351 console.log("unused import"); 2352 2353 ================================================================================ 2354 TestPackageJsonSideEffectsFalseRemoveNamedImportES6 2355 ---------- /out.js ---------- 2356 // Users/user/project/src/entry.js 2357 console.log("unused import"); 2358 2359 ================================================================================ 2360 TestPackageJsonSideEffectsFalseRemoveStarImportCommonJS 2361 ---------- /out.js ---------- 2362 // Users/user/project/src/entry.js 2363 console.log("unused import"); 2364 2365 ================================================================================ 2366 TestPackageJsonSideEffectsFalseRemoveStarImportES6 2367 ---------- /out.js ---------- 2368 // Users/user/project/src/entry.js 2369 console.log("unused import"); 2370 2371 ================================================================================ 2372 TestPackageJsonSideEffectsKeepExportDefaultExpr 2373 ---------- /out.js ---------- 2374 // Users/user/project/node_modules/demo-pkg/index.js 2375 var demo_pkg_default = exprWithSideEffects(); 2376 2377 // Users/user/project/src/entry.js 2378 console.log(demo_pkg_default); 2379 2380 ================================================================================ 2381 TestPackageJsonSideEffectsNestedDirectoryRemove 2382 ---------- /out.js ---------- 2383 // Users/user/project/src/entry.js 2384 console.log("unused import"); 2385 2386 ================================================================================ 2387 TestPackageJsonSideEffectsTrueKeepCommonJS 2388 ---------- /out.js ---------- 2389 // Users/user/project/node_modules/demo-pkg/index.js 2390 var require_demo_pkg = __commonJS({ 2391 "Users/user/project/node_modules/demo-pkg/index.js"(exports) { 2392 exports.foo = 123; 2393 console.log("hello"); 2394 } 2395 }); 2396 2397 // Users/user/project/src/entry.js 2398 var import_demo_pkg = __toESM(require_demo_pkg()); 2399 console.log("unused import"); 2400 2401 ================================================================================ 2402 TestPackageJsonSideEffectsTrueKeepES6 2403 ---------- /out.js ---------- 2404 // Users/user/project/node_modules/demo-pkg/index.js 2405 console.log("hello"); 2406 2407 // Users/user/project/src/entry.js 2408 console.log("unused import"); 2409 2410 ================================================================================ 2411 TestPreserveDirectivesMinifyBundle 2412 ---------- /out.js ---------- 2413 "use 1"; 2414 "use 2"; 2415 "use 3"; 2416 (() => { 2417 // nested.js 2418 //! A 2419 //! B 2420 //! C 2421 nested(); 2422 //! D 2423 //! E 2424 //! F 2425 2426 // entry.js 2427 //! 1 2428 //! 2 2429 //! 3 2430 entry(); 2431 //! 4 2432 //! 5 2433 //! 6 2434 })(); 2435 2436 ================================================================================ 2437 TestPreserveDirectivesMinifyIIFE 2438 ---------- /out.js ---------- 2439 "use 1"; 2440 "use 2"; 2441 "use 3"; 2442 (() => { 2443 //! 1 2444 //! 2 2445 //! 3 2446 entry(); 2447 //! 4 2448 //! 5 2449 //! 6 2450 })(); 2451 2452 ================================================================================ 2453 TestPreserveDirectivesMinifyPassThrough 2454 ---------- /out.js ---------- 2455 "use 1"; 2456 "use 2"; 2457 "use 3"; 2458 //! 1 2459 //! 2 2460 //! 3 2461 entry(); 2462 //! 4 2463 //! 5 2464 //! 6 2465 2466 ================================================================================ 2467 TestPureCallsWithSpread 2468 ---------- /out.js ---------- 2469 // entry.js 2470 [...args]; 2471 [...args]; 2472 2473 ================================================================================ 2474 TestRemoveCodeAfterLabelWithReturn 2475 ---------- /out.js ---------- 2476 function earlyReturn() { 2477 onlyWithKeep(); 2478 } 2479 function loop() { 2480 if (foo()) { 2481 bar(); 2482 return; 2483 } 2484 } 2485 2486 ================================================================================ 2487 TestRemoveTrailingReturn 2488 ---------- /out.js ---------- 2489 // entry.js 2490 function foo() { 2491 a && b(); 2492 } 2493 function bar() { 2494 return a && b(), KEEP_ME; 2495 } 2496 var entry_default = [ 2497 foo, 2498 bar, 2499 function() { 2500 a && b(); 2501 }, 2502 function() { 2503 return a && b(), KEEP_ME; 2504 }, 2505 () => { 2506 a && b(); 2507 }, 2508 () => (a && b(), KEEP_ME) 2509 ]; 2510 export { 2511 entry_default as default 2512 }; 2513 2514 ================================================================================ 2515 TestRemoveUnusedImportMeta 2516 ---------- /out.js ---------- 2517 // entry.js 2518 console.log("foo is unused"); 2519 2520 ================================================================================ 2521 TestRemoveUnusedImports 2522 ---------- /out.js ---------- 2523 import "a"; 2524 import "b"; 2525 import "c"; 2526 2527 ================================================================================ 2528 TestRemoveUnusedImportsEval 2529 ---------- /out.js ---------- 2530 import a from "a"; 2531 import * as b from "b"; 2532 import { c } from "c"; 2533 eval("foo(a, b, c)"); 2534 2535 ================================================================================ 2536 TestRemoveUnusedImportsEvalTS 2537 ---------- /out.js ---------- 2538 eval("foo(a, b, c)"); 2539 2540 ================================================================================ 2541 TestRemoveUnusedNoSideEffectsTaggedTemplates 2542 ---------- /out.js ---------- 2543 // entry.js 2544 // @__NO_SIDE_EFFECTS__ 2545 function foo() { 2546 } 2547 use(foo`keep`); 2548 keep, alsoKeep; 2549 `${keep}${alsoKeep}`; 2550 2551 ================================================================================ 2552 TestRemoveUnusedPureCommentCalls 2553 ---------- /out.js ---------- 2554 // entry.js 2555 function bar() { 2556 } 2557 var bare = foo(bar); 2558 var at_no = /* @__PURE__ */ foo(bar()); 2559 var new_at_no = /* @__PURE__ */ new foo(bar()); 2560 var nospace_at_no = /* @__PURE__ */ foo(bar()); 2561 var nospace_new_at_no = /* @__PURE__ */ new foo(bar()); 2562 var num_no = /* @__PURE__ */ foo(bar()); 2563 var new_num_no = /* @__PURE__ */ new foo(bar()); 2564 var nospace_num_no = /* @__PURE__ */ foo(bar()); 2565 var nospace_new_num_no = /* @__PURE__ */ new foo(bar()); 2566 var dot_no = /* @__PURE__ */ foo(sideEffect()).dot(bar()); 2567 var new_dot_no = /* @__PURE__ */ new foo(sideEffect()).dot(bar()); 2568 var nested_no = [1, /* @__PURE__ */ foo(bar()), 2]; 2569 var new_nested_no = [1, /* @__PURE__ */ new foo(bar()), 2]; 2570 var single_at_no = /* @__PURE__ */ foo(bar()); 2571 var new_single_at_no = /* @__PURE__ */ new foo(bar()); 2572 var single_num_no = /* @__PURE__ */ foo(bar()); 2573 var new_single_num_no = /* @__PURE__ */ new foo(bar()); 2574 var bad_no = ( 2575 /* __PURE__ */ 2576 foo(bar) 2577 ); 2578 var new_bad_no = ( 2579 /* __PURE__ */ 2580 new foo(bar) 2581 ); 2582 var parens_no = foo(bar); 2583 var new_parens_no = new foo(bar); 2584 var exp_no = /* @__PURE__ */ foo() ** foo(); 2585 var new_exp_no = /* @__PURE__ */ new foo() ** foo(); 2586 2587 ================================================================================ 2588 TestTextLoaderRemoveUnused 2589 ---------- /out.js ---------- 2590 // entry.js 2591 console.log("unused import"); 2592 2593 ================================================================================ 2594 TestTopLevelFunctionInliningWithSpread 2595 ---------- /out/entry.js ---------- 2596 // entry.js 2597 function identity1(x) { 2598 return x; 2599 } 2600 function identity3(x) { 2601 return x; 2602 } 2603 args; 2604 [...args]; 2605 identity1(); 2606 args; 2607 identity3(...args); 2608 2609 ---------- /out/entry-outer.js ---------- 2610 // inner.js 2611 function identity1(x) { 2612 return x; 2613 } 2614 function identity3(x) { 2615 return x; 2616 } 2617 2618 // entry-outer.js 2619 args; 2620 [...args]; 2621 identity1(); 2622 args; 2623 identity3(...args); 2624 2625 ================================================================================ 2626 TestTreeShakingBinaryOperators 2627 ---------- /out.js ---------- 2628 // entry.js 2629 var keep; 2630 var keep2; 2631 keep + keep2; 2632 keep - keep2; 2633 keep * keep2; 2634 keep / keep2; 2635 keep % keep2; 2636 keep ** keep2; 2637 keep < keep2; 2638 keep <= keep2; 2639 keep > keep2; 2640 keep >= keep2; 2641 keep in keep2; 2642 keep instanceof keep2; 2643 keep << keep2; 2644 keep >> keep2; 2645 keep >>> keep2; 2646 keep == keep2; 2647 keep != keep2; 2648 keep | keep2; 2649 keep & keep2; 2650 keep ^ keep2; 2651 keep = keep2; 2652 keep += keep2; 2653 keep -= keep2; 2654 keep *= keep2; 2655 keep /= keep2; 2656 keep %= keep2; 2657 keep **= keep2; 2658 keep <<= keep2; 2659 keep >>= keep2; 2660 keep >>>= keep2; 2661 keep |= keep2; 2662 keep &= keep2; 2663 keep ^= keep2; 2664 keep ??= keep2; 2665 keep ||= keep2; 2666 keep &&= keep2; 2667 2668 ================================================================================ 2669 TestTreeShakingClassProperty 2670 ---------- /out.js ---------- 2671 let keep1 = class { 2672 [x] = "x"; 2673 }; 2674 let keep2 = class { 2675 [x]() { 2676 } 2677 }; 2678 let keep3 = class { 2679 get [x]() { 2680 } 2681 }; 2682 let keep4 = class { 2683 set [x](_) { 2684 } 2685 }; 2686 let keep5 = class { 2687 async [x]() { 2688 } 2689 }; 2690 let keep6 = class { 2691 [{ toString() { 2692 } }] = "x"; 2693 }; 2694 2695 ================================================================================ 2696 TestTreeShakingClassStaticProperty 2697 ---------- /out.js ---------- 2698 let keep1 = class { 2699 static x = x; 2700 }; 2701 let keep2 = class { 2702 static ["x"] = x; 2703 }; 2704 let keep3 = class { 2705 static [x] = "x"; 2706 }; 2707 let keep4 = class { 2708 static [x]() { 2709 } 2710 }; 2711 let keep5 = class { 2712 static get [x]() { 2713 } 2714 }; 2715 let keep6 = class { 2716 static set [x](_) { 2717 } 2718 }; 2719 let keep7 = class { 2720 static async [x]() { 2721 } 2722 }; 2723 let keep8 = class { 2724 static [{ toString() { 2725 } }] = "x"; 2726 }; 2727 2728 ================================================================================ 2729 TestTreeShakingImportIdentifier 2730 ---------- /out.js ---------- 2731 // b.js 2732 var Base = class { 2733 }; 2734 2735 // a.js 2736 var Keep = class extends Base { 2737 }; 2738 2739 // entry.js 2740 new Keep(); 2741 2742 ================================================================================ 2743 TestTreeShakingInESMWrapper 2744 ---------- /out.js ---------- 2745 // lib.js 2746 var keep1, keep2; 2747 var init_lib = __esm({ 2748 "lib.js"() { 2749 keep1 = () => "keep1"; 2750 keep2 = () => "keep2"; 2751 } 2752 }); 2753 2754 // cjs.js 2755 var cjs_exports = {}; 2756 __export(cjs_exports, { 2757 default: () => cjs_default 2758 }); 2759 var cjs_default; 2760 var init_cjs = __esm({ 2761 "cjs.js"() { 2762 init_lib(); 2763 cjs_default = keep2(); 2764 } 2765 }); 2766 2767 // entry.js 2768 init_lib(); 2769 console.log(keep1(), (init_cjs(), __toCommonJS(cjs_exports))); 2770 2771 ================================================================================ 2772 TestTreeShakingJSWithAssociatedCSS 2773 ---------- /out/test.js ---------- 2774 // project/node_modules/pkg/button.js 2775 var Button; 2776 2777 // project/test.jsx 2778 render(/* @__PURE__ */ React.createElement(Button, null)); 2779 2780 ---------- /out/test.css ---------- 2781 /* project/node_modules/pkg/button.css */ 2782 button { 2783 color: red; 2784 } 2785 2786 /* project/node_modules/pkg/menu.css */ 2787 menu { 2788 color: red; 2789 } 2790 2791 ================================================================================ 2792 TestTreeShakingJSWithAssociatedCSSExportStarSideEffectsFalse 2793 ---------- /out/test.js ---------- 2794 // project/node_modules/pkg/button.css 2795 var require_button = __commonJS({ 2796 "project/node_modules/pkg/button.css"(exports, module) { 2797 module.exports = {}; 2798 } 2799 }); 2800 2801 // project/node_modules/pkg/components.jsx 2802 require_button(); 2803 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2804 2805 // project/test.jsx 2806 render(/* @__PURE__ */ React.createElement(Button, null)); 2807 2808 ---------- /out/test.css ---------- 2809 /* project/node_modules/pkg/button.css */ 2810 button { 2811 color: red; 2812 } 2813 2814 ================================================================================ 2815 TestTreeShakingJSWithAssociatedCSSExportStarSideEffectsFalseOnlyJS 2816 ---------- /out/test.js ---------- 2817 // project/node_modules/pkg/button.css 2818 var require_button = __commonJS({ 2819 "project/node_modules/pkg/button.css"(exports, module) { 2820 module.exports = {}; 2821 } 2822 }); 2823 2824 // project/node_modules/pkg/components.jsx 2825 require_button(); 2826 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2827 2828 // project/test.jsx 2829 render(/* @__PURE__ */ React.createElement(Button, null)); 2830 2831 ---------- /out/test.css ---------- 2832 /* project/node_modules/pkg/button.css */ 2833 button { 2834 color: red; 2835 } 2836 2837 ================================================================================ 2838 TestTreeShakingJSWithAssociatedCSSReExportSideEffectsFalse 2839 ---------- /out/test.js ---------- 2840 // project/node_modules/pkg/button.css 2841 var require_button = __commonJS({ 2842 "project/node_modules/pkg/button.css"(exports, module) { 2843 module.exports = {}; 2844 } 2845 }); 2846 2847 // project/node_modules/pkg/components.jsx 2848 require_button(); 2849 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2850 2851 // project/test.jsx 2852 render(/* @__PURE__ */ React.createElement(Button, null)); 2853 2854 ---------- /out/test.css ---------- 2855 /* project/node_modules/pkg/button.css */ 2856 button { 2857 color: red; 2858 } 2859 2860 ================================================================================ 2861 TestTreeShakingJSWithAssociatedCSSReExportSideEffectsFalseOnlyJS 2862 ---------- /out/test.js ---------- 2863 // project/node_modules/pkg/button.css 2864 var require_button = __commonJS({ 2865 "project/node_modules/pkg/button.css"(exports, module) { 2866 module.exports = {}; 2867 } 2868 }); 2869 2870 // project/node_modules/pkg/components.jsx 2871 require_button(); 2872 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2873 2874 // project/test.jsx 2875 render(/* @__PURE__ */ React.createElement(Button, null)); 2876 2877 ---------- /out/test.css ---------- 2878 /* project/node_modules/pkg/button.css */ 2879 button { 2880 color: red; 2881 } 2882 2883 ================================================================================ 2884 TestTreeShakingJSWithAssociatedCSSUnusedNestedImportSideEffectsFalse 2885 ---------- /out/test.js ---------- 2886 // project/node_modules/pkg/button.jsx 2887 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2888 2889 // project/test.jsx 2890 render(/* @__PURE__ */ React.createElement(Button, null)); 2891 2892 ---------- /out/test.css ---------- 2893 /* project/node_modules/pkg/styles.css */ 2894 button { 2895 color: red; 2896 } 2897 2898 ================================================================================ 2899 TestTreeShakingJSWithAssociatedCSSUnusedNestedImportSideEffectsFalseOnlyJS 2900 ---------- /out/test.js ---------- 2901 // project/node_modules/pkg/button.jsx 2902 var Button = () => /* @__PURE__ */ React.createElement("button", null); 2903 2904 // project/test.jsx 2905 render(/* @__PURE__ */ React.createElement(Button, null)); 2906 2907 ---------- /out/test.css ---------- 2908 /* project/node_modules/pkg/styles.css */ 2909 button { 2910 color: red; 2911 } 2912 2913 ================================================================================ 2914 TestTreeShakingLoweredClassStaticField 2915 ---------- /out/entry.js ---------- 2916 // entry.js 2917 var KeepMe1 = class { 2918 }; 2919 __publicField(KeepMe1, "x", "x"); 2920 __publicField(KeepMe1, "y", sideEffects()); 2921 __publicField(KeepMe1, "z", "z"); 2922 var KeepMe2 = class { 2923 }; 2924 __publicField(KeepMe2, "x", "x"); 2925 __publicField(KeepMe2, "y", "y"); 2926 __publicField(KeepMe2, "z", "z"); 2927 new KeepMe2(); 2928 2929 ================================================================================ 2930 TestTreeShakingLoweredClassStaticFieldAssignment 2931 ---------- /out/entry.js ---------- 2932 // entry.ts 2933 var KeepMe1 = class { 2934 }; 2935 KeepMe1.x = "x"; 2936 KeepMe1.y = "y"; 2937 KeepMe1.z = "z"; 2938 var KeepMe2 = class { 2939 }; 2940 KeepMe2.x = "x"; 2941 KeepMe2.y = sideEffects(); 2942 KeepMe2.z = "z"; 2943 var KeepMe3 = class { 2944 }; 2945 KeepMe3.x = "x"; 2946 KeepMe3.y = "y"; 2947 KeepMe3.z = "z"; 2948 new KeepMe3(); 2949 2950 ================================================================================ 2951 TestTreeShakingLoweredClassStaticFieldMinified 2952 ---------- /out/entry.js ---------- 2953 // entry.js 2954 var KeepMe1 = class { 2955 }; 2956 __publicField(KeepMe1, "x", "x"), __publicField(KeepMe1, "y", sideEffects()), __publicField(KeepMe1, "z", "z"); 2957 var KeepMe2 = class { 2958 }; 2959 __publicField(KeepMe2, "x", "x"), __publicField(KeepMe2, "y", "y"), __publicField(KeepMe2, "z", "z"); 2960 new KeepMe2(); 2961 2962 ================================================================================ 2963 TestTreeShakingNoBundleCJS 2964 ---------- /out.js ---------- 2965 function keep() { 2966 } 2967 function unused() { 2968 } 2969 keep(); 2970 2971 ================================================================================ 2972 TestTreeShakingNoBundleESM 2973 ---------- /out.js ---------- 2974 function keep() { 2975 } 2976 function unused() { 2977 } 2978 keep(); 2979 2980 ================================================================================ 2981 TestTreeShakingNoBundleIIFE 2982 ---------- /out.js ---------- 2983 (() => { 2984 function keep() { 2985 } 2986 keep(); 2987 })(); 2988 2989 ================================================================================ 2990 TestTreeShakingObjectProperty 2991 ---------- /out.js ---------- 2992 let keep1 = { x }; 2993 let keep2 = { x }; 2994 let keep3 = { ...x }; 2995 let keep4 = { [x]: "x" }; 2996 let keep5 = { [x]() { 2997 } }; 2998 let keep6 = { get [x]() { 2999 } }; 3000 let keep7 = { set [x](_) { 3001 } }; 3002 let keep8 = { async [x]() { 3003 } }; 3004 let keep9 = { [{ toString() { 3005 } }]: "x" }; 3006 3007 ================================================================================ 3008 TestTreeShakingReactElements 3009 ---------- /out.js ---------- 3010 // entry.jsx 3011 function Foo() { 3012 } 3013 var d = /* @__PURE__ */ React.createElement("div", null); 3014 var e = /* @__PURE__ */ React.createElement(Foo, null, d); 3015 var f = /* @__PURE__ */ React.createElement(React.Fragment, null, e); 3016 console.log(f); 3017 3018 ================================================================================ 3019 TestTreeShakingUnaryOperators 3020 ---------- /out.js ---------- 3021 (() => { 3022 // entry.js 3023 var keep; 3024 +keep; 3025 -keep; 3026 ~keep; 3027 delete keep; 3028 ++keep; 3029 --keep; 3030 keep++; 3031 keep--; 3032 })();