aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-06-13 19:50:26 +0100
committerGitHub <noreply@github.com>2020-06-14 02:50:26 +0800
commit88850a6e05b25a4ffa66e729cca56bd15850a756 (patch)
treef8d384746596fc71176be5b958604b3a3be24677 /lib/compress.js
parent9e881407bda32aeca1d383aa4137553c88419354 (diff)
downloadtracifyjs-88850a6e05b25a4ffa66e729cca56bd15850a756.tar.gz
tracifyjs-88850a6e05b25a4ffa66e729cca56bd15850a756.zip
enhance `evaluate` (#3995)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 860eae11..cf286187 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1485,7 +1485,7 @@ merge(Compressor.prototype, {
}
function is_last_node(node, parent) {
- if (node.TYPE == "Binary") return node.operator == "in" && !is_object(node.right.tail_node());
+ if (node.TYPE == "Binary") return node.operator == "in" && !is_object(node.right);
if (node instanceof AST_Call) {
var def, fn = node.expression;
if (fn instanceof AST_SymbolRef) {
@@ -3369,10 +3369,10 @@ merge(Compressor.prototype, {
var elements = [];
for (var i = 0; i < this.elements.length; i++) {
var element = this.elements[i];
- if (element instanceof AST_Hole) continue;
+ if (element instanceof AST_Hole) return this;
var value = element._eval(compressor, ignore_side_effects, cached, depth);
if (element === value) return this;
- elements[i] = value;
+ elements.push(value);
}
return elements;
}
@@ -3384,16 +3384,11 @@ merge(Compressor.prototype, {
for (var i = 0; i < this.properties.length; i++) {
var prop = this.properties[i];
var key = prop.key;
- if (key instanceof AST_Symbol) {
- key = key.name;
- } else if (key instanceof AST_Node) {
- key = key._eval(compressor, ignore_side_effects, cached, depth);
- if (key === prop.key) return this;
- }
- if (typeof Object.prototype[key] === "function") {
- return this;
+ if (key instanceof AST_Symbol) key = key.name;
+ if (prop.value instanceof AST_Function) {
+ if (typeof Object.prototype[key] == "function") return this;
+ continue;
}
- if (prop.value instanceof AST_Function) continue;
val[key] = prop.value._eval(compressor, ignore_side_effects, cached, depth);
if (val[key] === prop.value) return this;
}
@@ -3480,10 +3475,10 @@ merge(Compressor.prototype, {
case "&" : result = left & right; break;
case "^" : result = left ^ right; break;
case "+" : result = left + right; break;
+ case "-" : result = left - right; break;
case "*" : result = left * right; break;
case "/" : result = left / right; break;
case "%" : result = left % right; break;
- case "-" : result = left - right; break;
case "<<" : result = left << right; break;
case ">>" : result = left >> right; break;
case ">>>": result = left >>> right; break;
@@ -3495,7 +3490,13 @@ merge(Compressor.prototype, {
case "<=" : result = left <= right; break;
case ">" : result = left > right; break;
case ">=" : result = left >= right; break;
- default : return this;
+ case "in":
+ if (right && typeof right == "object" && HOP(right, left)) {
+ result = true;
+ break;
+ }
+ default:
+ return this;
}
if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
if (compressor.option("unsafe_math")
@@ -3849,7 +3850,7 @@ merge(Compressor.prototype, {
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.tail_node());
+ || this.operator == "in" && !is_object(this.right);
});
def(AST_Block, function(compressor) {
return any(this.body, compressor);
@@ -3962,7 +3963,7 @@ merge(Compressor.prototype, {
def(AST_Binary, function(compressor) {
return this.left.may_throw(compressor)
|| this.right.may_throw(compressor)
- || this.operator == "in" && !is_object(this.right.tail_node());
+ || this.operator == "in" && !is_object(this.right);
});
def(AST_Block, function(compressor) {
return any(this.body, compressor);
@@ -4057,7 +4058,7 @@ merge(Compressor.prototype, {
def(AST_Binary, function() {
return this.left.is_constant_expression()
&& this.right.is_constant_expression()
- && (this.operator != "in" || is_object(this.right.tail_node()));
+ && (this.operator != "in" || is_object(this.right));
});
def(AST_Constant, return_true);
def(AST_Lambda, function(scope) {
@@ -5163,7 +5164,7 @@ merge(Compressor.prototype, {
return this;
});
def(AST_Binary, function(compressor, first_in_statement) {
- if (this.operator == "in" && !is_object(this.right.tail_node())) {
+ if (this.operator == "in" && !is_object(this.right)) {
var left = this.left.drop_side_effect_free(compressor, first_in_statement);
if (left === this.left) return this;
var node = this.clone();
@@ -6921,10 +6922,9 @@ merge(Compressor.prototype, {
var indexFns = makePredicate("indexOf lastIndexOf");
var commutativeOperators = makePredicate("== === != !== * & | ^");
function is_object(node) {
- while (node instanceof AST_SymbolRef) {
+ while ((node = node.tail_node()) instanceof AST_SymbolRef) {
node = node.fixed_value();
if (!node) return false;
- node = node.tail_node();
}
return node instanceof AST_Array
|| node instanceof AST_Lambda