diff --git a/lib/compress.js b/lib/compress.js index 51fd18dc..d2f41263 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1954,15 +1954,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/lib/parse.js b/lib/parse.js index 05384812..bf80d5e2 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1274,7 +1274,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; @@ -1289,7 +1289,7 @@ function parse($TEXT, options) { expression : newexp, args : args, end : prev() - }), true); + }), allow_calls); }; function as_atom_node() { @@ -1333,7 +1333,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/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)(); + } +} 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);" +} 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; }