[Pkg-javascript-commits] [uglifyjs] 23/49: Fix negate_iife transform to return a correct tree for nested IIFEs

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:26 UTC 2016


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

js pushed a commit to branch master
in repository uglifyjs.

commit 8430123e9d2d12442312bbdcdf54004dc6d29c12
Author: Richard van Velzen <rvanvelzen at experty.com>
Date:   Wed Aug 17 11:43:50 2016 +0200

    Fix negate_iife transform to return a correct tree for nested IIFEs
    
    Fix for #1256, partially reverts d854523783b4
---
 lib/compress.js              |  9 ++++++++-
 lib/output.js                |  2 --
 test/compress/negate-iife.js | 14 ++++++++++++++
 test/compress/new.js         |  7 +++++++
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index fd839fa..f8d9d32 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -831,6 +831,13 @@ merge(Compressor.prototype, {
         };
 
         function negate_iifes(statements, compressor) {
+            function is_iife_call(node) {
+                if (node instanceof AST_Call) {
+                    return node.expression instanceof AST_Function || is_iife_call(node.expression);
+                }
+                return false;
+            }
+
             statements.forEach(function(stat){
                 if (stat instanceof AST_SimpleStatement) {
                     stat.body = (function transform(thing) {
@@ -838,7 +845,7 @@ merge(Compressor.prototype, {
                             if (node instanceof AST_New) {
                                 return node;
                             }
-                            if (node instanceof AST_Call && node.expression instanceof AST_Function) {
+                            if (is_iife_call(node)) {
                                 return make_node(AST_UnaryPrefix, node, {
                                     operator: "!",
                                     expression: node
diff --git a/lib/output.js b/lib/output.js
index f1e0c2f..801f751 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -531,8 +531,6 @@ function OutputStream(options) {
     });
 
     PARENS([ AST_Unary, AST_Undefined ], function(output){
-        if (this.expression instanceof AST_Call)
-            return false;
         var p = output.parent();
         return p instanceof AST_PropAccess && p.expression === this
             || p instanceof AST_Call && p.expression === this;
diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js
index aa95d95..0c11160 100644
--- a/test/compress/negate-iife.js
+++ b/test/compress/negate-iife.js
@@ -158,3 +158,17 @@ issue_1254_negate_iife_true: {
     }
     expect_exact: '!function(){return function(){console.log("test")}}()();'
 }
+
+issue_1254_negate_iife_nested: {
+    options = {
+        negate_iife: true,
+    }
+    input: {
+        (function() {
+            return function() {
+                console.log('test')
+            };
+        })()()()()();
+    }
+    expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
+}
diff --git a/test/compress/new.js b/test/compress/new.js
index bdf22b0..83da88e 100644
--- a/test/compress/new.js
+++ b/test/compress/new.js
@@ -75,3 +75,10 @@ call_with_unary_arguments: {
     }
     expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);"
 }
+
+new_with_unary_prefix: {
+    input: {
+        var bar = (+new Date()).toString(32);
+    }
+    expect_exact: 'var bar=(+new Date).toString(32);';
+}

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