fix corner case in `inline` (#4223)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 15 Oct 2020 13:52:40 +0000 (14:52 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Oct 2020 13:52:40 +0000 (21:52 +0800)
fixes #4222

lib/compress.js
test/compress/const.js

index e66331d..504bf39 100644 (file)
@@ -7041,7 +7041,7 @@ merge(Compressor.prototype, {
                     && fn.is_constant_expression(find_scope(compressor)))
                 && (value = can_flatten_body(stat))
                 && !fn.contains_this()) {
-                var replacing = exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1;
+                var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1;
                 if (can_substitute_directly()) {
                     var args = self.args.slice();
                     var refs = [];
index cd951ff..ef5c967 100644 (file)
@@ -1104,3 +1104,33 @@ issue_4220: {
     }
     expect_stdout: true
 }
+
+issue_4222: {
+    options = {
+        inline: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        {
+            const a = function() {
+                return function() {};
+            };
+            var b = a();
+        }
+        b();
+        console.log(typeof a);
+    }
+    expect: {
+        {
+            const a = function() {
+                return function() {};
+            };
+            var b = a();
+        }
+        b();
+        console.log(typeof a);
+    }
+    expect_stdout: true
+}