aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-07 20:58:29 +0100
committerGitHub <noreply@github.com>2021-05-08 03:58:29 +0800
commitbbca9de9cd7e715bf62a8c624cd3f53e4386b566 (patch)
tree2e01220b7f5f71a522fc48ce1d9dff851daa2772 /lib/compress.js
parentee9ceb79ca61c8adb9bbf7e82459ab0bbe3aaced (diff)
downloadtracifyjs-bbca9de9cd7e715bf62a8c624cd3f53e4386b566.tar.gz
tracifyjs-bbca9de9cd7e715bf62a8c624cd3f53e4386b566.zip
fix corner case in `collapse_vars` (#4919)
fixes #4918
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js44
1 files changed, 21 insertions, 23 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fdf46fb9..af9ff7e3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2546,12 +2546,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_PropAccess) {
var exp = parent.expression;
if (exp === node) return find_stop_unused(parent, level + 1);
- var sym = root_expr(exp);
- if (!(sym instanceof AST_SymbolRef)) return find_stop_unused(parent, level + 1);
- var lvalue = lvalues.get(sym.name);
- return !lvalue || all(lvalue, function(lhs) {
- return !(lhs instanceof AST_PropAccess);
- }) ? find_stop_unused(parent, level + 1) : node;
+ return check_expr(exp);
}
if (parent instanceof AST_Sequence) return find_stop_unused(parent, level + 1);
if (parent instanceof AST_SimpleStatement) return find_stop_unused(parent, level + 1);
@@ -2562,25 +2557,28 @@ merge(Compressor.prototype, {
if (parent instanceof AST_Yield) return node;
return null;
+ function check_expr(expr) {
+ var replace = can_replace;
+ can_replace = false;
+ var after = stop_after;
+ var if_hit = stop_if_hit;
+ var stack = scanner.stack;
+ scanner.stack = [ parent ];
+ expr.transform(scanner);
+ scanner.stack = stack;
+ stop_if_hit = if_hit;
+ stop_after = after;
+ can_replace = replace;
+ if (abort) {
+ abort = false;
+ return node;
+ }
+ return find_stop_unused(parent, level + 1);
+ }
+
function check_assignment(lhs) {
if (may_throw(parent)) return node;
- if (lhs !== node && lhs instanceof AST_Destructured) {
- var replace = can_replace;
- can_replace = false;
- var after = stop_after;
- var if_hit = stop_if_hit;
- var stack = scanner.stack;
- scanner.stack = [ parent ];
- lhs.transform(scanner);
- scanner.stack = stack;
- stop_if_hit = if_hit;
- stop_after = after;
- can_replace = replace;
- if (abort) {
- abort = false;
- return node;
- }
- }
+ if (lhs !== node && lhs instanceof AST_Destructured) return check_expr(lhs);
return find_stop_unused(parent, level + 1);
}
}