improve compress granularity through typeofs (#2201)

fixes #2198
This commit is contained in:
Alex Lam S.L
2017-07-05 19:20:33 +08:00
committed by GitHub
parent 5f046c724b
commit 1ac25fc032
4 changed files with 17 additions and 6 deletions

View File

@@ -80,6 +80,7 @@ function Compressor(options, false_by_default) {
switches : !false_by_default,
top_retain : null,
toplevel : !!(options && options["top_retain"]),
typeofs : !false_by_default,
unsafe : false,
unsafe_comps : false,
unsafe_Func : false,
@@ -3591,7 +3592,8 @@ merge(Compressor.prototype, {
case "==":
case "!=":
// "undefined" == typeof x => undefined === x
if (self.left instanceof AST_String
if (compressor.option("typeofs")
&& self.left instanceof AST_String
&& self.left.value == "undefined"
&& self.right instanceof AST_UnaryPrefix
&& self.right.operator == "typeof") {