fix corner case in `sequences` (#3491)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 17 Oct 2019 01:57:50 +0000 (09:57 +0800)
committerGitHub <noreply@github.com>
Thu, 17 Oct 2019 01:57:50 +0000 (09:57 +0800)
fixes #3490

lib/compress.js
test/compress/sequences.js

index c903d9a..e39435c 100644 (file)
@@ -2030,14 +2030,14 @@ merge(Compressor.prototype, {
                 n--;
                 CHANGED = true;
                 var left = prev.body;
-                return make_sequence(left, [ left, right ]).transform(compressor);
+                return make_sequence(left, [ left, right ]);
             }
             var n = 0, prev;
             for (var i = 0; i < statements.length; i++) {
                 var stat = statements[i];
                 if (prev) {
                     if (stat instanceof AST_Exit) {
-                        stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor));
+                        stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor);
                     } else if (stat instanceof AST_For) {
                         if (!(stat.init instanceof AST_Definitions)) {
                             var abort = false;
index 08a0679..fbca559 100644 (file)
@@ -1006,3 +1006,66 @@ angularjs_chain: {
         }
     }
 }
+
+issue_3490_1: {
+    options = {
+        conditionals: true,
+        dead_code: true,
+        inline: true,
+        sequences: true,
+        side_effects: true,
+        toplevel: true,
+    }
+    input: {
+        var b = 42, c = "FAIL";
+        if ({
+            3: function() {
+                var a;
+                return (a && a.p) < this;
+            }(),
+        }) c = "PASS";
+        if (b) while ("" == typeof d);
+        console.log(c, b);
+    }
+    expect: {
+        var b = 42, c = "FAIL";
+        if (function() {
+            var a;
+            a && a.p;
+        }(), c = "PASS", b) while ("" == typeof d);
+        console.log(c, b);
+    }
+    expect_stdout: "PASS 42"
+}
+
+issue_3490_2: {
+    options = {
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        toplevel: true,
+    }
+    input: {
+        var b = 42, c = "FAIL";
+        if ({
+            3: function() {
+                var a;
+                return (a && a.p) < this;
+            }(),
+        }) c = "PASS";
+        if (b) for (; "" == typeof d;);
+        console.log(c, b);
+    }
+    expect: {
+        var b = 42, c = "FAIL";
+        for (function() {
+            var a;
+        }(), c = "PASS", b; "" == typeof d;);
+        console.log(c, b);
+    }
+    expect_stdout: "PASS 42"
+}