enhance `inline` (#4163)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 30 Sep 2020 13:03:28 +0000 (14:03 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Sep 2020 13:03:28 +0000 (21:03 +0800)
lib/compress.js
test/compress/functions.js

index 69394a3..dfe444a 100644 (file)
@@ -6831,7 +6831,7 @@ merge(Compressor.prototype, {
                         return arg;
                     })).optimize(compressor);
                     node = maintain_this_binding(compressor, compressor.parent(), compressor.self(), node);
-                    if (replacing || best_of(compressor, self, node) === node) {
+                    if (replacing || best_of_expression(node, self) === node) {
                         refs.forEach(function(ref) {
                             var def = ref.definition();
                             def.references.push(ref);
index 4d75346..0cd07dd 100644 (file)
@@ -4829,3 +4829,27 @@ issue_4159: {
     }
     expect_stdout: "42 42"
 }
+
+direct_inline: {
+    options = {
+        inline: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        function f(a, b) {
+            function g(c) {
+                return c >> 1;
+            }
+            return g(a) + g(b);
+        }
+        console.log(f(13, 31));
+    }
+    expect: {
+        function f(a, b) {
+            return (a >> 1) + (b >> 1);
+        }
+        console.log(f(13, 31));
+    }
+    expect_stdout: "21"
+}