aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-31 23:39:24 +0800
committerGitHub <noreply@github.com>2019-12-31 23:39:24 +0800
commitd83d3d741ac8ea41a3776c9ca8d60e752180d420 (patch)
tree8fcc54acf1987c051dc51c186a0f0f77fab1966a /lib
parent99ac73a635d641935331e71d519c24297b50dd32 (diff)
downloadtracifyjs-d83d3d741ac8ea41a3776c9ca8d60e752180d420.tar.gz
tracifyjs-d83d3d741ac8ea41a3776c9ca8d60e752180d420.zip
enhance `unused` (#3662)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 38d09068..2bbd9704 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3879,7 +3879,7 @@ merge(Compressor.prototype, {
});
return true;
}
- return scan_ref_scoped(node, descend);
+ return scan_ref_scoped(node, descend, true);
});
self.walk(tw);
// pass 2: for every used symbol we need to walk its
@@ -3913,6 +3913,11 @@ merge(Compressor.prototype, {
if (node instanceof AST_Assign) {
if (!in_use || node.left === sym && def.id in fixed_ids && fixed_ids[def.id] !== 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) {
value = make_node(AST_Number, node, {
@@ -4182,7 +4187,7 @@ merge(Compressor.prototype, {
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);
if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) {
props.forEach(function(prop) {
@@ -4191,7 +4196,11 @@ merge(Compressor.prototype, {
if (node instanceof AST_Assign) {
if (node.write_only === "p" && node.right.may_throw_on_access(compressor)) return;
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_def.chained && sym.fixed_value(true) === right) {
fixed_ids[node_def.id] = node;