diff --git a/lib/parse.js b/lib/parse.js index 2b1a3714..41aa988b 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1276,9 +1276,16 @@ function parse($TEXT, options) { case "(": next(); var ex = expression(true); + [].push.apply(start.comments_before, ex.start.comments_before); + ex.start.comments_before = start.comments_before; + start.comments_after = ex.start.comments_after; ex.start = start; - ex.end = S.token; expect(")"); + var end = prev(); + end.comments_before = ex.end.comments_before; + [].push.apply(ex.end.comments_after, end.comments_after); + end.comments_after = ex.end.comments_after; + ex.end = end; return subscripts(ex, allow_calls); case "[": return subscripts(array_(), allow_calls); diff --git a/test/compress/pure_funcs.js b/test/compress/pure_funcs.js index 3cc529a8..7acc38ab 100644 --- a/test/compress/pure_funcs.js +++ b/test/compress/pure_funcs.js @@ -293,3 +293,16 @@ unary: { bar(); } } + +issue_2629: { + options = { + side_effects: true, + } + input: { + /*@__PURE__*/ f1(); + (/*@__PURE__*/ f2)(); + /*@__PURE__*/ (f3()); + (/*@__PURE__*/ f4()); + } + expect: {} +} diff --git a/test/mocha/comment.js b/test/mocha/comment.js index fae9ab36..3bad9e01 100644 --- a/test/mocha/comment.js +++ b/test/mocha/comment.js @@ -207,4 +207,16 @@ describe("Comment", function() { if (result.error) throw result.error; assert.strictEqual(result.code, code); }); + + it("Should preserve comments around IIFE", function() { + var result = uglify.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", { + compress: false, + mangle: false, + output: { + comments: "all", + }, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, "/*a*/ /*b*/(function(){/*c*/}/*d*/ /*e*/)();"); + }); });