[Pkg-javascript-commits] [uglifyjs] 384/491: enhance `collapse_vars` (#2704)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:55 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 6dead95eb3e2566f157b9d776803ea8b7168356d
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Jan 2 18:42:15 2018 +0800

    enhance `collapse_vars` (#2704)
---
 lib/compress.js            | 19 ++++++++++++++-----
 test/compress/functions.js |  4 ++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 5da07f7..3221268 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1159,10 +1159,10 @@ merge(Compressor.prototype, {
                     if (!expr.left.has_side_effects(compressor)) {
                         candidates.push(hit_stack.slice());
                     }
-                } else if (expr instanceof AST_Unary) {
-                    if (expr.operator == "++" || expr.operator == "--") {
-                        candidates.push(hit_stack.slice());
-                    }
+                    extract_candidates(expr.right);
+                } else if (expr instanceof AST_Binary) {
+                    extract_candidates(expr.left);
+                    extract_candidates(expr.right);
                 } else if (expr instanceof AST_Call) {
                     extract_candidates(expr.expression);
                     expr.args.forEach(extract_candidates);
@@ -1187,14 +1187,22 @@ merge(Compressor.prototype, {
                 } else if (expr instanceof AST_Switch) {
                     extract_candidates(expr.expression);
                     expr.body.forEach(extract_candidates);
+                } else if (expr instanceof AST_Unary) {
+                    if (expr.operator == "++" || expr.operator == "--") {
+                        candidates.push(hit_stack.slice());
+                    }
                 } else if (expr instanceof AST_VarDef) {
-                    if (expr.value) candidates.push(hit_stack.slice());
+                    if (expr.value) {
+                        candidates.push(hit_stack.slice());
+                        extract_candidates(expr.value);
+                    }
                 }
                 hit_stack.pop();
             }
 
             function find_stop(node, level) {
                 var parent = scanner.parent(level);
+                if (parent instanceof AST_Binary) return node;
                 if (parent instanceof AST_Call) return node;
                 if (parent instanceof AST_Case) return node;
                 if (parent instanceof AST_Conditional) return node;
@@ -1202,6 +1210,7 @@ merge(Compressor.prototype, {
                 if (parent instanceof AST_If) return node;
                 if (parent instanceof AST_Sequence) return find_stop(parent, level + 1);
                 if (parent instanceof AST_Switch) return node;
+                if (parent instanceof AST_VarDef) return node;
                 return null;
             }
 
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 7acb7fd..dd98ba6 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -1285,7 +1285,7 @@ issue_2630_1: {
     expect: {
         var c = 0;
         (function() {
-            while (c++, void (c = 1 + c));
+            while (void (c = 1 + ++c));
         })(),
         console.log(c);
     }
@@ -1316,7 +1316,7 @@ issue_2630_2: {
     expect: {
         var c = 0;
         !function() {
-            while (c += 1, void (c = 1 + c));
+            while (void (c = 1 + (c += 1)));
         }(), console.log(c);
     }
     expect_stdout: "2"

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