fix corner case in `if_return` (#4439)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 23 Dec 2020 20:08:57 +0000 (20:08 +0000)
committerGitHub <noreply@github.com>
Wed, 23 Dec 2020 20:08:57 +0000 (04:08 +0800)
fixes #4438

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

index 3834232..c397a60 100644 (file)
@@ -2669,7 +2669,7 @@ merge(Compressor.prototype, {
                     block = last.body;
                 }
                 block.pop();
-                if (ab.value) body.push(make_node(AST_SimpleStatement, ab.value, {
+                if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, {
                     body: ab.value.expression
                 }));
                 return body;
index fc32332..59b8902 100644 (file)
@@ -1228,3 +1228,35 @@ issue_1753_toplevel: {
     expect_stdout: "0"
     node_version: ">=4"
 }
+
+issue_4438: {
+    options = {
+        if_return: true,
+    }
+    input: {
+        "use strict";
+        function f() {
+            if (console) {
+                {
+                    let a = console.log;
+                    return void a("PASS");
+                }
+            }
+        }
+        f();
+    }
+    expect: {
+        "use strict";
+        function f() {
+            if (!console)
+                ;
+            else {
+                let a = console.log;
+                a("PASS");
+            }
+        }
+        f();
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}