[Pkg-javascript-commits] [uglifyjs] 168/228: fix corner case in `unused` (#1718)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:27 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 eb48a035e7880e73e7fe4f23727775cff365ffbc
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Mar 29 01:00:21 2017 +0800

    fix corner case in `unused` (#1718)
    
    When fixing catch-related issue in #1715, it tries to optimise for duplicate definitions but did not take anonymous functions into account.
    
    Remove such optimisation for now and we can cover this as a more general rule later.
---
 lib/compress.js              |  3 +--
 test/compress/drop-unused.js | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 64c654d..3c0fc45 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1896,8 +1896,7 @@ merge(Compressor.prototype, {
                             if (def.value) def.value = def.value.transform(tt);
                             var sym = def.name.definition();
                             if (sym.id in in_use_ids) return true;
-                            if (sym.orig[0] instanceof AST_SymbolCatch
-                                && sym.scope.parent_scope.find_variable(def.name).orig[0] === def.name) {
+                            if (sym.orig[0] instanceof AST_SymbolCatch) {
                                 def.value = def.value && def.value.drop_side_effect_free(compressor);
                                 return true;
                             }
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index aa875ec..d0b8776 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -931,3 +931,30 @@ issue_1715_3: {
     }
     expect_stdout: "1"
 }
+
+issue_1715_4: {
+    options = {
+        unused: true,
+    }
+    input: {
+        var a = 1;
+        !function a() {
+            a++;
+            try {} catch (a) {
+                var a;
+            }
+        }();
+        console.log(a);
+    }
+    expect: {
+        var a = 1;
+        !function() {
+            a++;
+            try {} catch (a) {
+                var a;
+            }
+        }();
+        console.log(a);
+    }
+    expect_stdout: "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