diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-11-17 12:05:31 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-11-17 12:05:31 +0200 |
commit | 0d3fd2ef30d0a85edb76d6db6e9f6ef034f1cee4 (patch) | |
tree | e127312ecc31c1d069abd3b9460c6e44b2b09773 /lib/compress.js | |
parent | e98119496a3d22f2d7ddc5f686eb8edfe05704ad (diff) | |
download | tracifyjs-0d3fd2ef30d0a85edb76d6db6e9f6ef034f1cee4.tar.gz tracifyjs-0d3fd2ef30d0a85edb76d6db6e9f6ef034f1cee4.zip |
retain (1,eval) as is when it's the expression of an AST_Call
otherwise we change the meaning of eval from global to lexical.
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 66375be8..7c4c910d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1549,8 +1549,19 @@ merge(Compressor.prototype, { OPT(AST_Seq, function(self, compressor){ if (!compressor.option("side_effects")) return self; - if (!self.car.has_side_effects()) - return self.cdr; + if (!self.car.has_side_effects()) { + // we shouldn't compress (1,eval)(something) to + // eval(something) because that changes the meaning of + // eval (becomes lexical instead of global). + var p; + if (!(self.cdr instanceof AST_SymbolRef + && self.cdr.name == "eval" + && self.cdr.undeclared() + && (p = compressor.parent()) instanceof AST_Call + && p.expression === self)) { + return self.cdr; + } + } if (compressor.option("cascade")) { if (self.car instanceof AST_Assign && !self.car.left.has_side_effects() |