[Pkg-javascript-commits] [uglifyjs] 334/491: fix `reduce_vars` on single `AST_Defun` reference across loop (#2593)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:50 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 3f18a61532a86f0f52edbb50ca7d81e0869ad7c3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Dec 14 18:47:05 2017 +0800

    fix `reduce_vars` on single `AST_Defun` reference across loop (#2593)
---
 lib/compress.js              |  7 ++++++-
 test/compress/reduce_vars.js | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 4166909..96ed24a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -334,6 +334,11 @@ merge(Compressor.prototype, {
                 if (node instanceof AST_SymbolRef) {
                     var d = node.definition();
                     d.references.push(node);
+                    if (d.references.length == 1
+                        && !d.fixed
+                        && d.orig[0] instanceof AST_SymbolDefun) {
+                        loop_ids[d.id] = in_loop;
+                    }
                     var value;
                     if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") {
                         d.fixed = false;
@@ -402,9 +407,9 @@ merge(Compressor.prototype, {
                         d.fixed = false;
                     } else {
                         d.fixed = node;
+                        d.single_use = ref_once(d);
                         loop_ids[d.id] = in_loop;
                         mark(d, true);
-                        d.single_use = ref_once(d);
                     }
                     var save_ids = safe_ids;
                     safe_ids = Object.create(null);
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 108dc0e..ff93079 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -4838,3 +4838,31 @@ inverted_var: {
     }
     expect_stdout: true
 }
+
+defun_single_use_loop: {
+    options = {
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        for (var x, i = 2; --i >= 0; ) {
+            var y = x;
+            x = f;
+            console.log(x === y);
+        }
+        function f() {};
+    }
+    expect: {
+        for (var x, i = 2; --i >= 0; ) {
+            var y = x;
+            x = f;
+            console.log(x === y);
+        }
+        function f() {};
+    }
+    expect_stdout: [
+        "false",
+        "true",
+    ]
+}

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