From e23a10f7f96cda932c605988d2d99bb5225d18a5 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 17 Jan 2021 22:36:59 +0000 Subject: [PATCH] fix corner case in `loops` (#4565) fixes #4564 --- lib/compress.js | 2 +- test/compress/loops.js | 30 ++++++++++++++++++++++++++++++ test/reduce.js | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) 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) { -- 2.34.1