diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-24 04:46:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 11:46:58 +0800 |
commit | 1e787c556b916644e8ba2fc36fce024001f00ff8 (patch) | |
tree | 31ac8c02d19f77720d10c1b1bc9dbd3957aa6514 | |
parent | df47632eccdc505810073d7bfced21bbf8c2dd98 (diff) | |
download | tracifyjs-1e787c556b916644e8ba2fc36fce024001f00ff8.tar.gz tracifyjs-1e787c556b916644e8ba2fc36fce024001f00ff8.zip |
fix corner case in `mangle` (#4961)
fixes #4960
-rw-r--r-- | lib/scope.js | 5 | ||||
-rw-r--r-- | test/compress/const.js | 30 |
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/scope.js b/lib/scope.js index 466ab8d6..c74c494a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -70,9 +70,7 @@ SymbolDef.prototype = { } else if (!this.mangled_name && !this.unmangleable(options)) { var def = this.redefined(); if (def) { - var name = def.mangled_name || def.name; - this.mangled_name = name; - names_in_use(this.scope, options)[name] = true; + this.mangled_name = def.mangled_name || def.name; } else { this.mangled_name = next_mangled_name(this, options); } @@ -683,6 +681,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) { redef = scope.def_variable(sym); scope.to_mangle.push(redef); } else if (redef.mangled_name) { + names_in_use(def.scope, options)[redef.mangled_name] = true; return false; } redefined.push(def); diff --git a/test/compress/const.js b/test/compress/const.js index d7731005..58c1a304 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1588,3 +1588,33 @@ issue_4954_2: { expect_stdout: "PASS" node_version: ">=4" } + +issue_4960: { + mangle = {} + input: { + "use strict"; + var a; + (function() { + { + const a = console.log("PASS"); + } + try {} catch (e) { + const a = console.log("FAIL"); + } + })(); + } + expect: { + "use strict"; + var a; + (function() { + { + const o = console.log("PASS"); + } + try {} catch (c) { + const o = console.log("FAIL"); + } + })(); + } + expect_stdout: "PASS" + node_version: ">=4" +} |