fix corner case in `unused` (#4134)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 20 Sep 2020 15:21:59 +0000 (16:21 +0100)
committerGitHub <noreply@github.com>
Sun, 20 Sep 2020 15:21:59 +0000 (23:21 +0800)
fixes #4133

lib/compress.js
test/compress/drop-unused.js

index 1f86c5b..2df76f5 100644 (file)
@@ -2906,9 +2906,12 @@ merge(Compressor.prototype, {
             var fixed = this.fixed_value();
             if (!fixed) return true;
             this._dot_throw = return_true;
-            var result = fixed._dot_throw(compressor);
-            delete this._dot_throw;
-            return result;
+            if (fixed._dot_throw(compressor)) {
+                delete this._dot_throw;
+                return true;
+            }
+            this._dot_throw = return_false;
+            return false;
         });
         def(AST_UnaryPrefix, function() {
             return this.operator == "void";
index 46f273e..eadf279 100644 (file)
@@ -2924,3 +2924,24 @@ forin_var_2: {
     }
     expect_stdout: "undefined"
 }
+
+issue_4133: {
+    options = {
+        evaluate: true,
+        merge_vars: true,
+        pure_getters: "strict",
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 1;
+        var b = [ a-- ], c = b && b[c];
+        console.log(a);
+    }
+    expect: {
+        var b = 1;
+        console.log(0);
+    }
+    expect_stdout: "0"
+}