[Pkg-javascript-commits] [uglifyjs] 233/491: clean up lazy operator detection (#2373)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:39 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 c1346e06b70806995f3b75919d35bf5348ce88ed
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Oct 17 23:25:45 2017 +0800

    clean up lazy operator detection (#2373)
---
 lib/compress.js | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 488cc6f..3ab54f1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -404,8 +404,7 @@ merge(Compressor.prototype, {
                     pop();
                     return true;
                 }
-                if (node instanceof AST_Binary
-                    && (node.operator == "&&" || node.operator == "||")) {
+                if (node instanceof AST_Binary && lazy_op(node.operator)) {
                     node.left.walk(tw);
                     push();
                     node.right.walk(tw);
@@ -844,8 +843,7 @@ merge(Compressor.prototype, {
                                && (lvalues[node.name]
                                    || side_effects && !references_in_scope(node.definition()))
                             || (sym = lhs_or_def(node)) && get_symbol(sym).name in lvalues
-                            || parent instanceof AST_Binary
-                                && (parent.operator == "&&" || parent.operator == "||")
+                            || parent instanceof AST_Binary && lazy_op(parent.operator)
                             || parent instanceof AST_Case
                             || parent instanceof AST_Conditional
                             || parent instanceof AST_For
@@ -1434,9 +1432,10 @@ merge(Compressor.prototype, {
             return member(this.operator, unary_bool);
         });
         def(AST_Binary, function(){
-            return member(this.operator, binary_bool) ||
-                ( (this.operator == "&&" || this.operator == "||") &&
-                  this.left.is_boolean() && this.right.is_boolean() );
+            return member(this.operator, binary_bool)
+                || lazy_op(this.operator)
+                    && this.left.is_boolean()
+                    && this.right.is_boolean();
         });
         def(AST_Conditional, function(){
             return this.consequent.is_boolean() && this.alternative.is_boolean();
@@ -1505,6 +1504,7 @@ merge(Compressor.prototype, {
         node.DEFMETHOD("is_string", func);
     });
 
+    var lazy_op = makePredicate("&& ||");
     var unary_side_effects = makePredicate("delete ++ --");
 
     function is_lhs(node, parent) {
@@ -2701,14 +2701,12 @@ merge(Compressor.prototype, {
         def(AST_Binary, function(compressor, first_in_statement){
             var right = this.right.drop_side_effect_free(compressor);
             if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);
-            switch (this.operator) {
-              case "&&":
-              case "||":
+            if (lazy_op(this.operator)) {
                 if (right === this.right) return this;
                 var node = this.clone();
                 node.right = right;
                 return node;
-              default:
+            } else {
                 var left = this.left.drop_side_effect_free(compressor, first_in_statement);
                 if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement);
                 return make_sequence(this, [ left, right ]);
@@ -3574,7 +3572,7 @@ merge(Compressor.prototype, {
                     }
                     if (cdr instanceof AST_Binary && !(cdr instanceof AST_Assign)) {
                         if (cdr.left.is_constant()) {
-                            if (cdr.operator == "||" || cdr.operator == "&&") {
+                            if (lazy_op(cdr.operator)) {
                                 expressions[++i] = expressions[j];
                                 break;
                             }
@@ -4074,8 +4072,7 @@ merge(Compressor.prototype, {
         // "x" + (y + "z")==>  "x" + y + "z"
         if (self.right instanceof AST_Binary
             && self.right.operator == self.operator
-            && (self.operator == "&&"
-                || self.operator == "||"
+            && (lazy_op(self.operator)
                 || (self.operator == "+"
                     && (self.right.left.is_string(compressor)
                         || (self.left.is_string(compressor)

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