From: Christopher Chedeau Date: Mon, 10 Aug 2015 18:22:36 +0000 (-0700) Subject: [Fix] --define replaces SymbolRefs in LHS of assignments X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3ff0b9e0c97f9eae70756763354e59fc0d675795;p=UglifyJS.git [Fix] --define replaces SymbolRefs in LHS of assignments See #208 for context --- diff --git a/lib/compress.js b/lib/compress.js index 401a1c75..ac306fc3 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 00000000..14752b8a --- /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; } +}