Skip to content

Commit

Permalink
fix corner case in mangle (#5581)
Browse files Browse the repository at this point in the history
fixes #5580
  • Loading branch information
alexlamsl authored Jul 28, 2022
1 parent 513995f commit 937a672
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
85 changes: 85 additions & 0 deletions test/compress/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 937a672

Please sign in to comment.