[Pkg-javascript-commits] [uglifyjs] 244/491: deduplicate declarations regardless of `toplevel` (#2393)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:40 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 8a713e449f551d89745d9a8105b7cb33e9893214
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Oct 23 01:00:50 2017 +0800

    deduplicate declarations regardless of `toplevel` (#2393)
---
 lib/compress.js                | 8 ++++----
 test/compress/collapse_vars.js | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index eb0e201..7085fcb 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2240,7 +2240,6 @@ merge(Compressor.prototype, {
         if (self.uses_eval || self.uses_with) return;
         var drop_funcs = !(self instanceof AST_Toplevel) || compressor.toplevel.funcs;
         var drop_vars = !(self instanceof AST_Toplevel) || compressor.toplevel.vars;
-        if (!drop_funcs && !drop_vars) return;
         var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node) {
             if (node instanceof AST_Assign && (node.write_only || node.operator == "=")) {
                 return node.left;
@@ -2375,7 +2374,8 @@ merge(Compressor.prototype, {
                     }
                     return node;
                 }
-                if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn && tt.parent().init === node)) {
+                var parent = tt.parent();
+                if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) {
                     // place uninitialized names at the start
                     var body = [], head = [], tail = [];
                     // for unused names whose initialization has
@@ -2385,7 +2385,7 @@ merge(Compressor.prototype, {
                     node.definitions.forEach(function(def) {
                         if (def.value) def.value = def.value.transform(tt);
                         var sym = def.name.definition();
-                        if (sym.id in in_use_ids) {
+                        if (!drop_vars || sym.id in in_use_ids) {
                             if (def.name instanceof AST_SymbolVar) {
                                 var var_defs = var_defs_by_id.get(sym.id);
                                 if (var_defs.length > 1 && !def.value) {
@@ -2467,7 +2467,7 @@ merge(Compressor.prototype, {
                         && !((def = def.definition()).id in in_use_ids)
                         && self.variables.get(def.name) === def) {
                         if (node instanceof AST_Assign) {
-                            return maintain_this_binding(tt.parent(), node, node.right.transform(tt));
+                            return maintain_this_binding(parent, node, node.right.transform(tt));
                         }
                         return make_node(AST_Number, node, {
                             value: 0
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 1f702ad..b5b97d2 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2051,7 +2051,7 @@ inner_lvalues: {
         console.log(null, a, b);
     }
     expect: {
-        var a, b = 10;
+        var b = 10;
         var a = (--b || a || 3).toString(), c = --b + -a;
         console.log(null, a, b);
     }

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