aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-14 18:09:54 +0100
committerGitHub <noreply@github.com>2020-05-15 01:09:54 +0800
commit5ef7060098e231e1c31800f0ebcb19317bf0e077 (patch)
tree54ece930c586de29fad4141c120cfed698c01f4b /lib/compress.js
parent938368ba219f29703b9f9e67c6fb0d1c0723220a (diff)
downloadtracifyjs-5ef7060098e231e1c31800f0ebcb19317bf0e077.tar.gz
tracifyjs-5ef7060098e231e1c31800f0ebcb19317bf0e077.zip
fix corner case in `collapse_vars` (#3898)
fixes #3897
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 93dbe063..36a04a70 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1855,7 +1855,12 @@ merge(Compressor.prototype, {
}
function foldable(expr) {
+ var lhs_ids = Object.create(null);
+ var marker = new TreeWalker(function(node) {
+ if (node instanceof AST_SymbolRef) lhs_ids[node.definition().id] = true;
+ });
while (expr instanceof AST_Assign && expr.operator == "=") {
+ expr.left.walk(marker);
expr = expr.right;
}
if (expr instanceof AST_SymbolRef) {
@@ -1871,12 +1876,9 @@ merge(Compressor.prototype, {
if (!(lhs instanceof AST_SymbolRef)) return false;
if (!invariant(expr)) return false;
var circular;
- var def = lhs.definition();
expr.walk(new TreeWalker(function(node) {
if (circular) return true;
- if (node instanceof AST_SymbolRef && node.definition() === def) {
- circular = true;
- }
+ if (node instanceof AST_SymbolRef && lhs_ids[node.definition().id]) circular = true;
}));
return !circular && rhs_exact_match;