fix corner case in `reduce_vars` (#4802)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 18 Mar 2021 15:58:35 +0000 (15:58 +0000)
committerGitHub <noreply@github.com>
Thu, 18 Mar 2021 15:58:35 +0000 (23:58 +0800)
fixes #4801

lib/compress.js
test/compress/bigint.js
test/compress/let.js

index 81298cb..d920bc1 100644 (file)
@@ -10436,7 +10436,7 @@ merge(Compressor.prototype, {
                     } else {
                         value = fixed.optimize(compressor);
                     }
-                    if (value === fixed) value = value.transform(new TreeTransformer(function(node, descend) {
+                    value = value.transform(new TreeTransformer(function(node, descend) {
                         if (node instanceof AST_Scope) return node;
                         node = node.clone();
                         descend(node, this);
index 9c21d08..b417268 100644 (file)
@@ -60,3 +60,33 @@ issue_4590: {
     expect_stdout: "PASS"
     node_version: ">=10"
 }
+
+issue_4801: {
+    options = {
+        booleans: true,
+        collapse_vars: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        try {
+            (function(a) {
+                A = 42;
+                a || A;
+            })(!(0 == 42 >> 0o644n));
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect: {
+        try {
+            (function(a) {
+                0 != (A = 42) >> 0o644n || A;
+            })();
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect_stdout: "PASS"
+    node_version: ">=10"
+}
index 3f42dd1..90d9952 100644 (file)
@@ -419,36 +419,36 @@ reduce_vars_3: {
     }
     input: {
         "use strict";
-        (function(scope) {
+        (function(a) {
             let i = 1;
             function f() {
                 i = 0;
             }
-            for (let i = 0, x = 0; i < scope.length; i++, x++) {
+            for (let i = 0, x = 0; i < a.length; i++, x++) {
                 if (x != i) {
                     console.log("FAIL");
                     break;
                 }
                 f();
-                console.log(scope[i]);
+                console.log(a[i]);
             }
             console.log(i);
         })([ 4, 2 ]);
     }
     expect: {
         "use strict";
-        (function(scope) {
+        (function(a) {
             let i = 1;
             function f() {
                 i = 0;
             }
-            for (let i = 0, x = 0; i < scope.length; i++, x++) {
+            for (let i = 0, x = 0; i < a.length; i++, x++) {
                 if (x != i) {
                     console.log("FAIL");
                     break;
                 }
                 f();
-                console.log(scope[i]);
+                console.log(a[i]);
             }
             console.log(i);
         })([ 4, 2 ]);