You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9377120
Browse filesBrowse the repository at this point in the historyBrowse files
fix(javascript): scope a parameter list apart from its body in the minifier
A name a parameter default or catch pattern reads resolved to what the body or block declares, as terser scopes it, so the mangler renamed the read onto the inner binding and the compressor dropped the outer one as unused. Such a read now skips the body's bindings. Moves 42 test262 cases off the printer's list; minifying a 1 MB bundle is within noise.
Keep a name a parameter list or catch parameter reads from resolving to what the function body or catch block declares, which the minifier renamed or dropped as unused.
* @property {boolean=} ie8 whether catch parameters belong to their function
1667
1671
* @property {boolean=} safari10 whether a loop's scope reads its parent's names, and catch parameters belong to their function
1668
1672
* @property {EXPECTED_ANY=} keep_fnames which function names survive, collecting the declarators naming one
1673
+
* @property {boolean=} parameterScopes whether a name read in a parameter list or a catch parameter skips what the body declares, as the spec scopes it
Copy file name to clipboardExpand all lines: test/unitCases/syntax-printer.unittest.js
+90-3Lines changed: 90 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -629,7 +629,62 @@ const CORRECTED_CASES = [
629
629
input,
630
630
{compress: false,mangle: false}
631
631
])
632
-
)
632
+
),
633
+
[
634
+
"a parameter default's closure reading a name its body declares with `var`",
635
+
"var x = 'out'; var a, b; function f(_ = a = () => x) { var x = 'in'; b = () => x; } f(); console.log(a(), b());",
636
+
{compress: false,mangle: true}
637
+
],
638
+
[
639
+
"a parameter default reading a name its body redeclares",
640
+
"var x = 1; function f(a = x, b = a) { var x = 2, a; return x + a + b; } console.log(f());",
641
+
{compress: false,mangle: true}
642
+
],
643
+
[
644
+
"a parameter default's closure reading a name its body declares, compressed",
645
+
"function g() { var x = 'out'; var a, b; function f(_ = a = () => x) { var x = 'in'; b = () => x; } f(); console.log(a(), b()); } g();",
646
+
{compress: {},mangle: false}
647
+
],
648
+
[
649
+
"a parameter default's closure reading a name its body declares as a function",
650
+
"var h = 'out'; var a; function f(_ = a = () => h) { function h() {} } f(); console.log(a());",
651
+
{compress: false,mangle: true}
652
+
],
653
+
[
654
+
"a parameter default's closure reading a name its body declares with `let`",
655
+
"var x = 'out'; var a; function f(_ = a = () => x) { let x = 'in'; } f(); console.log(a());",
656
+
{compress: false,mangle: true}
657
+
],
658
+
[
659
+
"a destructured parameter default's closure reading a name its body declares",
660
+
"var x = 'out'; var a; function f({ y = a = () => x } = {}) { var x = 'in'; } f(); console.log(a());",
661
+
{compress: false,mangle: true}
662
+
],
663
+
[
664
+
"an arrow's parameter default reading a name its body declares",
665
+
"var x = 'out'; var a, b; var f = (_ = a = () => x) => { var x = 'in'; b = () => x; }; f(); console.log(a(), b());",
666
+
{compress: false,mangle: true}
667
+
],
668
+
[
669
+
"a method's parameter default reading a name its body declares",
670
+
"var x = 'out'; var a; class C { static m(_ = a = () => x) { var x = 'in'; } } C.m(); console.log(a());",
671
+
{compress: false,mangle: true}
672
+
],
673
+
[
674
+
"a nested function's parameter default reading a name its body declares",
675
+
"var x = 'out'; var a; function f(_ = function () { return function (__ = a = () => x) { var x = 'deep'; }; }) { var x = 'in'; _()(); } f(); console.log(a());",
676
+
{compress: false,mangle: true}
677
+
],
678
+
[
679
+
"a catch parameter default's closure reading a name its block declares",
680
+
"var a, b; let x = 'out'; try { throw []; } catch ([_ = a = () => x]) { b = () => x; let x = 'in'; } console.log(a(), b());",
681
+
{compress: false,mangle: true}
682
+
],
683
+
[
684
+
"a catch parameter default's closure reading a name its block declares, compressed",
685
+
"function g() { var a, b; let x = 'out'; try { throw []; } catch ([_ = a = () => x]) { b = () => x; let x = 'in'; } console.log(a(), b()); } g();",
686
+
{compress: {},mangle: false}
687
+
]
633
688
];
634
689
635
690
// terser's parser refuses `let` as a name, so with corrections off the print
0 commit comments