fix corner cases in `sequences` (#4690)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 25 Feb 2021 04:48:40 +0000 (04:48 +0000)
committerGitHub <noreply@github.com>
Thu, 25 Feb 2021 04:48:40 +0000 (12:48 +0800)
fixes #4689

lib/compress.js
test/compress/const.js
test/compress/let.js

index 2b28c75..08b0987 100644 (file)
@@ -3118,7 +3118,7 @@ merge(Compressor.prototype, {
                             }
                         }
                     } else if (stat instanceof AST_ForIn) {
-                        stat.object = cons_seq(stat.object);
+                        if (!is_lexical_definition(stat.init)) stat.object = cons_seq(stat.object);
                     } else if (stat instanceof AST_If) {
                         stat.condition = cons_seq(stat.condition);
                     } else if (stat instanceof AST_Switch) {
index 38cd8fb..be49e84 100644 (file)
@@ -1434,3 +1434,23 @@ issue_4527: {
     }
     expect_stdout: "aaaa"
 }
+
+issue_4689: {
+    options = {
+        sequences: true,
+    }
+    input: {
+        "use strict";
+        var a = "PASS";
+        console.log(a);
+        for (const a in 42);
+    }
+    expect: {
+        "use strict";
+        var a = "PASS";
+        console.log(a);
+        for (const a in 42);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}
index 7a9db16..b5005eb 100644 (file)
@@ -1319,7 +1319,6 @@ issue_4531_2: {
         toplevel: true,
     }
     input: {
-        "use strict";
         var a = console;
         console.log(typeof a, function a() {
             let { [console]: a } = 0 && a;
@@ -1328,7 +1327,6 @@ issue_4531_2: {
         }());
     }
     expect: {
-        "use strict";
         var o = console;
         console.log(typeof o, function o() {
             let { [console]: o } = 0;
@@ -1339,3 +1337,23 @@ issue_4531_2: {
     expect_stdout: "object undefined"
     node_version: ">=6"
 }
+
+issue_4689: {
+    options = {
+        sequences: true,
+    }
+    input: {
+        "use strict";
+        var a = "PASS";
+        console.log(a);
+        for (let a in 42);
+    }
+    expect: {
+        "use strict";
+        var a = "PASS";
+        console.log(a);
+        for (let a in 42);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}