correctly count declarations after `hoist_vars` (#2297)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 3 Sep 2017 09:23:31 +0000 (17:23 +0800)
committerGitHub <noreply@github.com>
Sun, 3 Sep 2017 09:23:31 +0000 (17:23 +0800)
fixes #2295

lib/compress.js
test/compress/hoist_vars.js

index 9121d0c..b6a984c 100644 (file)
@@ -3113,6 +3113,7 @@ merge(Compressor.prototype, {
                 }));
                 if (reduce_vars) name.definition().fixed = false;
             }
+            remove(def.name.definition().orig, def.name);
             return a;
         }, []);
         if (assignments.length == 0) return null;
index 6fe1c77..6aa1f7b 100644 (file)
@@ -88,3 +88,24 @@ sequences_funs: {
         }
     }
 }
+
+issue_2295: {
+    options = {
+        collapse_vars: true,
+        hoist_vars: true,
+    }
+    input: {
+        function foo(o) {
+            var a = o.a;
+            if (a) return a;
+            var a = 1;
+        }
+    }
+    expect: {
+        function foo(o) {
+            var a = o.a;
+            if (a) return a;
+            a = 1;
+        }
+    }
+}