Skip to content

Commit 937a672

Browse files
authored
fix corner case in mangle (#5581)
fixes #5580
1 parent 513995f commit 937a672

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

Diff for: lib/scope.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,12 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
704704
}
705705
redefined.push(def);
706706
def.references.forEach(reference);
707-
if (sym instanceof AST_SymbolCatch || sym instanceof AST_SymbolConst) reference(sym);
707+
if (sym instanceof AST_SymbolCatch || sym instanceof AST_SymbolConst) {
708+
reference(sym);
709+
def.redefined = function() {
710+
return redef;
711+
};
712+
}
708713
return true;
709714

710715
function reference(sym) {

Diff for: test/compress/const.js

+85
Original file line numberDiff line numberDiff line change
@@ -2011,3 +2011,88 @@ issue_5516: {
20112011
}
20122012
expect_stdout: "function"
20132013
}
2014+
2015+
issue_5580_1: {
2016+
mangle = {}
2017+
input: {
2018+
"use strict";
2019+
console.log(function(a, b, c) {
2020+
try {
2021+
FAIL;
2022+
} catch (e) {
2023+
return function() {
2024+
var d = e, i, j;
2025+
{
2026+
const e = j;
2027+
}
2028+
return a;
2029+
}();
2030+
} finally {
2031+
const e = 42;
2032+
}
2033+
}("PASS"));
2034+
}
2035+
expect: {
2036+
"use strict";
2037+
console.log(function(r, n, t) {
2038+
try {
2039+
FAIL;
2040+
} catch (o) {
2041+
return function() {
2042+
var n = o, t, c;
2043+
{
2044+
const o = c;
2045+
}
2046+
return r;
2047+
}();
2048+
} finally {
2049+
const c = 42;
2050+
}
2051+
}("PASS"));
2052+
}
2053+
expect_stdout: "PASS"
2054+
node_version: ">=4"
2055+
}
2056+
2057+
issue_5580_2: {
2058+
options = {
2059+
inline: true,
2060+
reduce_vars: true,
2061+
varify: true,
2062+
}
2063+
input: {
2064+
"use strict";
2065+
(function() {
2066+
try {
2067+
throw "PASS";
2068+
} catch (e) {
2069+
return function() {
2070+
console.log(e);
2071+
{
2072+
const e = "FAIL 1";
2073+
}
2074+
}();
2075+
} finally {
2076+
const e = "FAIL 2";
2077+
}
2078+
})();
2079+
}
2080+
expect: {
2081+
"use strict";
2082+
(function() {
2083+
try {
2084+
throw "PASS";
2085+
} catch (e) {
2086+
console.log(e);
2087+
{
2088+
const e = "FAIL 1";
2089+
}
2090+
return;
2091+
} finally {
2092+
var e = "FAIL 2";
2093+
}
2094+
})();
2095+
}
2096+
expect_stdout: "PASS"
2097+
node_version: ">=4"
2098+
}

0 commit comments

Comments
 (0)