enhance unused (#4922)
This commit is contained in:
@@ -6057,7 +6057,7 @@ merge(Compressor.prototype, {
|
||||
if (!side_effects) {
|
||||
initializations.add(def.id, value);
|
||||
} else if (shared) {
|
||||
verify_safe_usage(def, true, value_modified[def.id]);
|
||||
verify_safe_usage(def, name, value_modified[def.id]);
|
||||
}
|
||||
assignments.add(def.id, defn);
|
||||
}
|
||||
@@ -6200,19 +6200,13 @@ merge(Compressor.prototype, {
|
||||
if (drop_vars) {
|
||||
var props = [], sym = assign_as_unused(node, props);
|
||||
if (sym) {
|
||||
var def = sym.definition();
|
||||
var in_use = def.id in in_use_ids;
|
||||
var value;
|
||||
if (can_drop_lhs(sym, node)) {
|
||||
if (node instanceof AST_Assign) {
|
||||
if (!in_use || node.left === sym && indexOf_assign(def, node) < 0) {
|
||||
value = get_rhs(node);
|
||||
if (node.write_only === true) {
|
||||
value = value.drop_side_effect_free(compressor)
|
||||
|| make_node(AST_Number, node, { value: 0 });
|
||||
if (node.write_only === true) value = value.drop_side_effect_free(compressor);
|
||||
}
|
||||
}
|
||||
} else if (!in_use || node.expression === sym && indexOf_assign(def, node) < 0) {
|
||||
value = make_node(AST_Number, node, { value: 0 });
|
||||
if (!value) value = make_node(AST_Number, node, { value: 0 });
|
||||
}
|
||||
if (value) {
|
||||
if (props.assign) {
|
||||
@@ -6705,7 +6699,7 @@ merge(Compressor.prototype, {
|
||||
function verify_safe_usage(def, read, modified) {
|
||||
if (def.id in in_use_ids) return;
|
||||
if (read && modified) {
|
||||
in_use_ids[def.id] = true;
|
||||
in_use_ids[def.id] = read;
|
||||
in_use.push(def);
|
||||
} else {
|
||||
value_read[def.id] = read;
|
||||
@@ -6713,6 +6707,14 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
function can_drop_lhs(sym, node) {
|
||||
var def = sym.definition();
|
||||
var in_use = in_use_ids[def.id];
|
||||
if (!in_use) return true;
|
||||
if (node[node instanceof AST_Assign ? "left" : "expression"] !== sym) return false;
|
||||
return in_use === sym && def.references.length - def.replaced == 1 || indexOf_assign(def, node) < 0;
|
||||
}
|
||||
|
||||
function get_rhs(assign) {
|
||||
var rhs = assign.right;
|
||||
if (!assign.write_only) return rhs;
|
||||
@@ -6775,7 +6777,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (node.left === sym) {
|
||||
if (!node.write_only || shared) {
|
||||
verify_safe_usage(node_def, true, value_modified[node_def.id]);
|
||||
verify_safe_usage(node_def, sym, value_modified[node_def.id]);
|
||||
}
|
||||
} else {
|
||||
var fixed = sym.fixed_value();
|
||||
|
||||
@@ -3436,7 +3436,7 @@ issue_4912_2: {
|
||||
console.log(function() {
|
||||
var g, f = function() {};
|
||||
f.p = {};
|
||||
(g = f.p.q = function() {}).r = "PASS";
|
||||
(f.p.q = function() {}).r = "PASS";
|
||||
return f;
|
||||
}().p.q.r);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user