Fixed typeof undefined optimization and updated related test case to
authorJustin Lau <justin@tclau.com>
Sun, 5 May 2013 12:38:32 +0000 (20:38 +0800)
committerMihai Bazon <mihai@bazon.net>
Wed, 8 May 2013 13:22:48 +0000 (16:22 +0300)
accomodates the sort behaviour changes made in commit
mishoo/UglifyJS2@aebafad41eab48f43ed649ce8c77e8f1528b50da.
Signed-off-by: Justin Lau <justin@tclau.com>
lib/compress.js
test/compress/issue-105.js

index 992d78f..c994a3a 100644 (file)
@@ -1751,14 +1751,14 @@ merge(Compressor.prototype, {
             // XXX: intentionally falling down to the next case
           case "==":
           case "!=":
-            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.left = self.right.expression;
+            if (compressor.option("unsafe")
+                && self.left instanceof AST_UnaryPrefix
+                && self.left.operator == "typeof"
+                && self.right instanceof AST_String
+                && self.right.value == "undefined") {
+                if (!(self.left.expression instanceof AST_SymbolRef)
+                    || !self.left.expression.undeclared()) {
+                    self.left = self.left.expression;
                     self.right = make_node(AST_Undefined, self.left).optimize(compressor);
                     if (self.operator.length == 2) self.operator += "=";
                 }
index 349d732..0c37eb8 100644 (file)
@@ -1,10 +1,9 @@
 typeof_eq_undefined: {
     options = {
-        comparisons: true,
-        unsafe: false
+        comparisons: true
     };
     input: { a = typeof b.c != "undefined" }
-    expect: { a = "undefined" != typeof b.c }
+    expect: { a = typeof b.c != "undefined" }
 }
 
 typeof_eq_undefined_unsafe: {