improve fix for #4325 (#4649)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 13 Feb 2021 18:24:57 +0000 (18:24 +0000)
committerGitHub <noreply@github.com>
Sat, 13 Feb 2021 18:24:57 +0000 (02:24 +0800)
lib/compress.js
test/compress/functions.js
test/compress/keep_fargs.js
test/compress/loops.js
test/compress/rests.js
test/compress/side_effects.js
test/mocha/reduce.js

index 38d25b1..7e113ec 100644 (file)
@@ -7003,6 +7003,8 @@ merge(Compressor.prototype, {
                 // always shallow clone to ensure stripping of negated IIFEs
                 self = self.clone();
                 self.expression = exp.clone();
+                // avoid extraneous traversal
+                if (exp._squeezed) self.expression._squeezed = true;
             }
             if (self instanceof AST_New) {
                 var fn = exp;
index 5de05f6..77dd256 100644 (file)
@@ -3322,7 +3322,9 @@ issue_3506_1: {
     }
     expect: {
         var a = "FAIL";
-        a && (a = "PASS");
+        !function(b) {
+            b && (a = "PASS");
+        }(a);
         console.log(a);
     }
     expect_stdout: "PASS"
index d5d7ef9..4c1c1b7 100644 (file)
@@ -438,7 +438,7 @@ issue_2506: {
         function f0(bar) {
             (function() {
                 (function() {
-                    if (false <= NaN & this >> 1 >= 0)
+                    if (false <= 0/0 & this >> 1 >= 0)
                         c++;
                 })(c++);
             })();
index 3217afd..0afffae 100644 (file)
@@ -1067,7 +1067,6 @@ issue_4084: {
     options = {
         keep_fargs: false,
         loops: true,
-        passes: 2,
         reduce_vars: true,
         unused: true,
     }
@@ -1276,6 +1275,7 @@ issue_4355: {
         dead_code: true,
         evaluate: true,
         loops: true,
+        passes: 2,
         side_effects: true,
         unused: true,
     }
index 59e2945..676b5e7 100644 (file)
@@ -673,27 +673,21 @@ issue_4575: {
         unused: true,
     }
     input: {
-        A = "PASS";
-        (function() {
-            var a = 0, b = a;
-            var c = function a(...b) {
-                A;
-                var d = A;
-                console.log(d, b.length);
+        (function(a) {
+            var b = a;
+            var c = function a(...d) {
+                console.log(d.length);
             }();
         })();
     }
     expect: {
-        A = "PASS";
-        (function() {
-            (function(b) {
-                A;
-                var d = A;
-                console.log(d, b.length);
-            })([]);
+        (function(a) {
+            (function a(...d) {
+                console.log(d.length);
+            })();
         })();
     }
-    expect_stdout: "PASS 0"
+    expect_stdout: "0"
     node_version: ">=6"
 }
 
index 2a65bc2..177cf50 100644 (file)
@@ -458,14 +458,14 @@ issue_4325: {
     }
     expect: {
         (function() {
-            (function() {
+            (function(c) {
                 try {
-                    (void 0).p = 0;
+                    c.p = 0;
                 } catch (e) {
                     console.log("PASS");
                     return;
                 }
-            })();
+            })(void 0);
         })();
     }
     expect_stdout: "PASS"
index 587aa7b..9e3fc8b 100644 (file)
@@ -294,8 +294,9 @@ describe("test/reduce.js", function() {
             "// }",
         ]).join("\n"));
     });
-    it("Should maintain block-scope for const & let", function() {
+    it("Should maintain block-scope for const/let", function() {
         if (semver.satisfies(process.version, "<4")) return;
+        this.timeout(120000);
         var code = [
             '"use strict";',
             "",