[Pkg-javascript-commits] [uglifyjs] 404/491: fix recursive function `inline` (#2738)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:57 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 1ee8be8d91dd94a983e853b7abcc64d6dbc6214b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Jan 7 15:31:24 2018 +0800

    fix recursive function `inline` (#2738)
    
    fixes #2737
---
 lib/compress.js            |  5 +++--
 test/compress/functions.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 28d6a1c..011bb1b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4075,9 +4075,10 @@ merge(Compressor.prototype, {
             if (compressor.option("inline")
                 && !fn.uses_arguments
                 && !fn.uses_eval
+                && !(fn.name && fn instanceof AST_Function)
                 && (value = can_flatten_body(stat))
-                && (exp === fn ? !fn.name
-                    : compressor.option("unused")
+                && (exp === fn
+                    || compressor.option("unused")
                         && (def = exp.definition()).references.length == 1
                         && !recursive_ref(compressor, def)
                         && fn.is_constant_expression(exp.scope))
diff --git a/test/compress/functions.js b/test/compress/functions.js
index f466208..222aa0c 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -1905,3 +1905,49 @@ duplicate_arg_var: {
     }
     expect_stdout: "PASS"
 }
+
+issue_2737_1: {
+    options = {
+        inline: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function(a) {
+            while (a());
+        })(function f() {
+            console.log(typeof f);
+        });
+    }
+    expect: {
+        (function(a) {
+            while (a());
+        })(function f() {
+            console.log(typeof f);
+        });
+    }
+    expect_stdout: "function"
+}
+
+issue_2737_2: {
+    options = {
+        inline: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function(bar) {
+            for (;bar(); ) break;
+        })(function qux() {
+            return console.log("PASS"), qux;
+        });
+    }
+    expect: {
+        (function(bar) {
+            for (;bar(); ) break;
+        })(function qux() {
+            return console.log("PASS"), qux;
+        });
+    }
+    expect_stdout: "PASS"
+}

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