[Pkg-javascript-commits] [uglifyjs] 175/228: speed up IIFE elimination (#1728)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:28 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 beb9659778b04e46556b58bd1d093f3938be9dce
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Mar 29 23:27:35 2017 +0800

    speed up IIFE elimination (#1728)
    
    - `side_effects` will clean up inner statements, so checking for an empty function body should suffice
    - drop side effects when dropping `return` from statement
---
 lib/compress.js | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 786fc56..e36ff89 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -199,7 +199,7 @@ merge(Compressor.prototype, {
         return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string();
     });
 
-    AST_Node.DEFMETHOD("process_expression", function(insert) {
+    AST_Node.DEFMETHOD("process_expression", function(insert, compressor) {
         var self = this;
         var tt = new TreeTransformer(function(node) {
             if (insert && node instanceof AST_SimpleStatement) {
@@ -208,6 +208,12 @@ merge(Compressor.prototype, {
                 });
             }
             if (!insert && node instanceof AST_Return) {
+                if (compressor) {
+                    var value = node.value && node.value.drop_side_effect_free(compressor, true);
+                    return value ? make_node(AST_SimpleStatement, node, {
+                        body: value
+                    }) : make_node(AST_EmptyStatement, node);
+                }
                 return make_node(AST_SimpleStatement, node, {
                     body: node.value || make_node(AST_Undefined, node)
                 });
@@ -2153,7 +2159,7 @@ merge(Compressor.prototype, {
                 if (this.expression instanceof AST_Function
                     && (!this.expression.name || !this.expression.name.definition().references.length)) {
                     var node = this.clone();
-                    node.expression = node.expression.process_expression(false);
+                    node.expression = node.expression.process_expression(false, compressor);
                     return node;
                 }
                 return this;
@@ -2866,11 +2872,9 @@ merge(Compressor.prototype, {
                     return AST_Seq.from_array(args).transform(compressor);
                 }
             }
-            if (compressor.option("side_effects")) {
-                if (!AST_Block.prototype.has_side_effects.call(exp, compressor)) {
-                    var args = self.args.concat(make_node(AST_Undefined, self));
-                    return AST_Seq.from_array(args).transform(compressor);
-                }
+            if (compressor.option("side_effects") && all(exp.body, is_empty)) {
+                var args = self.args.concat(make_node(AST_Undefined, self));
+                return AST_Seq.from_array(args).transform(compressor);
             }
         }
         if (compressor.option("drop_console")) {

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