fix corner case in `conditionals` (#4624)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 8 Feb 2021 10:31:08 +0000 (10:31 +0000)
committerGitHub <noreply@github.com>
Mon, 8 Feb 2021 10:31:08 +0000 (18:31 +0800)
fixes #4623

lib/compress.js
test/compress/yields.js

index 9e9f15f..591f28a 100644 (file)
@@ -4466,34 +4466,6 @@ merge(Compressor.prototype, {
         def(AST_Statement, function() {
             throw new Error("Cannot negate a statement");
         });
-        def(AST_Arrow, function() {
-            return basic_negation(this);
-        });
-        def(AST_AsyncArrow, function() {
-            return basic_negation(this);
-        });
-        def(AST_AsyncFunction, function() {
-            return basic_negation(this);
-        });
-        def(AST_Function, function() {
-            return basic_negation(this);
-        });
-        def(AST_UnaryPrefix, function() {
-            if (this.operator == "!")
-                return this.expression;
-            return basic_negation(this);
-        });
-        def(AST_Sequence, function(compressor) {
-            var expressions = this.expressions.slice();
-            expressions.push(expressions.pop().negate(compressor));
-            return make_sequence(this, expressions);
-        });
-        def(AST_Conditional, function(compressor, first_in_statement) {
-            var self = this.clone();
-            self.consequent = self.consequent.negate(compressor);
-            self.alternative = self.alternative.negate(compressor);
-            return best(this, self, first_in_statement);
-        });
         def(AST_Binary, function(compressor, first_in_statement) {
             var self = this.clone(), op = this.operator;
             if (compressor.option("unsafe_comps")) {
@@ -4522,6 +4494,25 @@ merge(Compressor.prototype, {
             }
             return basic_negation(this);
         });
+        def(AST_Conditional, function(compressor, first_in_statement) {
+            var self = this.clone();
+            self.consequent = self.consequent.negate(compressor);
+            self.alternative = self.alternative.negate(compressor);
+            return best(this, self, first_in_statement);
+        });
+        def(AST_LambdaExpression, function() {
+            return basic_negation(this);
+        });
+        def(AST_Sequence, function(compressor) {
+            var expressions = this.expressions.slice();
+            expressions.push(expressions.pop().negate(compressor));
+            return make_sequence(this, expressions);
+        });
+        def(AST_UnaryPrefix, function() {
+            if (this.operator == "!")
+                return this.expression;
+            return basic_negation(this);
+        });
     })(function(node, func) {
         node.DEFMETHOD("negate", function(compressor, first_in_statement) {
             return func.call(this, compressor, first_in_statement);
index 2c06a4a..2d29c9b 100644 (file)
@@ -587,3 +587,18 @@ issue_4618: {
     expect_stdout: "function"
     node_version: ">=4"
 }
+
+issue_4623: {
+    options = {
+        conditionals: true,
+    }
+    input: {
+        if (console ? function*() {} : 0)
+            console.log("PASS");
+    }
+    expect: {
+        (console ? function*() {} : 0) && console.log("PASS");
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}