From: Alex Lam S.L Date: Sun, 3 Sep 2017 09:23:31 +0000 (+0800) Subject: correctly count declarations after `hoist_vars` (#2297) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3f355866cf903c40c2bab2cd841ab2b56a2bacf1;p=UglifyJS.git correctly count declarations after `hoist_vars` (#2297) fixes #2295 --- 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; + } + } +}