[Pkg-javascript-commits] [uglifyjs] 105/228: disallow parameter substitution for named IIFEs (#1596)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:21 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 d9344f30b83ecdfc8310ff43b9361c67cc85ec3e
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Mar 11 03:34:55 2017 +0800

    disallow parameter substitution for named IIFEs (#1596)
    
    Self-referenced function has non-fixed values assigned to its parameters.
    
    Let `unused` & `!keep_fnames` do the scanning, then apply `reduce_vars` only to unnamed functions.
    
    fixes #1595
---
 lib/compress.js              |  1 +
 test/compress/reduce_vars.js | 75 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 3964636..7302f5b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -279,6 +279,7 @@ merge(Compressor.prototype, {
                 }
                 var iife;
                 if (node instanceof AST_Function
+                    && !node.name
                     && (iife = tw.parent()) instanceof AST_Call
                     && iife.expression === node) {
                     // Virtually turn IIFE parameters into variable definitions:
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 734ce4e..a5ab59f 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1252,3 +1252,78 @@ iife_func_side_effects: {
         })(x(), 0, z());
     }
 }
+
+issue_1595_1: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function f(a) {
+            return f(a + 1);
+        })(2);
+    }
+    expect: {
+        (function f(a) {
+            return f(a + 1);
+        })(2);
+    }
+}
+
+issue_1595_2: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function f(a) {
+            return g(a + 1);
+        })(2);
+    }
+    expect: {
+        (function(a) {
+            return g(a + 1);
+        })(2);
+    }
+}
+
+issue_1595_3: {
+    options = {
+        evaluate: true,
+        passes: 2,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function f(a) {
+            return g(a + 1);
+        })(2);
+    }
+    expect: {
+        (function(a) {
+            return g(3);
+        })();
+    }
+}
+
+issue_1595_4: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function iife(a, b, c) {
+            console.log(a, b, c);
+            if (a) iife(a - 1, b, c);
+        })(3, 4, 5);
+    }
+    expect: {
+        (function iife(a, b, c) {
+            console.log(a, b, c);
+            if (a) iife(a - 1, b, c);
+        })(3, 4, 5);
+    }
+}

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