enhance `comparisons` (#4062)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 22 Aug 2020 17:03:48 +0000 (01:03 +0800)
committerGitHub <noreply@github.com>
Sat, 22 Aug 2020 17:03:48 +0000 (01:03 +0800)
lib/compress.js
test/compress/comparisons.js

index 595e503..bcaecb8 100644 (file)
@@ -7112,7 +7112,7 @@ merge(Compressor.prototype, {
                 && self.right instanceof AST_SymbolRef
                 && self.left.definition() === self.right.definition()
                 && is_object(self.left)) {
-                return make_node(self.operator[0] == "=" ? AST_True : AST_False, self);
+                return make_node(self.operator[0] == "=" ? AST_True : AST_False, self).optimize(compressor);
             }
             break;
           case "&&":
index f93ccbe..a04498e 100644 (file)
@@ -123,6 +123,29 @@ self_comparison_3: {
     ]
 }
 
+self_comparison_4: {
+    options = {
+        booleans: true,
+        comparisons: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var o = {};
+        console.log(o == o, o != o);
+        console.log(o === o, o !== o);
+    }
+    expect: {
+        console.log(!0, !1);
+        console.log(!0, !1);
+    }
+    expect_stdout: [
+        "true false",
+        "true false",
+    ]
+}
+
 issue_2857_1: {
     options = {
         comparisons: true,