@@ -2452,7 +2452,7 @@ Compressor.prototype.compress = function(node) {
|
||||
|
||||
function is_last_node(node, parent) {
|
||||
if (node instanceof AST_Await) return true;
|
||||
if (node.TYPE == "Binary") return node.operator == "in" && !is_object(node.right);
|
||||
if (node.TYPE == "Binary") return !can_drop_op(node.operator, node.right);
|
||||
if (node instanceof AST_Call) {
|
||||
var def, fn = node.expression;
|
||||
if (fn instanceof AST_SymbolRef) {
|
||||
@@ -5551,7 +5551,7 @@ Compressor.prototype.compress = function(node) {
|
||||
def(AST_Binary, function(compressor) {
|
||||
return this.left.has_side_effects(compressor)
|
||||
|| this.right.has_side_effects(compressor)
|
||||
|| this.operator == "in" && !is_object(this.right);
|
||||
|| !can_drop_op(this.operator, this.right);
|
||||
});
|
||||
def(AST_Block, function(compressor) {
|
||||
return any(this.body, compressor);
|
||||
@@ -5705,7 +5705,7 @@ Compressor.prototype.compress = function(node) {
|
||||
def(AST_Binary, function(compressor) {
|
||||
return this.left.may_throw(compressor)
|
||||
|| this.right.may_throw(compressor)
|
||||
|| this.operator == "in" && !is_object(this.right);
|
||||
|| !can_drop_op(this.operator, this.right);
|
||||
});
|
||||
def(AST_Block, function(compressor) {
|
||||
return any(this.body, compressor);
|
||||
@@ -5822,7 +5822,7 @@ Compressor.prototype.compress = function(node) {
|
||||
def(AST_Binary, function(scope) {
|
||||
return this.left.is_constant_expression(scope)
|
||||
&& this.right.is_constant_expression(scope)
|
||||
&& (this.operator != "in" || is_object(this.right));
|
||||
&& can_drop_op(this.operator, this.right);
|
||||
});
|
||||
def(AST_Class, function(scope) {
|
||||
var base = this.extends;
|
||||
@@ -8533,7 +8533,7 @@ Compressor.prototype.compress = function(node) {
|
||||
var left = this.left;
|
||||
var right = this.right;
|
||||
var op = this.operator;
|
||||
if (op == "in" && !is_object(right)) {
|
||||
if (!can_drop_op(op, right)) {
|
||||
var lhs = left.drop_side_effect_free(compressor, first_in_statement);
|
||||
if (lhs === left) return this;
|
||||
var node = this.clone();
|
||||
@@ -11202,6 +11202,18 @@ Compressor.prototype.compress = function(node) {
|
||||
|| node instanceof AST_Object;
|
||||
}
|
||||
|
||||
function can_drop_op(op, rhs) {
|
||||
switch (op) {
|
||||
case "in":
|
||||
return is_object(rhs);
|
||||
case "instanceof":
|
||||
if (rhs instanceof AST_SymbolRef) rhs = rhs.fixed_value();
|
||||
return is_lambda(rhs);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function is_primitive(compressor, node) {
|
||||
if (node.is_constant()) return true;
|
||||
if (node instanceof AST_Assign) return node.operator != "=" || is_primitive(compressor, node.right);
|
||||
@@ -11708,6 +11720,12 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "instanceof":
|
||||
if (is_lambda(self.right)) return make_sequence(self, [
|
||||
self,
|
||||
make_node(AST_False, self),
|
||||
]).optimize(compressor);
|
||||
break;
|
||||
}
|
||||
if (!(parent instanceof AST_UnaryPrefix && parent.operator == "delete")) {
|
||||
if (self.left instanceof AST_Number && !self.right.is_constant()) switch (self.operator) {
|
||||
|
||||
Reference in New Issue
Block a user