[Pkg-javascript-commits] [uglifyjs] 468/491: handle `break` & `continue` in `collapse_vars` (#2875)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:05 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 7e13c0db4034d2c28e36473a3add915de1813844
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Feb 3 07:58:43 2018 +0800

    handle `break` & `continue` in `collapse_vars` (#2875)
    
    fixes #2873
---
 lib/compress.js                |  1 +
 test/compress/collapse_vars.js | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 6f9d64f..993092a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -968,6 +968,7 @@ merge(Compressor.prototype, {
                     || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
                     || node instanceof AST_Debugger
                     || node instanceof AST_IterationStatement && !(node instanceof AST_For)
+                    || node instanceof AST_LoopControl
                     || node instanceof AST_Try
                     || node instanceof AST_With
                     || parent instanceof AST_For && node !== parent.init
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index a2571c2..ad09edc 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4383,3 +4383,53 @@ cond_branch_switch: {
     }
     expect_stdout: "1"
 }
+
+issue_2873_1: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var b = 1, c = 0;
+        do {
+            c++;
+            if (!--b) break;
+            c = 1 + c;
+        } while (0);
+        console.log(b, c);
+    }
+    expect: {
+        var b = 1, c = 0;
+        do {
+            c++;
+            if (!--b) break;
+            c = 1 + c;
+        } while (0);
+        console.log(b, c);
+    }
+    expect_stdout: "0 1"
+}
+
+issue_2873_2: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var b = 1, c = 0;
+        do {
+            c++;
+            if (!--b) continue;
+            c = 1 + c;
+        } while (0);
+        console.log(b, c);
+    }
+    expect: {
+        var b = 1, c = 0;
+        do {
+            c++;
+            if (!--b) continue;
+            c = 1 + c;
+        } while (0);
+        console.log(b, c);
+    }
+    expect_stdout: "0 1"
+}

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