[Pkg-javascript-commits] [uglifyjs] 17/190: [Fix] --define replaces SymbolRefs in LHS of assignments

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 3ff0b9e0c97f9eae70756763354e59fc0d675795
Author: Christopher Chedeau <vjeux at fb.com>
Date:   Mon Aug 10 11:22:36 2015 -0700

    [Fix] --define replaces SymbolRefs in LHS of assignments
    
    See #208 for context
---
 lib/compress.js            | 10 +++++++++-
 test/compress/issue-208.js | 11 +++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 401a1c7..ac306fc 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2277,7 +2277,15 @@ merge(Compressor.prototype, {
     });
 
     OPT(AST_SymbolRef, function(self, compressor){
-        if (self.undeclared()) {
+        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 && defines.hasOwnProperty(self.name)) {
                 return make_node_from_constant(compressor, defines[self.name], self);
diff --git a/test/compress/issue-208.js b/test/compress/issue-208.js
new file mode 100644
index 0000000..14752b8
--- /dev/null
+++ b/test/compress/issue-208.js
@@ -0,0 +1,11 @@
+do_not_update_lhs: {
+    options = { global_defs: { DEBUG: false } };
+    input: { DEBUG = false; }
+    expect: { DEBUG = false; }
+}
+
+do_update_rhs: {
+    options = { global_defs: { DEBUG: false } };
+    input: { MY_DEBUG = DEBUG; }
+    expect: { MY_DEBUG = false; }
+}

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