diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-30 03:06:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-30 11:06:31 +0800 |
commit | 2e0ad40fe6635f7754a3e4dcdfb3b5bff75f4ae5 (patch) | |
tree | fa938d02895cce7bab4b50d302e61ba195ba9574 | |
parent | 5d12abc41b9cb4890b937599fa588a53fdb2996b (diff) | |
download | tracifyjs-2e0ad40fe6635f7754a3e4dcdfb3b5bff75f4ae5.tar.gz tracifyjs-2e0ad40fe6635f7754a3e4dcdfb3b5bff75f4ae5.zip |
fix corner case in `ie8` (#4251)
fixes #4250
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/ie8.js | 27 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 0b6ad857..e8c88016 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5200,7 +5200,10 @@ merge(Compressor.prototype, { var def = sym.definition(); if (!def) return; if (def.id in in_use_ids) return; - if (def.scope !== self && self.find_variable(sym) === def) return; + if (def.scope !== self) { + var d = self.find_variable(sym); + if ((d && d.redefined() || d) === def) return; + } log(sym, "Dropping unused loop variable {name}"); if (for_ins[def.id] === node) delete for_ins[def.id]; var body = []; diff --git a/test/compress/ie8.js b/test/compress/ie8.js index 2a7dace3..c5b8b155 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -2877,3 +2877,30 @@ issue_4235: { } expect_stdout: "undefined" } + +issue_4250: { + options = { + ie8: true, + loops: true, + unused: true, + } + input: { + console.log(function f() { + (function() { + for (f in "f"); + })(); + return f; + var f; + }()); + } + expect: { + console.log(function f() { + (function() { + for (f in "f"); + })(); + return f; + var f; + }()); + } + expect_stdout: "0" +} |