fix corner case in `collapse_vars` (#3574)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 7 Nov 2019 12:38:03 +0000 (20:38 +0800)
committerGitHub <noreply@github.com>
Thu, 7 Nov 2019 12:38:03 +0000 (20:38 +0800)
fixes #3573

lib/compress.js
test/compress/collapse_vars.js

index ba78981..0d19640 100644 (file)
@@ -1283,6 +1283,7 @@ merge(Compressor.prototype, {
                             }
                             branch.expression = branch.expression.transform(scanner);
                             if (!replace_all) break;
+                            scan_rhs = false;
                         }
                     }
                     abort = true;
index cf4e45a..86e8d63 100644 (file)
@@ -6435,3 +6435,36 @@ call_assign_order: {
     }
     expect_stdout: "PASS PASS"
 }
+
+issue_3573: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var c = 0;
+        (function(b) {
+            while (--b) {
+                b = NaN;
+                switch (0 / this < 0) {
+                  case c++, false:
+                  case c++, NaN:
+                }
+            }
+        })(3);
+        console.log(c);
+    }
+    expect: {
+        var c = 0;
+        (function(b) {
+            while (--b) {
+                b = NaN;
+                switch (0 / this < 0) {
+                  case c++, false:
+                  case c++, NaN:
+                }
+            }
+        })(3);
+        console.log(c);
+    }
+    expect_stdout: "1"
+}