From 937a6728798cc139defa868c78ddf57d851913d7 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 28 Jul 2022 20:04:10 +0100 Subject: [PATCH] fix corner case in `mangle` (#5581) fixes #5580 --- lib/scope.js | 7 +++- test/compress/const.js | 85 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/lib/scope.js b/lib/scope.js index 3d19757193d..e3e4248d8e2 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -704,7 +704,12 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) { } redefined.push(def); def.references.forEach(reference); - if (sym instanceof AST_SymbolCatch || sym instanceof AST_SymbolConst) reference(sym); + if (sym instanceof AST_SymbolCatch || sym instanceof AST_SymbolConst) { + reference(sym); + def.redefined = function() { + return redef; + }; + } return true; function reference(sym) { diff --git a/test/compress/const.js b/test/compress/const.js index 6964b3daf7e..b39b94742f5 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -2011,3 +2011,88 @@ issue_5516: { } expect_stdout: "function" } + +issue_5580_1: { + mangle = {} + input: { + "use strict"; + console.log(function(a, b, c) { + try { + FAIL; + } catch (e) { + return function() { + var d = e, i, j; + { + const e = j; + } + return a; + }(); + } finally { + const e = 42; + } + }("PASS")); + } + expect: { + "use strict"; + console.log(function(r, n, t) { + try { + FAIL; + } catch (o) { + return function() { + var n = o, t, c; + { + const o = c; + } + return r; + }(); + } finally { + const c = 42; + } + }("PASS")); + } + expect_stdout: "PASS" + node_version: ">=4" +} + +issue_5580_2: { + options = { + inline: true, + reduce_vars: true, + varify: true, + } + input: { + "use strict"; + (function() { + try { + throw "PASS"; + } catch (e) { + return function() { + console.log(e); + { + const e = "FAIL 1"; + } + }(); + } finally { + const e = "FAIL 2"; + } + })(); + } + expect: { + "use strict"; + (function() { + try { + throw "PASS"; + } catch (e) { + console.log(e); + { + const e = "FAIL 1"; + } + return; + } finally { + var e = "FAIL 2"; + } + })(); + } + expect_stdout: "PASS" + node_version: ">=4" +}