From: Alex Lam S.L Date: Tue, 22 Oct 2019 12:36:05 +0000 (+0800) Subject: fix corner case in `reduce_vars` (#3510) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=02308a7b5651ce04703fafc43887636642c5e888;p=UglifyJS.git fix corner case in `reduce_vars` (#3510) fixes #3509 --- diff --git a/lib/scope.js b/lib/scope.js index 131235f6..6e33365c 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -292,9 +292,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) { var def = this.variables.get(symbol.name); if (def) { def.orig.push(symbol); - if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) { - def.init = init; - } + if (def.init instanceof AST_Function) def.init = init; } else { def = new SymbolDef(this, symbol, init); this.variables.set(symbol.name, def); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 744cdf1b..ce7c16da 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -6752,3 +6752,31 @@ issue_3377: { } expect_stdout: "42" } + +issue_3509: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function a() { + console.log("PASS"); + } + try { + } catch (a) { + var a; + } + a(); + } + expect: { + try { + } catch (a) { + var a; + } + (function() { + console.log("PASS"); + })(); + } + expect_stdout: "PASS" +}