}
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) {
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;