diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-12 12:02:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 19:02:44 +0800 |
commit | 1cdf810f0bc7dfbbdadedd1274e990c46e6e59b8 (patch) | |
tree | 8b9c22499b80bf03d103f24698386068d7f7ba30 | |
parent | b512726cf39066919483d2add87905f677db1832 (diff) | |
download | tracifyjs-1cdf810f0bc7dfbbdadedd1274e990c46e6e59b8.tar.gz tracifyjs-1cdf810f0bc7dfbbdadedd1274e990c46e6e59b8.zip |
fix corner case in `reduce_vars` (#4203)
fixes #4198
-rw-r--r-- | lib/compress.js | 8 | ||||
-rw-r--r-- | test/compress/const.js | 35 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index fc65e426..f930dd82 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6640,7 +6640,13 @@ merge(Compressor.prototype, { if (def.scope === scope) return true; return !scope.variables.has(node.name) && !scope.globals.has(node.name); } - return def.scope === scope || !scope.find_variable(node); + if (def.scope === scope) return true; + var s = def.scope; + do { + s = s.parent_scope; + if (s.variables.has(node.name)) return false; + } while (s !== scope); + return true; }) ? make_node(AST_Var, self, { definitions: self.definitions.map(function(defn) { var name = make_node(AST_SymbolVar, defn.name, defn.name); diff --git a/test/compress/const.js b/test/compress/const.js index f2b92247..72033f4a 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -805,3 +805,38 @@ issue_4197: { } expect_stdout: "1" } + +issue_4198: { + options = { + reduce_vars: true, + } + input: { + console.log(function() { + try { + throw "PASS"; + } catch (e) { + { + const e = "FAIL"; + } + return function() { + return e; + }(); + } + }()); + } + expect: { + console.log(function() { + try { + throw "PASS"; + } catch (e) { + { + const e = "FAIL"; + } + return function() { + return e; + }(); + } + }()); + } + expect_stdout: "PASS" +} |