improve unused over duplicate variable names (#2656)
This commit is contained in:
@@ -2645,14 +2645,14 @@ merge(Compressor.prototype, {
|
|||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node === self) return;
|
if (node === self) return;
|
||||||
if (node instanceof AST_Defun) {
|
if (node instanceof AST_Defun) {
|
||||||
|
var node_def = node.name.definition();
|
||||||
if (!drop_funcs && scope === self) {
|
if (!drop_funcs && scope === self) {
|
||||||
var node_def = node.name.definition();
|
|
||||||
if (!(node_def.id in in_use_ids)) {
|
if (!(node_def.id in in_use_ids)) {
|
||||||
in_use_ids[node_def.id] = true;
|
in_use_ids[node_def.id] = true;
|
||||||
in_use.push(node_def);
|
in_use.push(node_def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initializations.add(node.name.name, node);
|
initializations.add(node_def.id, node);
|
||||||
return true; // don't go in nested scopes
|
return true; // don't go in nested scopes
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolFunarg && scope === self) {
|
if (node instanceof AST_SymbolFunarg && scope === self) {
|
||||||
@@ -2671,7 +2671,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def.value) {
|
if (def.value) {
|
||||||
initializations.add(def.name.name, def.value);
|
initializations.add(node_def.id, def.value);
|
||||||
if (def.value.has_side_effects(compressor)) {
|
if (def.value.has_side_effects(compressor)) {
|
||||||
def.value.walk(tw);
|
def.value.walk(tw);
|
||||||
}
|
}
|
||||||
@@ -2686,13 +2686,10 @@ merge(Compressor.prototype, {
|
|||||||
// initialization code to figure out if it uses other
|
// initialization code to figure out if it uses other
|
||||||
// symbols (that may not be in_use).
|
// symbols (that may not be in_use).
|
||||||
tw = new TreeWalker(scan_ref_scoped);
|
tw = new TreeWalker(scan_ref_scoped);
|
||||||
for (var i = 0; i < in_use.length; ++i) {
|
for (var i = 0; i < in_use.length; i++) {
|
||||||
in_use[i].orig.forEach(function(decl){
|
var init = initializations.get(in_use[i].id);
|
||||||
// undeclared globals will be instanceof AST_SymbolRef
|
if (init) init.forEach(function(init) {
|
||||||
var init = initializations.get(decl.name);
|
init.walk(tw);
|
||||||
if (init) init.forEach(function(init){
|
|
||||||
init.walk(tw);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// pass 3: we should drop declarations not in_use
|
// pass 3: we should drop declarations not in_use
|
||||||
|
|||||||
@@ -1413,3 +1413,24 @@ issue_2516_2: {
|
|||||||
Baz(2);
|
Baz(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defun_lambda_same_name: {
|
||||||
|
options = {
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(n) {
|
||||||
|
return n ? n * f(n - 1) : 1;
|
||||||
|
}
|
||||||
|
console.log(function f(n) {
|
||||||
|
return n ? n * f(n - 1) : 1;
|
||||||
|
}(5));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(n) {
|
||||||
|
return n ? n * f(n - 1) : 1;
|
||||||
|
}(5));
|
||||||
|
}
|
||||||
|
expect_stdout: "120"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user