fix corner case in `inline` (#5284)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 10 Jan 2022 07:43:26 +0000 (07:43 +0000)
committerGitHub <noreply@github.com>
Mon, 10 Jan 2022 07:43:26 +0000 (15:43 +0800)
fixes #5283

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

index f1c6e07..8c9e3f7 100644 (file)
@@ -12998,6 +12998,7 @@ Compressor.prototype.compress = function(node) {
                 });
                 scope = scope.parent_scope;
             }
+            if (!member(scope, compressor.stack)) return;
             if (scope instanceof AST_Toplevel && fn.variables.size() > (arrow ? 0 : 1)) {
                 if (!compressor.toplevel.vars) return;
                 if (fn.functions.size() > 0 && !compressor.toplevel.funcs) return;
index a196f79..31be259 100644 (file)
@@ -7977,3 +7977,40 @@ issue_5264_2: {
         "baz",
     ]
 }
+
+issue_5283: {
+    options = {
+        if_return: true,
+        inline: true,
+        pure_getters: "strict",
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        var a = "FAIL 1";
+        (function() {
+            (a = "PASS")[function() {
+                if (console)
+                    return null;
+                var b = function f(a) {
+                    console.log("FAIL 2");
+                    var c = a.p;
+                }();
+            }()];
+        })();
+        console.log(a);
+    }
+    expect: {
+        var a = "FAIL 1";
+        (function() {
+            a = "PASS";
+            if (!console)
+                (function(a) {
+                    console.log("FAIL 2");
+                    a.p;
+                })();
+        })();
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}