enhance join_vars (#4881)

This commit is contained in:
Alex Lam S.L
2021-04-30 04:40:47 +01:00
committed by GitHub
parent 8aa650bcf9
commit d833e66d23
3 changed files with 87 additions and 19 deletions

View File

@@ -3396,12 +3396,14 @@ merge(Compressor.prototype, {
if (prop instanceof AST_Node) break;
prop = "" + prop;
var diff = prop == "__proto__" || compressor.has_directive("use strict") ? function(node) {
return typeof node.key == "string" && node.key != prop;
var key = node.key;
return typeof key == "string" && key != prop && key != "__proto__";
} : function(node) {
var key = node.key;
if (node instanceof AST_ObjectGetter || node instanceof AST_ObjectSetter) {
return typeof node.key == "string" && node.key != prop;
return typeof key == "string" && key != prop;
}
return true;
return key !== "__proto__";
};
if (!all(value.properties, diff)) break;
value.properties.push(make_node(AST_ObjectKeyVal, node, {
@@ -5141,12 +5143,12 @@ merge(Compressor.prototype, {
return true;
}
def(AST_Node, return_false);
def(AST_Array, function() {
return all_constant(this.elements);
def(AST_Array, function(scope) {
return all_constant(this.elements, scope);
});
def(AST_Binary, function() {
return this.left.is_constant_expression()
&& this.right.is_constant_expression()
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));
});
def(AST_Class, function(scope) {
@@ -5198,14 +5200,14 @@ merge(Compressor.prototype, {
}));
return result;
});
def(AST_Object, function() {
return all_constant(this.properties);
def(AST_Object, function(scope) {
return all_constant(this.properties, scope);
});
def(AST_ObjectProperty, function() {
return typeof this.key == "string" && this.value.is_constant_expression();
def(AST_ObjectProperty, function(scope) {
return typeof this.key == "string" && this.value.is_constant_expression(scope);
});
def(AST_Unary, function() {
return this.expression.is_constant_expression();
def(AST_Unary, function(scope) {
return this.expression.is_constant_expression(scope);
});
})(function(node, func) {
node.DEFMETHOD("is_constant_expression", func);