From 9b7a13c8c7f06598b3da8da29da4e8e5680cd24e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 12 Oct 2020 05:43:26 +0100 Subject: [PATCH] fix corner case in `ie8` & `mangle` (#4196) fixes #4195 --- lib/scope.js | 12 ++++++------ 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" +} -- 2.34.1