Skip to content

Commit

Permalink
fix corner case in reduce_vars (#5778)
Browse files Browse the repository at this point in the history
fixes #5777
  • Loading branch information
alexlamsl authored Jan 16, 2023
1 parent 57dd3f6 commit a437a61
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,9 @@ Compressor.prototype.compress = function(node) {
}

function pop_scope(tw, scope) {
var fn_defs = scope.fn_defs;
var tangled = scope.may_call_this === return_true ? fn_defs : fn_defs.filter(function(fn) {
if (fn.safe_ids === false) return true;
fn.safe_ids = tw.safe_ids;
walk_fn_def(tw, fn);
return false;
});
pop(tw);
tangled.forEach(function(fn) {
var fn_defs = scope.fn_defs;
fn_defs.forEach(function(fn) {
fn.safe_ids = tw.safe_ids;
walk_fn_def(tw, fn);
});
Expand Down
74 changes: 74 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8148,3 +8148,77 @@ issue_5730_3: {
}
expect_stdout: "PASS"
}

issue_5777_1: {
options = {
reduce_vars: true,
unused: true,
}
input: {
function f() {
(function(a) {
function g() {
h();
}
g();
a = function() {};
function h() {
console.log(a);
}
})("PASS");
}
f();
}
expect: {
function f() {
(function(a) {
(function() {
h();
})();
a = function() {};
function h() {
console.log(a);
}
})("PASS");
}
f();
}
expect_stdout: "PASS"
}

issue_5777_2: {
options = {
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function f(a) {
(function() {
function g() {
h();
}
g();
a = function() {};
function h() {
console.log(a);
}
})();
}
f("PASS");
}
expect: {
(function(a) {
(function() {
(function() {
h();
})();
a = function() {};
function h() {
console.log(a);
}
})();
})("PASS");
}
expect_stdout: "PASS"
}

0 comments on commit a437a61

Please sign in to comment.