[Fix] --define replaces SymbolRefs in LHS of assignments
See #208 for context
This commit is contained in:
@@ -2277,7 +2277,15 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_SymbolRef, function(self, compressor){
|
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");
|
var defines = compressor.option("global_defs");
|
||||||
if (defines && defines.hasOwnProperty(self.name)) {
|
if (defines && defines.hasOwnProperty(self.name)) {
|
||||||
return make_node_from_constant(compressor, defines[self.name], self);
|
return make_node_from_constant(compressor, defines[self.name], self);
|
||||||
|
|||||||
11
test/compress/issue-208.js
Normal file
11
test/compress/issue-208.js
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user