diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-12 05:43:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 12:43:26 +0800 |
commit | 9b7a13c8c7f06598b3da8da29da4e8e5680cd24e (patch) | |
tree | c64f777b0b7e72763d69ea8a14bb7331115c3197 | |
parent | 74ff6ce261548289c96f7d907a3605640e20e9d1 (diff) | |
download | tracifyjs-9b7a13c8c7f06598b3da8da29da4e8e5680cd24e.tar.gz tracifyjs-9b7a13c8c7f06598b3da8da29da4e8e5680cd24e.zip |
fix corner case in `ie8` & `mangle` (#4196)
fixes #4195
-rw-r--r-- | lib/scope.js | 12 | ||||
-rw-r--r-- | test/compress/const.js | 29 |
2 files changed, 35 insertions, 6 deletions
diff --git a/lib/scope.js b/lib/scope.js index c3bb3fa7..abb50c4f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -68,8 +68,8 @@ SymbolDef.prototype = { if (this.global && cache && cache.has(this.name)) { this.mangled_name = cache.get(this.name); } else if (!this.mangled_name && !this.unmangleable(options)) { - var def; - if (def = this.redefined()) { + var def = this.redefined(); + if (def) { this.mangled_name = def.mangled_name || def.name; } else { this.mangled_name = next_mangled_name(this.scope, options, this); @@ -84,8 +84,8 @@ SymbolDef.prototype = { if (!scope) return; var def = scope.variables.get(this.name); if (!def && scope instanceof AST_Toplevel) def = scope.globals.get(this.name); - if (def === this) return; - return def; + if (!def || def === this) return; + return def.redefined() || def; }, unmangleable: function(options) { return this.global && !options.toplevel @@ -274,8 +274,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { var old_def = node.thedef; var new_def = scope.find_variable(name); if (new_def) { - var redef; - while (redef = new_def.redefined()) new_def = redef; + var redef = new_def.redefined(); + if (redef) new_def = redef; } else { new_def = self.globals.get(name); } diff --git a/test/compress/const.js b/test/compress/const.js index f09dc56f..6cd1124a 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -747,3 +747,32 @@ issue_4193: { } expect_stdout: true } + +issue_4195: { + mangle = { + ie8: true, + } + input: { + console.log(function f(a) { + (function a() { + { + const b = f, a = 0; + b; + } + })(); + a && f; + }()); + } + expect: { + console.log(function f(o) { + (function o() { + { + const n = f, o = 0; + n; + } + })(); + o && f; + }()); + } + expect_stdout: "undefined" +} |