From: Richard van Velzen Date: Tue, 25 Aug 2015 08:53:35 +0000 (+0200) Subject: Don't change sequences that influence lexical binding in calls X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=e3bd223dac41ed8fcbbc3a139d78c68bcd50f628;p=UglifyJS.git Don't change sequences that influence lexical binding in calls Fixes #782 --- diff --git a/lib/compress.js b/lib/compress.js index ac306fc3..51dd66f8 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1910,15 +1910,11 @@ merge(Compressor.prototype, { if (!compressor.option("side_effects")) return self; if (!self.car.has_side_effects(compressor)) { - // 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)) { + // we shouldn't compress (1,func)(something) to + // func(something) because that changes the meaning of + // the func (becomes lexical instead of global). + var p = compressor.parent(); + if (!(p instanceof AST_Call && p.expression === self)) { return self.cdr; } } diff --git a/test/compress/issue-782.js b/test/compress/issue-782.js new file mode 100644 index 00000000..cce15fd1 --- /dev/null +++ b/test/compress/issue-782.js @@ -0,0 +1,23 @@ +remove_redundant_sequence_items: { + options = { side_effects: true }; + input: { + (0, 1, logThis)(); + (0, 1, _decorators.logThis)(); + } + expect: { + (0, logThis)(); + (0, _decorators.logThis)(); + } +} + +dont_remove_lexical_binding_sequence: { + options = { side_effects: true }; + input: { + (0, logThis)(); + (0, _decorators.logThis)(); + } + expect: { + (0, logThis)(); + (0, _decorators.logThis)(); + } +}