improve `inline` of `/*@__PURE__*/` calls (#3865)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 9 May 2020 23:16:09 +0000 (00:16 +0100)
committerGitHub <noreply@github.com>
Sat, 9 May 2020 23:16:09 +0000 (07:16 +0800)
lib/ast.js
test/compress/pure_funcs.js

index 240ef16..31072a0 100644 (file)
@@ -745,7 +745,7 @@ function must_be_expressions(node, prop) {
     });
 }
 
-var AST_Call = DEFNODE("Call", "expression args", {
+var AST_Call = DEFNODE("Call", "expression args pure", {
     $documentation: "A function call expression",
     $propdoc: {
         expression: "[AST_Node] expression to invoke as function",
index 2ca21d0..15ddf09 100644 (file)
@@ -706,3 +706,79 @@ issue_3858: {
     }
     expect_stdout: "PASS"
 }
+
+inline_pure_call_1: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        keep_fargs: "strict",
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var f = function(a) {
+            return /*@__PURE__*/ function(b) {
+                console.log(b);
+            }(a);
+        };
+        f("PASS");
+    }
+    expect: {}
+}
+
+inline_pure_call_2: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        keep_fargs: "strict",
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var f = function(a) {
+            return /*@__PURE__*/ function(b) {
+                console.log(b);
+            }(a);
+        };
+        var a = f("PASS");
+    }
+    expect: {}
+}
+
+inline_pure_call_3: {
+    options = {
+        collapse_vars: true,
+        evaluate: true,
+        inline: true,
+        keep_fargs: "strict",
+        passes: 2,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var f = function(a) {
+            return /*@__PURE__*/ function(b) {
+                console.log(b);
+            }(a);
+        };
+        var a = f("PASS");
+        console.log(a);
+    }
+    expect: {
+        var a = function() {
+            console.log("PASS");
+        }();
+        console.log(a);
+    }
+    expect_stdout: [
+        "PASS",
+        "undefined",
+    ]
+}