fix corner case in `keep_fargs` & `reduce_vars` (#4354)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 8 Dec 2020 17:41:10 +0000 (17:41 +0000)
committerGitHub <noreply@github.com>
Tue, 8 Dec 2020 17:41:10 +0000 (01:41 +0800)
fixes #4353

lib/compress.js
test/compress/keep_fargs.js

index 144a533..4da1375 100644 (file)
@@ -904,6 +904,7 @@ merge(Compressor.prototype, {
                 reset_variables(tw, compressor, fn);
                 descend();
                 pop(tw);
+                if (fn.name) mark_escaped(tw, fn.name.definition(), fn, fn.name, fn, 0, 1);
                 walk_defuns(tw, fn);
             }
             return true;
index 7141a41..8d6c5c9 100644 (file)
@@ -1452,3 +1452,37 @@ issue_3619: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4353_1: {
+    options = {
+        keep_fargs: "strict",
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function f(a) {}.length);
+    }
+    expect: {
+        console.log(function(a) {}.length);
+    }
+    expect_stdout: "1"
+}
+
+issue_4353_2: {
+    options = {
+        keep_fargs: "strict",
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function f(a) {
+            while (console.log("PASS"));
+        })();
+    }
+    expect: {
+        (function() {
+            while (console.log("PASS"));
+        })();
+    }
+    expect_stdout: "PASS"
+}