return this;
});
+ var indexFns = makePredicate("indexOf lastIndexOf");
var commutativeOperators = makePredicate("== === != !== * & | ^");
function is_object(node) {
return node instanceof AST_Array
}
}
}
+ if (compressor.option("unsafe")
+ && self.right instanceof AST_Call
+ && self.right.expression instanceof AST_Dot
+ && indexFns[self.right.expression.property]) {
+ if (compressor.option("comparisons") && is_indexOf_match_pattern()) {
+ var node = make_node(AST_UnaryPrefix, self, {
+ operator: "!",
+ expression: make_node(AST_UnaryPrefix, self, {
+ operator: "~",
+ expression: self.right
+ })
+ });
+ if (self.operator == "!=" || self.operator == "<=") node = make_node(AST_UnaryPrefix, self, {
+ operator: "!",
+ expression: node
+ });
+ return node.optimize(compressor);
+ }
+ }
// x && (y && z) ==> x && y && z
// x || (y || z) ==> x || y || z
// x + ("y" + z) ==> x + "y" + z
if (node.is_truthy()) return true;
return node.evaluate(compressor);
}
+
+ function is_indexOf_match_pattern() {
+ switch (self.operator) {
+ case ">":
+ case "<=":
+ // 0 > array.indexOf(string) => !~array.indexOf(string)
+ // 0 <= array.indexOf(string) => !!~array.indexOf(string)
+ return self.left instanceof AST_Number && self.left.getValue() == 0;
+ case "==":
+ case "!=":
+ // -1 == array.indexOf(string) => !~array.indexOf(string)
+ // -1 != array.indexOf(string) => !!~array.indexOf(string)
+ return self.left instanceof AST_Number && self.left.getValue() == -1
+ || self.left instanceof AST_UnaryPrefix && self.left.operator == "-"
+ && self.left.expression instanceof AST_Number && self.left.expression.getValue() == 1;
+ }
+ }
});
function recursive_ref(compressor, def) {