From: Alex Lam S.L Date: Wed, 11 Apr 2018 07:44:43 +0000 (+0800) Subject: fix `inline` of `catch`-scoped variables (#3077) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6a916523d458952a7ecde360e5294a5ae807d249;p=UglifyJS.git fix `inline` of `catch`-scoped variables (#3077) fixes #3076 --- diff --git a/lib/compress.js b/lib/compress.js index 454ce945..999e03c4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4841,6 +4841,11 @@ merge(Compressor.prototype, { for (var j = 0, defs = stat.definitions.length; j < defs; j++) { var var_def = stat.definitions[j]; var name = var_def.name; + var redef = name.definition().redefined(); + if (redef) { + name = name.clone(); + name.thedef = redef; + } append_var(decls, expressions, name, var_def.value); if (in_loop && all(fn.argnames, function(argname) { return argname.name != name.name; diff --git a/test/compress/functions.js b/test/compress/functions.js index 471ebf7f..650254f4 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -2267,3 +2267,39 @@ issue_3054: { } expect_stdout: "true true" } + +issue_3076: { + options = { + dead_code: true, + inline: true, + sequences: true, + unused: true, + } + input: { + var c = "PASS"; + (function(b) { + var n = 2; + while (--b + function() { + e && (c = "FAIL"); + e = 5; + return 1; + try { + var a = 5; + } catch (e) { + var e; + } + }().toString() && --n > 0); + })(2); + console.log(c); + } + expect: { + var c = "PASS"; + (function(b) { + var n = 2; + while (--b + (e = void 0, e && (c = "FAIL"), e = 5, 1).toString() && --n > 0); + var e; + })(2), + console.log(c); + } + expect_stdout: "PASS" +}