fix corner case in `inline` (#4472)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 28 Dec 2020 02:05:59 +0000 (02:05 +0000)
committerGitHub <noreply@github.com>
Mon, 28 Dec 2020 02:05:59 +0000 (10:05 +0800)
fixes #4471

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

index 58e0d78..c556c49 100644 (file)
@@ -8039,7 +8039,11 @@ merge(Compressor.prototype, {
                         refs.forEach(function(ref) {
                             var def = ref.definition();
                             def.references.push(ref);
-                            if (replacing) def.replaced++;
+                            if (replacing) {
+                                def.replaced++;
+                            } else {
+                                def.single_use = false;
+                            }
                         });
                         return node;
                     }
index 066bc3c..af99467 100644 (file)
@@ -5249,3 +5249,37 @@ issue_4451: {
     }
     expect_stdout: "function"
 }
+
+issue_4471: {
+    options = {
+        inline: true,
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        f(f());
+        function f() {
+            return g();
+        }
+        function g() {
+            {
+                console.log("PASS");
+            }
+        }
+    }
+    expect: {
+        f(g());
+        function f() {
+            return g();
+        }
+        function g() {
+            console.log("PASS");
+        }
+    }
+    expect_stdout: [
+        "PASS",
+        "PASS",
+    ]
+}