From e3bd223dac41ed8fcbbc3a139d78c68bcd50f628 Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Tue, 25 Aug 2015 10:53:35 +0200 Subject: [PATCH 1/3] Don't change sequences that influence lexical binding in calls Fixes #782 --- lib/compress.js | 14 +++++--------- test/compress/issue-782.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 test/compress/issue-782.js 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)(); + } +} From fcde6109b0138502a445a7571adc810b5b9e68ee Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Thu, 6 Aug 2015 21:27:46 +0200 Subject: [PATCH 2/3] Fix bad parsing of `new new x()()` constructs Fixes #739 --- lib/parse.js | 6 +++--- test/compress/new.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/compress/new.js diff --git a/lib/parse.js b/lib/parse.js index ab72ad2d..496a673f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1114,7 +1114,7 @@ function parse($TEXT, options) { }); }; - var new_ = function() { + var new_ = function(allow_calls) { var start = S.token; expect_token("operator", "new"); var newexp = expr_atom(false), args; @@ -1129,7 +1129,7 @@ function parse($TEXT, options) { expression : newexp, args : args, end : prev() - }), true); + }), allow_calls); }; function as_atom_node() { @@ -1173,7 +1173,7 @@ function parse($TEXT, options) { var expr_atom = function(allow_calls) { if (is("operator", "new")) { - return new_(); + return new_(allow_calls); } var start = S.token; if (is("punc")) { diff --git a/test/compress/new.js b/test/compress/new.js new file mode 100644 index 00000000..4b2c51c3 --- /dev/null +++ b/test/compress/new.js @@ -0,0 +1,12 @@ +new_statement: { + input: { + new x(1); + new x(1)(2); + new x(1)(2)(3); + new new x(1); + new new x(1)(2); + new (new x(1))(2); + (new new x(1))(2); + } + expect_exact: "new x(1);new x(1)(2);new x(1)(2)(3);new new x(1);new new x(1)(2);new new x(1)(2);(new new x(1))(2);" +} From 3a5f35484606914b54fb80540f51b37fae20282b Mon Sep 17 00:00:00 2001 From: Ingo Struck Date: Thu, 27 Aug 2015 19:38:33 +0200 Subject: [PATCH 3/3] allow for anonymous map generation using string type check --- tools/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index 29d5632d..eba2bc1d 100644 --- a/tools/node.js +++ b/tools/node.js @@ -131,7 +131,7 @@ exports.minify = function(files, options) { var stream = UglifyJS.OutputStream(output); toplevel.print(stream); - if(options.outSourceMap){ + if (options.outSourceMap && "string" === typeof options.outSourceMap) { stream += "\n//# sourceMappingURL=" + options.outSourceMap; }