[Pkg-javascript-commits] [uglifyjs] 05/228: add missing LHS cases which global_defs should avoid

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:11 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 48284844a461e6113bb9911cdcdad7ab8a3d85de
Author: alexlamsl <alexlamsl at gmail.com>
Date:   Tue Jan 17 17:33:40 2017 +0800

    add missing LHS cases which global_defs should avoid
---
 lib/compress.js            | 13 +++++--------
 lib/scope.js               |  2 +-
 test/compress/issue-208.js | 30 ++++++++++++++++++++++++------
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 5879b93..bbd3659 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -970,6 +970,11 @@ merge(Compressor.prototype, {
         node.DEFMETHOD("is_string", func);
     });
 
+    function isLHS(node, parent) {
+        return parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
+            || parent instanceof AST_Assign && parent.left === node;
+    }
+
     function best_of(ast1, ast2) {
         return ast1.print_to_string().length >
             ast2.print_to_string().length
@@ -2608,14 +2613,6 @@ merge(Compressor.prototype, {
     });
 
     OPT(AST_SymbolRef, function(self, compressor){
-        function isLHS(symbol, parent) {
-            return (
-                parent instanceof AST_Binary &&
-                parent.operator === '=' &&
-                parent.left === symbol
-            );
-        }
-
         if (self.undeclared() && !isLHS(self, compressor.parent())) {
             var defines = compressor.option("global_defs");
             if (defines && HOP(defines, self.name)) {
diff --git a/lib/scope.js b/lib/scope.js
index 4943b56..bc5db90 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -220,7 +220,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
                 sym = g;
             }
             node.thedef = sym;
-            if (parent instanceof AST_Unary && (parent.operator === '++' || parent.operator === '--')
+            if (parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
              || parent instanceof AST_Assign && parent.left === node) {
                 sym.modified = true;
             }
diff --git a/test/compress/issue-208.js b/test/compress/issue-208.js
index 14752b8..2f10378 100644
--- a/test/compress/issue-208.js
+++ b/test/compress/issue-208.js
@@ -1,11 +1,29 @@
 do_not_update_lhs: {
-    options = { global_defs: { DEBUG: false } };
-    input: { DEBUG = false; }
-    expect: { DEBUG = false; }
+    options = {
+        global_defs: { DEBUG: 0 }
+    }
+    input: {
+        DEBUG++;
+        DEBUG += 1;
+        DEBUG = 1;
+    }
+    expect: {
+        DEBUG++;
+        DEBUG += 1;
+        DEBUG = 1;
+    }
 }
 
 do_update_rhs: {
-    options = { global_defs: { DEBUG: false } };
-    input: { MY_DEBUG = DEBUG; }
-    expect: { MY_DEBUG = false; }
+    options = {
+        global_defs: { DEBUG: 0 }
+    }
+    input: {
+        MY_DEBUG = DEBUG;
+        MY_DEBUG += DEBUG;
+    }
+    expect: {
+        MY_DEBUG = 0;
+        MY_DEBUG += 0;
+    }
 }

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