[Pkg-javascript-commits] [uglifyjs] 108/228: minor clean-ups (#1600)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:21 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 381bd3836ecd79eb5d4f7b84807c778ee1acf9c9
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Mar 14 13:19:05 2017 +0800

    minor clean-ups (#1600)
    
    - remove obsolete optimisation in `AST_Binary` after #1477
    - improve `TreeWalker.has_directive()` readability and resilience against multiple visits
---
 lib/ast.js      |  6 +++---
 lib/compress.js | 12 +-----------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/lib/ast.js b/lib/ast.js
index f7ab52e..092a959 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -984,8 +984,8 @@ TreeWalker.prototype = {
     push: function (node) {
         if (node instanceof AST_Lambda) {
             this.directives = Object.create(this.directives);
-        } else if (node instanceof AST_Directive) {
-            this.directives[node.value] = this.directives[node.value] ? "up" : true;
+        } else if (node instanceof AST_Directive && !this.directives[node.value]) {
+            this.directives[node.value] = node;
         }
         this.stack.push(node);
     },
@@ -1013,7 +1013,7 @@ TreeWalker.prototype = {
             for (var i = 0; i < node.body.length; ++i) {
                 var st = node.body[i];
                 if (!(st instanceof AST_Directive)) break;
-                if (st.value == type) return true;
+                if (st.value == type) return st;
             }
         }
     },
diff --git a/lib/compress.js b/lib/compress.js
index e3ae5bd..ab4c3c2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1664,7 +1664,7 @@ merge(Compressor.prototype, {
     /* -----[ optimizers ]----- */
 
     OPT(AST_Directive, function(self, compressor){
-        if (compressor.has_directive(self.value) === "up") {
+        if (compressor.has_directive(self.value) !== self) {
             return make_node(AST_EmptyStatement, self);
         }
         return self;
@@ -3018,16 +3018,6 @@ merge(Compressor.prototype, {
     var commutativeOperators = makePredicate("== === != !== * & | ^");
 
     OPT(AST_Binary, function(self, compressor){
-        var lhs = self.left.evaluate(compressor);
-        var rhs = self.right.evaluate(compressor);
-        if (lhs.length > 1 && lhs[0].is_constant() !== self.left.is_constant()
-            || rhs.length > 1 && rhs[0].is_constant() !== self.right.is_constant()) {
-            return make_node(AST_Binary, self, {
-                operator: self.operator,
-                left: lhs[0],
-                right: rhs[0]
-            }).optimize(compressor);
-        }
         function reversible() {
             return self.left instanceof AST_Constant
                 || self.right instanceof AST_Constant

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