fix `reduce_vars` on `AST_Accessor` (#2776)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 12 Jan 2018 18:46:14 +0000 (02:46 +0800)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2018 18:46:14 +0000 (02:46 +0800)
fixes #2774

lib/compress.js
test/compress/reduce_vars.js

index 21d79b0..b35e453 100644 (file)
@@ -467,8 +467,9 @@ merge(Compressor.prototype, {
             if (node instanceof AST_SymbolRef) d.references.push(node);
             d.fixed = false;
         });
-        def(AST_Accessor, function(tw, descend) {
+        def(AST_Accessor, function(tw, descend, compressor) {
             push(tw);
+            reset_variables(tw, compressor, this);
             descend();
             pop(tw);
             return true;
index 3d993b9..ec0471a 100644 (file)
@@ -5276,3 +5276,29 @@ duplicate_lambda_defun_name_2: {
     }
     expect_stdout: "0"
 }
+
+issue_2774: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log({
+            get a() {
+                var b;
+                (b = true) && b.c;
+                b = void 0;
+            }
+        }.a);
+    }
+    expect: {
+        console.log({
+            get a() {
+                var b;
+                (b = true) && b.c;
+                b = void 0;
+            }
+        }.a);
+    }
+    expect_stdout: "undefined"
+}