push: function (node) {
if (node instanceof AST_Lambda) {
this.directives = Object.create(this.directives);
- } else if (node instanceof AST_Directive) {
- this.directives[node.value] = this.directives[node.value] ? "up" : true;
+ } else if (node instanceof AST_Directive && !this.directives[node.value]) {
+ this.directives[node.value] = node;
}
this.stack.push(node);
},
for (var i = 0; i < node.body.length; ++i) {
var st = node.body[i];
if (!(st instanceof AST_Directive)) break;
- if (st.value == type) return true;
+ if (st.value == type) return st;
}
}
},
/* -----[ optimizers ]----- */
OPT(AST_Directive, function(self, compressor){
- if (compressor.has_directive(self.value) === "up") {
+ if (compressor.has_directive(self.value) !== self) {
return make_node(AST_EmptyStatement, self);
}
return self;
var commutativeOperators = makePredicate("== === != !== * & | ^");
OPT(AST_Binary, function(self, compressor){
- var lhs = self.left.evaluate(compressor);
- var rhs = self.right.evaluate(compressor);
- if (lhs.length > 1 && lhs[0].is_constant() !== self.left.is_constant()
- || rhs.length > 1 && rhs[0].is_constant() !== self.right.is_constant()) {
- return make_node(AST_Binary, self, {
- operator: self.operator,
- left: lhs[0],
- right: rhs[0]
- }).optimize(compressor);
- }
function reversible() {
return self.left instanceof AST_Constant
|| self.right instanceof AST_Constant