drop anonymous function name when overshadowed by other declarations (#1712)
fixes #1709
This commit is contained in:
@@ -1850,9 +1850,13 @@ merge(Compressor.prototype, {
|
|||||||
function before(node, descend, in_list) {
|
function before(node, descend, in_list) {
|
||||||
if (node instanceof AST_Function
|
if (node instanceof AST_Function
|
||||||
&& node.name
|
&& node.name
|
||||||
&& !compressor.option("keep_fnames")
|
&& !compressor.option("keep_fnames")) {
|
||||||
&& !(node.name.definition().id in in_use_ids)) {
|
var def = node.name.definition();
|
||||||
node.name = null;
|
// any declarations with same name will overshadow
|
||||||
|
// name of this anonymous function and can therefore
|
||||||
|
// never be used anywhere
|
||||||
|
if (!(def.id in in_use_ids) || def.orig.length > 1)
|
||||||
|
node.name = null;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
||||||
var trim = !compressor.option("keep_fargs");
|
var trim = !compressor.option("keep_fargs");
|
||||||
|
|||||||
@@ -805,3 +805,42 @@ issue_1656: {
|
|||||||
}
|
}
|
||||||
expect_exact: "for (;;) ;"
|
expect_exact: "for (;;) ;"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1709: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
function x() {
|
||||||
|
var x = 1;
|
||||||
|
return x;
|
||||||
|
}(),
|
||||||
|
function y() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
|
function z() {
|
||||||
|
function z() {}
|
||||||
|
return z;
|
||||||
|
}()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
function() {
|
||||||
|
var x = 1;
|
||||||
|
return x;
|
||||||
|
}(),
|
||||||
|
function() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
|
function() {
|
||||||
|
function z() {}
|
||||||
|
return z;
|
||||||
|
}()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user