fix corner case in `functions` (#3900)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 15 May 2020 10:03:56 +0000 (11:03 +0100)
committerGitHub <noreply@github.com>
Fri, 15 May 2020 10:03:56 +0000 (18:03 +0800)
fixes #3899

lib/compress.js
test/compress/drop-unused.js

index 36a04a7..986bed3 100644 (file)
@@ -4363,6 +4363,7 @@ merge(Compressor.prototype, {
                         } else if (compressor.option("functions")
                             && !compressor.option("ie8")
                             && var_defs.length == 1
+                            && sym.assignments == 0
                             && def.value === def.name.fixed_value()
                             && def.value instanceof AST_Function
                             && !(def.value.name && def.value.name.definition().assignments)
index ff230ae..e316697 100644 (file)
@@ -2527,7 +2527,40 @@ issue_3802_2: {
     }
     expect: {
         0;
-        function a() {};
+        var a = function() {};
+        console.log(typeof a);
+    }
+    expect_stdout: "function"
+}
+
+issue_3899: {
+    options = {
+        assignments: true,
+        evaluate: true,
+        functions: true,
+        inline: true,
+        join_vars: true,
+        passes: 2,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 0;
+        a = a + 1;
+        var a = function f(b) {
+            return function() {
+                return b;
+            };
+        }(2);
+        console.log(typeof a);
+    }
+    expect: {
+        ++a;
+        var a = function() {
+            return 2;
+        };
         console.log(typeof a);
     }
     expect_stdout: "function"