enhance unsafe_comps (#5510)
This commit is contained in:
@@ -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 !can_drop_op(node.operator, node.right);
|
||||
if (node.TYPE == "Binary") return !can_drop_op(node.operator, node.right, compressor);
|
||||
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)
|
||||
|| !can_drop_op(this.operator, this.right);
|
||||
|| !can_drop_op(this.operator, this.right, compressor);
|
||||
});
|
||||
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)
|
||||
|| !can_drop_op(this.operator, this.right);
|
||||
|| !can_drop_op(this.operator, this.right, compressor);
|
||||
});
|
||||
def(AST_Block, function(compressor) {
|
||||
return any(this.body, compressor);
|
||||
@@ -8533,7 +8533,7 @@ Compressor.prototype.compress = function(node) {
|
||||
var left = this.left;
|
||||
var right = this.right;
|
||||
var op = this.operator;
|
||||
if (!can_drop_op(op, right)) {
|
||||
if (!can_drop_op(op, right, compressor)) {
|
||||
var lhs = left.drop_side_effect_free(compressor, first_in_statement);
|
||||
if (lhs === left) return this;
|
||||
var node = this.clone();
|
||||
@@ -11202,13 +11202,13 @@ Compressor.prototype.compress = function(node) {
|
||||
|| node instanceof AST_Object;
|
||||
}
|
||||
|
||||
function can_drop_op(op, rhs) {
|
||||
function can_drop_op(op, rhs, compressor) {
|
||||
switch (op) {
|
||||
case "in":
|
||||
return is_object(rhs);
|
||||
return is_object(rhs) || compressor && compressor.option("unsafe_comps");
|
||||
case "instanceof":
|
||||
if (rhs instanceof AST_SymbolRef) rhs = rhs.fixed_value();
|
||||
return is_lambda(rhs);
|
||||
return is_lambda(rhs) || compressor && compressor.option("unsafe_comps");
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user