From 3ff0b9e0c97f9eae70756763354e59fc0d675795 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 10 Aug 2015 11:22:36 -0700 Subject: [PATCH] [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(-) create mode 100644 test/compress/issue-208.js 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; } +} -- 2.34.1