[Pkg-javascript-commits] [uglifyjs] 458/491: account for declaration assignment in `collapse_vars` (#2859)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:04 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 102f994b9d09b3ed0447f02a894fd88fcc903171
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Feb 1 15:09:53 2018 +0800

    account for declaration assignment in `collapse_vars` (#2859)
    
    fixes #2858
---
 lib/compress.js                |  1 +
 test/compress/collapse_vars.js | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index db6ee8b..9a3446c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -990,6 +990,7 @@ merge(Compressor.prototype, {
                     || node instanceof AST_Debugger
                     || node instanceof AST_IterationStatement && !(node instanceof AST_For)
                     || node instanceof AST_Try
+                    || node instanceof AST_VarDef && node.value && side_effects && !references_in_scope(node.name.definition())
                     || node instanceof AST_With
                     || parent instanceof AST_For && node !== parent.init
                     || (side_effects || !replace_all)
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index b361781..f56face 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4190,3 +4190,37 @@ return_3: {
     }
     expect_stdout: "0"
 }
+
+issue_2858: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var b;
+        (function() {
+            function f() {
+                a++;
+            }
+            f();
+            var c = f();
+            var a = void 0;
+            c || (b = a);
+        })();
+        console.log(b);
+    }
+    expect: {
+        var b;
+        (function() {
+            function f() {
+                a++;
+            }
+            f();
+            var c = f();
+            var a = void 0;
+            c || (b = a);
+        })();
+        console.log(b);
+    }
+    expect_stdout: "undefined"
+}

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