enable typeof "undefined" for general use

move out of unsafe, guard corner case with screw_id8 instead

closes #1446
This commit is contained in:
alexlamsl
2017-02-18 19:01:42 +08:00
parent fa668a28b4
commit e5badb9541
3 changed files with 77 additions and 30 deletions

View File

@@ -2504,14 +2504,15 @@ merge(Compressor.prototype, {
// XXX: intentionally falling down to the next case
case "==":
case "!=":
// "undefined" == typeof x => undefined === x
if (self.left instanceof AST_String
&& self.left.value == "undefined"
&& self.right instanceof AST_UnaryPrefix
&& self.right.operator == "typeof"
&& compressor.option("unsafe")) {
if (!(self.right.expression instanceof AST_SymbolRef)
|| !self.right.expression.undeclared()) {
self.right = self.right.expression;
&& self.right.operator == "typeof") {
var expr = self.right.expression;
if (expr instanceof AST_SymbolRef ? !expr.undeclared()
: !(expr instanceof AST_PropAccess) || compressor.option("screw_ie8")) {
self.right = expr;
self.left = make_node(AST_Undefined, self.left).optimize(compressor);
if (self.operator.length == 2) self.operator += "=";
}