aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-09-03 17:23:31 +0800
committerGitHub <noreply@github.com>2017-09-03 17:23:31 +0800
commit3f355866cf903c40c2bab2cd841ab2b56a2bacf1 (patch)
tree40d81e3dabad934313eaa5e88ebcd355ef628c89
parent71d52f147dedfb49bf45bccb46613cd1f46ec286 (diff)
downloadtracifyjs-3f355866cf903c40c2bab2cd841ab2b56a2bacf1.tar.gz
tracifyjs-3f355866cf903c40c2bab2cd841ab2b56a2bacf1.zip
correctly count declarations after `hoist_vars` (#2297)
fixes #2295
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/hoist_vars.js21
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9121d0ce..b6a984cc 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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;
diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js
index 6fe1c773..6aa1f7b4 100644
--- a/test/compress/hoist_vars.js
+++ b/test/compress/hoist_vars.js
@@ -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;
+ }
+ }
+}