diff --git a/lib/compress.js b/lib/compress.js index 3309d7fa61..342748a087 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10462,9 +10462,11 @@ Compressor.prototype.compress = function(node) { def.orig[def.orig.indexOf(node)] = name; for (var s = scope; s !== def.scope && (s = s.parent_scope);) { remove(s.enclosed, def); + s._var_names = undefined; } - def.scope = scope; + def.scope.variables.del(def.name); scope.variables.set(def.name, def); + def.scope = scope; }), value: defn.value, }); diff --git a/test/compress/let.js b/test/compress/let.js index 7205090cec..ec5c130e5f 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -2566,3 +2566,35 @@ issue_5787: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5950: { + options = { + conditionals: true, + join_vars: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + "use strict"; + { + let a; + if (console.log("PASS")) { + var b = function() { + a; + }, c = b; + } + } + } + expect: { + "use strict"; + { + let a; + console.log("PASS") && function() { + a; + }; + } + } + expect_stdout: "PASS" + node_version: ">=4" +}