[Pkg-javascript-commits] [uglifyjs] 60/228: trim unused invocation parameters (#1526)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 9699ffb1afc8bead9fbc3643c6b90b14169ef02c
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Mar 2 11:33:59 2017 +0800

    trim unused invocation parameters (#1526)
---
 lib/compress.js           | 14 ++++++++++++++
 test/compress/evaluate.js | 23 +++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 1d4e719..ddf2b10 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2481,6 +2481,20 @@ merge(Compressor.prototype, {
     });
 
     OPT(AST_Call, function(self, compressor){
+        if (compressor.option("unused")
+            && self.expression instanceof AST_Function
+            && !self.expression.uses_arguments
+            && !self.expression.uses_eval
+            && self.args.length > self.expression.argnames.length) {
+            var end = self.expression.argnames.length;
+            for (var i = end, len = self.args.length; i < len; i++) {
+                var node = self.args[i].drop_side_effect_free(compressor);
+                if (node) {
+                    self.args[end++] = node;
+                }
+            }
+            self.args.length = end;
+        }
         if (compressor.option("unsafe")) {
             var exp = self.expression;
             if (exp instanceof AST_SymbolRef && exp.undeclared()) {
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index f84436d..26b6e48 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -646,6 +646,29 @@ call_args: {
     }
 }
 
+call_args_drop_param: {
+    options = {
+        evaluate: true,
+        keep_fargs: false,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        const a = 1;
+        console.log(a);
+        +function(a) {
+            return a;
+        }(a, b);
+    }
+    expect: {
+        const a = 1;
+        console.log(1);
+        +function() {
+            return 1;
+        }(b);
+    }
+}
+
 in_boolean_context: {
     options = {
         booleans: true,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list