fix corner case in `inline` (#5238)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 25 Dec 2021 11:30:49 +0000 (19:30 +0800)
committerGitHub <noreply@github.com>
Sat, 25 Dec 2021 11:30:49 +0000 (19:30 +0800)
fixes #5237

lib/compress.js
test/compress/functions.js

index 46b59b9..da9034f 100644 (file)
@@ -12818,7 +12818,6 @@ Compressor.prototype.compress = function(node) {
                     left: make_node(AST_Number, node, { value: 0 }),
                     right: make_node(AST_Number, node, { value: 0 }),
                 });
-                if (node instanceof AST_Scope && node !== scope) return node;
             }));
             var body = [];
             if (fn.rest || !all(fn.argnames, function(argname) {
index 0273519..c31d282 100644 (file)
@@ -7103,3 +7103,35 @@ issue_5230: {
     }
     expect_stdout: "42"
 }
+
+issue_5237: {
+    options = {
+        evaluate: true,
+        inline: true,
+    }
+    input: {
+        function f() {
+            (function() {
+                while (console.log(0/0));
+            })();
+            (function() {
+                var NaN = console && console.log(NaN);
+            })();
+        }
+        f();
+    }
+    expect: {
+        function f() {
+            (function() {
+                while (console.log(0/0));
+            })();
+            var NaN = console && console.log(NaN);
+            return;
+        }
+        f();
+    }
+    expect_stdout: [
+        "NaN",
+        "undefined",
+    ]
+}