fix corner cases in collapse_vars (#4591)

fixes #4590
This commit is contained in:
Alex Lam S.L
2021-01-24 14:15:43 +00:00
committed by GitHub
parent a36c5472d2
commit fd7ad8e779
5 changed files with 32 additions and 2 deletions

View File

@@ -2413,7 +2413,8 @@ merge(Compressor.prototype, {
if (expr instanceof AST_This) return rhs_exact_match;
if (expr.is_truthy()) return rhs_fuzzy_match(true, return_false);
if (expr.is_constant()) {
return rhs_fuzzy_match(expr.evaluate(compressor), rhs_exact_match);
var ev = expr.evaluate(compressor);
if (!(ev instanceof AST_Node)) return rhs_fuzzy_match(ev, rhs_exact_match);
}
if (!(lhs instanceof AST_SymbolRef)) return false;
if (!invariant(expr)) return false;
@@ -2436,7 +2437,8 @@ merge(Compressor.prototype, {
return true;
}
if (node.is_constant()) {
return !node.evaluate(compressor) == !value;
var ev = node.evaluate(compressor);
if (!(ev instanceof AST_Node)) return !ev == !value;
}
}
return fallback(node);