Skip to content

Commit

Permalink
fix corner case in reduce_funcs (#5049)
Browse files Browse the repository at this point in the history
fixes #5048
  • Loading branch information
alexlamsl committed Jul 4, 2021
1 parent f4ae267 commit f5dbb67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10913,9 +10913,10 @@ merge(Compressor.prototype, {
return self;
});

function recursive_ref(compressor, def) {
function recursive_ref(compressor, def, fn) {
var level = 0, node = compressor.self();
do {
if (node === fn) return node;
if (is_lambda(node) && node.name && node.name.definition() === def) return node;
} while (node = compressor.parent(level++));
}
Expand Down Expand Up @@ -10951,7 +10952,7 @@ merge(Compressor.prototype, {
if ((def.scope !== self.scope.resolve() || def.in_loop)
&& (!compressor.option("reduce_funcs") || def.escaped.depth == 1 || fixed.inlined)) {
single_use = false;
} else if (recursive_ref(compressor, def)) {
} else if (recursive_ref(compressor, def, fixed)) {
single_use = false;
} else if (fixed.name && fixed.name.definition() !== def) {
single_use = false;
Expand Down
19 changes: 19 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7677,3 +7677,22 @@ issue_4949: {
}
expect_stdout: "0 1"
}

issue_5048: {
options = {
reduce_funcs: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function() {
var a = function() {
return a + 42;
};
}());
}
expect: {
console.log(function() {}());
}
expect_stdout: "undefined"
}

0 comments on commit f5dbb67

Please sign in to comment.