[Pkg-javascript-commits] [uglifyjs] 477/491: account for exceptions in `AST_Assign.left` (#2892)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:06 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 d66d86f20bc231bd8d305ee5ba05efa77aa8b6be
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Feb 8 03:31:51 2018 +0800

    account for exceptions in `AST_Assign.left` (#2892)
    
    fixes #2891
---
 lib/compress.js                |  9 +++++--
 test/compress/collapse_vars.js | 56 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 142728c..dc453f1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2758,8 +2758,13 @@ merge(Compressor.prototype, {
             return any(this.elements, compressor);
         });
         def(AST_Assign, function(compressor){
-            return this.operator != "=" && this.left.may_throw(compressor)
-                || this.right.may_throw(compressor);
+            if (this.right.may_throw(compressor)) return true;
+            if (!compressor.has_directive("use strict")
+                && this.operator == "="
+                && this.left instanceof AST_SymbolRef) {
+                return false;
+            }
+            return this.left.may_throw(compressor);
         });
         def(AST_Binary, function(compressor){
             return this.left.may_throw(compressor)
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 19db605..ed1d8d9 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4461,3 +4461,59 @@ issue_2878: {
     }
     expect_stdout: "1"
 }
+
+issue_2891_1: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        var a = "PASS", b;
+        try {
+            b = c.p = 0;
+            a = "FAIL";
+            b();
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS", b;
+        try {
+            b = c.p = 0;
+            a = "FAIL";
+            b();
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2891_2: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        "use strict";
+        var a = "PASS", b;
+        try {
+            b = c = 0;
+            a = "FAIL";
+            b();
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    expect: {
+        "use strict";
+        var a = "PASS", b;
+        try {
+            b = c = 0;
+            a = "FAIL";
+            b();
+        } catch (e) {
+        }
+        console.log(a);
+    }
+    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