aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-07 12:38:22 +0100
committerGitHub <noreply@github.com>2021-05-07 19:38:22 +0800
commit19d232badb0d9b16f447e89c33998fcf542496ce (patch)
treec9ebaab983c06b1c1bc08b12f2b7d9240fee4157 /lib/compress.js
parentd464be3f3f7ef91c7083e16210cc7d1b8a337816 (diff)
downloadtracifyjs-19d232badb0d9b16f447e89c33998fcf542496ce.tar.gz
tracifyjs-19d232badb0d9b16f447e89c33998fcf542496ce.zip
fix corner case in `unused` (#4913)
fixes #4912
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index ba683e24..7b871e41 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6030,8 +6030,10 @@ merge(Compressor.prototype, {
}
if (node instanceof AST_Definitions) {
node.definitions.forEach(function(defn) {
- var side_effects = defn.value
- && (defn.name instanceof AST_Destructured || defn.value.has_side_effects(compressor));
+ var value = defn.value;
+ var side_effects = value
+ && (defn.name instanceof AST_Destructured || value.has_side_effects(compressor));
+ var shared = side_effects && value.tail_node().operator == "=";
defn.name.mark_symbol(function(name) {
if (!(name instanceof AST_SymbolDeclaration)) return;
var def = name.definition();
@@ -6046,13 +6048,17 @@ merge(Compressor.prototype, {
in_use_ids[def.id] = true;
in_use.push(def);
}
- if (defn.value) {
- if (!side_effects) initializations.add(def.id, defn.value);
+ if (value) {
+ if (!side_effects) {
+ initializations.add(def.id, value);
+ } else if (shared) {
+ verify_safe_usage(def, true, value_modified[def.id]);
+ }
assignments.add(def.id, defn);
}
return true;
}, tw);
- if (side_effects) defn.value.walk(tw);
+ if (side_effects) value.walk(tw);
});
return true;
}
@@ -6755,14 +6761,15 @@ merge(Compressor.prototype, {
prop.walk(tw);
});
if (node instanceof AST_Assign) {
- var right = get_rhs(node);
+ var right = get_rhs(node), shared = false;
if (init && node.write_only === true && node_def.scope === self && !right.has_side_effects(compressor)) {
initializations.add(node_def.id, right);
} else {
right.walk(tw);
+ shared = right.tail_node().operator == "=";
}
if (node.left === sym) {
- if (!node.write_only) {
+ if (!node.write_only || shared) {
verify_safe_usage(node_def, true, value_modified[node_def.id]);
}
} else {