fix unsafe evaluate on type-converting operators (#2917)

fixes #2916
This commit is contained in:
Alex Lam S.L
2018-02-14 16:48:47 +08:00
committed by GitHub
parent 83d8aa8b12
commit d316fb139d
2 changed files with 64 additions and 0 deletions

View File

@@ -2375,6 +2375,7 @@ merge(Compressor.prototype, {
}
return this;
});
var non_converting_unary = makePredicate("! typeof void");
def(AST_UnaryPrefix, function(compressor, depth) {
var e = this.expression;
// Function would be evaluated to an array and so typeof would
@@ -2386,6 +2387,7 @@ merge(Compressor.prototype, {
&& e.fixed_value() instanceof AST_Lambda)) {
return typeof function(){};
}
if (!non_converting_unary(this.operator)) depth++;
e = e._eval(compressor, depth);
if (e === this.expression) return this;
switch (this.operator) {
@@ -2402,7 +2404,9 @@ merge(Compressor.prototype, {
}
return this;
});
var non_converting_binary = makePredicate("&& || === !==");
def(AST_Binary, function(compressor, depth) {
if (!non_converting_binary(this.operator)) depth++;
var left = this.left._eval(compressor, depth);
if (left === this.left) return this;
var right = this.right._eval(compressor, depth);