diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-17 22:36:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 06:36:59 +0800 |
commit | e23a10f7f96cda932c605988d2d99bb5225d18a5 (patch) | |
tree | 55bc342a6c9bd3404bf5f5094055e9eaea3fb3d4 | |
parent | 884ec4e8a5dc83aa8897bfa7bf49034907311e47 (diff) | |
download | tracifyjs-e23a10f7f96cda932c605988d2d99bb5225d18a5.tar.gz tracifyjs-e23a10f7f96cda932c605988d2d99bb5225d18a5.zip |
fix corner case in `loops` (#4565)
fixes #4564
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/loops.js | 30 | ||||
-rw-r--r-- | 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) { |