From 3f355866cf903c40c2bab2cd841ab2b56a2bacf1 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 3 Sep 2017 17:23:31 +0800 Subject: [PATCH] correctly count declarations after `hoist_vars` (#2297) fixes #2295 --- lib/compress.js | 1 + test/compress/hoist_vars.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) 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; + } + } +} -- 2.34.1