enhance evaluate (#3339)

fixes #3299
This commit is contained in:
Alex Lam S.L
2019-03-15 02:48:23 +08:00
committed by GitHub
parent 627f5fb41e
commit b3ef5e514d
2 changed files with 16 additions and 10 deletions

View File

@@ -2727,19 +2727,25 @@ merge(Compressor.prototype, {
return typeof function(){};
}
if (!non_converting_unary[this.operator]) depth++;
e = e._eval(compressor, cached, depth);
if (e === this.expression) return this;
var v = e._eval(compressor, cached, depth);
if (v === this.expression) return this;
switch (this.operator) {
case "!": return !e;
case "!": return !v;
case "typeof":
// typeof <RegExp> returns "object" or "function" on different platforms
// so cannot evaluate reliably
if (e instanceof RegExp) return this;
return typeof e;
case "void": return void e;
case "~": return ~e;
case "-": return -e;
case "+": return +e;
if (v instanceof RegExp) return this;
return typeof v;
case "void": return void v;
case "~": return ~v;
case "-": return -v;
case "+": return +v;
case "++":
case "--":
if (e instanceof AST_SymbolRef) {
var refs = e.definition().references;
if (refs[refs.length - 1] === e) return v;
}
}
return this;
});