aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-08 13:45:28 +0800
committerGitHub <noreply@github.com>2019-11-08 13:45:28 +0800
commit10648c9af66364697f0f51219b0497fdfcb6dd34 (patch)
treeb4f2864c7c984a9e8723bcd161114118a82f8d81 /lib
parent87e67ec29958a4167d5c202ae3a0fe4be1e10faf (diff)
downloadtracifyjs-10648c9af66364697f0f51219b0497fdfcb6dd34.tar.gz
tracifyjs-10648c9af66364697f0f51219b0497fdfcb6dd34.zip
enhance `dead_code` (#3575)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js39
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 0d19640d..43ee1126 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6543,23 +6543,28 @@ merge(Compressor.prototype, {
}
}
} else if (self.left instanceof AST_SymbolRef) {
+ if (self.left.is_immutable()) return strip_assignment();
var def = self.left.definition();
- if (def.scope === compressor.find_parent(AST_Lambda)) {
- if (self.left.is_immutable()) return strip_assignment();
- var level = 0, node, parent = self;
- do {
- node = parent;
- parent = compressor.parent(level++);
- if (parent instanceof AST_Exit) {
- if (in_try(level, parent)) break;
- if (is_reachable(def.scope, [ def ])) break;
- def.fixed = false;
- return strip_assignment();
- }
- } while (parent instanceof AST_Binary && parent.right === node
- || parent instanceof AST_Sequence && parent.tail_node() === node
- || parent instanceof AST_UnaryPrefix);
- }
+ var local = def.scope.resolve() === compressor.find_parent(AST_Lambda);
+ var level = 0, node, parent = self;
+ do {
+ node = parent;
+ parent = compressor.parent(level++);
+ if (parent instanceof AST_Assign) {
+ if (!(parent.left instanceof AST_SymbolRef)) continue;
+ if (parent.left.definition() !== def) continue;
+ def.fixed = false;
+ return strip_assignment();
+ } else if (parent instanceof AST_Exit) {
+ if (!local) break;
+ if (in_try(level, parent)) break;
+ if (is_reachable(def.scope, [ def ])) break;
+ def.fixed = false;
+ return strip_assignment();
+ }
+ } while (parent instanceof AST_Binary && parent.right === node
+ || parent instanceof AST_Sequence && parent.tail_node() === node
+ || parent instanceof AST_UnaryPrefix);
}
}
self = self.lift_sequences(compressor);
@@ -6599,7 +6604,7 @@ merge(Compressor.prototype, {
self.right = make_node(AST_Null, right);
var may_throw = node.may_throw(compressor);
self.right = right;
- var scope = self.left.definition().scope;
+ var scope = self.left.definition().scope.resolve();
var parent;
while ((parent = compressor.parent(level++)) !== scope) {
if (parent instanceof AST_Try) {