&& unaryPrefix[this.operator];
}
});
- function modified(sym) {
- if (!(sym instanceof AST_SymbolRef)) return;
- sym.definition().references.forEach(function(node) {
- delete node._eval;
- });
+ var scan_modified = new TreeWalker(function(node) {
+ if (node instanceof AST_Assign) modified(node.left);
+ if (node instanceof AST_Unary && unary_arithmetic[node.operator]) modified(node.expression);
+ });
+ function modified(node) {
+ if (node instanceof AST_Dot) {
+ modified(node.expression);
+ } else if (node instanceof AST_Sub) {
+ modified(node.expression);
+ node.property.walk(scan_modified);
+ } else if (node instanceof AST_SymbolRef) {
+ node.definition().references.forEach(function(ref) {
+ delete ref._eval;
+ });
+ }
}
def(AST_Statement, function() {
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
});
def(AST_Sequence, function(compressor, ignore_side_effects, cached, depth) {
if (!ignore_side_effects) return this;
- var tail = this.tail_node();
- this.walk(new TreeWalker(function(node) {
- if (node === tail) return true;
- if (node instanceof AST_Assign) modified(node.left);
- if (node instanceof AST_Unary && unary_arithmetic[node.operator]) modified(node.expression);
- }));
+ var exprs = this.expressions;
+ for (var i = 0, last = exprs.length - 1; i < last; i++) {
+ exprs[i].walk(scan_modified);
+ }
+ var tail = exprs[last];
var value = tail._eval(compressor, ignore_side_effects, cached, depth);
return value === tail ? this : value;
});