aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen1@gmail.com>2015-08-10 20:29:37 +0200
committerRichard van Velzen <rvanvelzen1@gmail.com>2015-08-10 20:29:37 +0200
commit6c8db6eae108b0b3d672b8b3ae01a4603a9f4533 (patch)
tree73d6e4cdbfdfb790055aa917202ec727c2cc3f7e
parent464a942a95395722b0a928168bd9494e1e858d0d (diff)
parent3ff0b9e0c97f9eae70756763354e59fc0d675795 (diff)
downloadtracifyjs-6c8db6eae108b0b3d672b8b3ae01a4603a9f4533.tar.gz
tracifyjs-6c8db6eae108b0b3d672b8b3ae01a4603a9f4533.zip
Merge pull request #767 from vjeux/208
[Fix] --define replaces SymbolRefs in LHS of assignments
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/issue-208.js11
2 files changed, 20 insertions, 1 deletions
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; }
+}