[Pkg-javascript-commits] [uglifyjs] 312/491: eliminate noop calls more aggressively (#2559)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:48 UTC 2018


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

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit d21cb84696f47f5cba25c88527d5575b7954191a
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Dec 7 01:22:08 2017 +0800

    eliminate noop calls more aggressively (#2559)
---
 lib/compress.js            | 25 +++++++++++++------------
 test/compress/functions.js | 20 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 3f0414e..4195ab2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3460,11 +3460,11 @@ merge(Compressor.prototype, {
     OPT(AST_Call, function(self, compressor){
         var exp = self.expression;
         var fn = exp;
+        if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
+            fn = fn.fixed_value();
+        }
         if (compressor.option("unused")
-            && (fn instanceof AST_Function
-                || compressor.option("reduce_vars")
-                    && fn instanceof AST_SymbolRef
-                    && (fn = fn.fixed_value()) instanceof AST_Function)
+            && fn instanceof AST_Function
             && !fn.uses_arguments
             && !fn.uses_eval) {
             var pos = 0, last = 0;
@@ -3683,14 +3683,15 @@ merge(Compressor.prototype, {
                 return make_sequence(self, args).optimize(compressor);
             }
         }
-        if (exp instanceof AST_Function) {
+        if (fn instanceof AST_Function) {
             if (compressor.option("inline")
-                && !exp.name
-                && !exp.uses_arguments
-                && !exp.uses_eval
-                && exp.body.length == 1
-                && !exp.contains_this()
-                && all(exp.argnames, function(arg) {
+                && exp === fn
+                && !fn.name
+                && !fn.uses_arguments
+                && !fn.uses_eval
+                && fn.body.length == 1
+                && !fn.contains_this()
+                && all(fn.argnames, function(arg) {
                     return arg.__unused;
                 })
                 && !self.has_pure_annotation(compressor)) {
@@ -3708,7 +3709,7 @@ merge(Compressor.prototype, {
                     return make_sequence(self, args).optimize(compressor);
                 }
             }
-            if (compressor.option("side_effects") && all(exp.body, is_empty)) {
+            if (compressor.option("side_effects") && all(fn.body, is_empty)) {
                 var args = self.args.concat(make_node(AST_Undefined, self));
                 return make_sequence(self, args).optimize(compressor);
             }
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 7a336bb..15727fc 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -652,3 +652,23 @@ issue_2531_3: {
     }
     expect_stdout: "Greeting: Hello"
 }
+
+empty_body: {
+    options = {
+        reduce_vars: true,
+        side_effects: true,
+    }
+    input: {
+        function f() {
+            function noop() {}
+            noop();
+            return noop;
+        }
+    }
+    expect: {
+        function f() {
+            function noop() {}
+            return noop;
+        }
+    }
+}

-- 
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