[Pkg-javascript-commits] [uglifyjs] 152/228: fix `cascade` on `delete` operator (#1687)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:25 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 e76fb354eb62d8e7b6968f1f77cfbb219814cea3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Mar 26 18:08:44 2017 +0800

    fix `cascade` on `delete` operator (#1687)
    
    Conditions including strict mode would make `delete` return `true` or `false`, and are too complex to be evaluated by the compressor.
    
    Suppress assignment folding into said operator.
    
    fixes #1685
---
 lib/compress.js            |  6 ++++--
 test/compress/sequences.js | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 8467f96..a617adb 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2542,7 +2542,6 @@ merge(Compressor.prototype, {
                         continue;
                     }
                 }
-                var case_side_effects = branch instanceof AST_Case && branch.expression.has_side_effects(compressor);
                 if (aborts(branch)) {
                     var block = make_node(AST_BlockStatement, branch, branch).print_to_string();
                     if (!fallthrough && prev_block === block) body[body.length - 1].body = [];
@@ -2946,7 +2945,10 @@ merge(Compressor.prototype, {
                             field = "left";
                         }
                     } else if (cdr instanceof AST_Call
-                        || cdr instanceof AST_Unary && cdr.operator != "++" && cdr.operator != "--") {
+                        || cdr instanceof AST_Unary
+                            && cdr.operator != "delete"
+                            && cdr.operator != "++"
+                            && cdr.operator != "--") {
                         field = "expression";
                     } else break;
                     parent = cdr;
diff --git a/test/compress/sequences.js b/test/compress/sequences.js
index 49b61ae..af6e0c3 100644
--- a/test/compress/sequences.js
+++ b/test/compress/sequences.js
@@ -306,3 +306,27 @@ unsafe_undefined: {
         }
     }
 }
+
+issue_1685: {
+    options = {
+        cascade: true,
+        side_effects: true,
+    }
+    input: {
+        var a = 100, b = 10;
+        function f() {
+            var a = (a--, delete a && --b);
+        }
+        f();
+        console.log(a, b);
+    }
+    expect: {
+        var a = 100, b = 10;
+        function f() {
+            var a = (a--, delete a && --b);
+        }
+        f();
+        console.log(a, b);
+    }
+    expect_stdout: 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