enhance unused (#3662)
This commit is contained in:
@@ -3879,7 +3879,7 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return scan_ref_scoped(node, descend);
|
return scan_ref_scoped(node, descend, true);
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
// pass 2: for every used symbol we need to walk its
|
// pass 2: for every used symbol we need to walk its
|
||||||
@@ -3913,6 +3913,11 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Assign) {
|
if (node instanceof AST_Assign) {
|
||||||
if (!in_use || node.left === sym && def.id in fixed_ids && fixed_ids[def.id] !== node) {
|
if (!in_use || node.left === sym && def.id in fixed_ids && fixed_ids[def.id] !== node) {
|
||||||
value = get_rhs(node);
|
value = get_rhs(node);
|
||||||
|
if (node.write_only) {
|
||||||
|
value = value.drop_side_effect_free(compressor) || make_node(AST_Number, node, {
|
||||||
|
value: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (!in_use) {
|
} else if (!in_use) {
|
||||||
value = make_node(AST_Number, node, {
|
value = make_node(AST_Number, node, {
|
||||||
@@ -4182,7 +4187,7 @@ merge(Compressor.prototype, {
|
|||||||
return rhs.right.has_side_effects(compressor) ? rhs : rhs.right;
|
return rhs.right.has_side_effects(compressor) ? rhs : rhs.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
function scan_ref_scoped(node, descend) {
|
function scan_ref_scoped(node, descend, init) {
|
||||||
var node_def, props = [], sym = assign_as_unused(node, props);
|
var node_def, props = [], sym = assign_as_unused(node, props);
|
||||||
if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) {
|
if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) {
|
||||||
props.forEach(function(prop) {
|
props.forEach(function(prop) {
|
||||||
@@ -4191,7 +4196,11 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Assign) {
|
if (node instanceof AST_Assign) {
|
||||||
if (node.write_only === "p" && node.right.may_throw_on_access(compressor)) return;
|
if (node.write_only === "p" && node.right.may_throw_on_access(compressor)) return;
|
||||||
var right = get_rhs(node);
|
var right = get_rhs(node);
|
||||||
right.walk(tw);
|
if (init && node.write_only && node_def.scope === self && !right.has_side_effects(compressor)) {
|
||||||
|
initializations.add(node_def.id, right);
|
||||||
|
} else {
|
||||||
|
right.walk(tw);
|
||||||
|
}
|
||||||
if (node.left === sym) {
|
if (node.left === sym) {
|
||||||
if (!node_def.chained && sym.fixed_value(true) === right) {
|
if (!node_def.chained && sym.fixed_value(true) === right) {
|
||||||
fixed_ids[node_def.id] = node;
|
fixed_ids[node_def.id] = node;
|
||||||
|
|||||||
@@ -2254,3 +2254,84 @@ issue_3598: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self_assign: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(a) {
|
||||||
|
a = a;
|
||||||
|
}
|
||||||
|
function e(a, b) {
|
||||||
|
a = b;
|
||||||
|
b = a;
|
||||||
|
}
|
||||||
|
function f(a, b, c) {
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
c = a;
|
||||||
|
}
|
||||||
|
function g(a, b, c) {
|
||||||
|
a = a * b + c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function d(a) {}
|
||||||
|
function e(a, b) {}
|
||||||
|
function f(a, b, c) {}
|
||||||
|
function g(a, b, c) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function_argument_reference: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_parameter_ie8: {
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
f(a = 1 + a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
})(0);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -266,12 +266,7 @@ issue_2084: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
!function() {
|
23..toString(),
|
||||||
var c;
|
|
||||||
c = 1 + (c = -1),
|
|
||||||
c = 1 + (c = 0),
|
|
||||||
0 !== 23..toString() && (c = 1 + c);
|
|
||||||
}(),
|
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
|
|||||||
Reference in New Issue
Block a user