From: Alex Lam S.L Date: Sun, 17 Jan 2021 22:36:59 +0000 (+0000) Subject: fix corner case in `loops` (#4565) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=e23a10f7f96cda932c605988d2d99bb5225d18a5;p=UglifyJS.git fix corner case in `loops` (#4565) fixes #4564 --- diff --git a/lib/compress.js b/lib/compress.js index d5334a95..81511535 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6169,7 +6169,7 @@ merge(Compressor.prototype, { var def = sym.definition(); if (def.scope !== self) { var d = find_variable(sym.name); - if ((d && d.redefined() || d) === def) return; + if (d === def || d && d.redefined() === def) return; } node.object.walk(tw); return true; diff --git a/test/compress/loops.js b/test/compress/loops.js index d76e7f74..a6d0277b 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -1280,3 +1280,33 @@ issue_4355: { } expect_stdout: "PASS" } + +issue_4564: { + options = { + loops: true, + unused: true, + } + input: { + try { + throw null; + } catch (a) { + var a; + (function() { + for (a in "foo"); + })(); + console.log(a); + } + } + expect: { + try { + throw null; + } catch (a) { + var a; + (function() { + for (a in "foo"); + })(); + console.log(a); + } + } + expect_stdout: "2" +} diff --git a/test/reduce.js b/test/reduce.js index c478da5f..91df8bce 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -666,7 +666,7 @@ function has_loopcontrol(body, loop, label) { } function is_error(result) { - return typeof result == "object" && typeof result.name == "string" && typeof result.message == "string"; + return result && typeof result.name == "string" && typeof result.message == "string"; } function is_timed_out(result) {