fix corner case in unsafe evaluate (#3989)

fixes #3988
This commit is contained in:
Alex Lam S.L
2020-06-11 00:37:39 +01:00
committed by GitHub
parent 596fad182e
commit e89031f1af
2 changed files with 42 additions and 18 deletions

View File

@@ -3562,32 +3562,32 @@ merge(Compressor.prototype, {
var regexp_props = makePredicate("global ignoreCase multiline source");
def(AST_PropAccess, function(compressor, ignore_side_effects, cached, depth) {
if (compressor.option("unsafe")) {
var val;
var exp = this.expression;
if (!is_undeclared_ref(exp)) {
val = exp._eval(compressor, ignore_side_effects, cached, depth + 1);
if (val == null || val === exp) return this;
}
var key = this.property;
if (key instanceof AST_Node) {
key = key._eval(compressor, ignore_side_effects, cached, depth);
if (key === this.property) return this;
}
var exp = this.expression;
var val;
if (is_undeclared_ref(exp)) {
if (val === undefined) {
var static_value = static_values[exp.name];
if (!static_value || !static_value[key]) return this;
val = global_objs[exp.name];
} else {
val = exp._eval(compressor, ignore_side_effects, cached, depth + 1);
if (val == null || val === exp) return this;
if (val instanceof RegExp) {
if (!regexp_props[key]) return this;
} else if (typeof val == "object") {
if (!HOP(val, key)) return this;
} else if (typeof val == "function") switch (key) {
case "name":
return val.node.name ? val.node.name.name : "";
case "length":
return val.node.argnames.length;
default:
return this;
}
} else if (val instanceof RegExp) {
if (!regexp_props[key]) return this;
} else if (typeof val == "object") {
if (!HOP(val, key)) return this;
} else if (typeof val == "function") switch (key) {
case "name":
return val.node.name ? val.node.name.name : "";
case "length":
return val.node.argnames.length;
default:
return this;
}
return val[key];
}