aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/parse.js2
-rw-r--r--test/mocha/comments.js24
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/parse.js b/lib/parse.js
index 7321878f..16d8dad3 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -1253,6 +1253,7 @@ function parse($TEXT, options) {
var ex = expression(true);
var len = start.comments_before.length;
[].unshift.apply(ex.start.comments_before, start.comments_before);
+ start.comments_before.length = 0;
start.comments_before = ex.start.comments_before;
start.comments_before_length = len;
if (len == 0 && start.comments_before.length > 0) {
@@ -1268,6 +1269,7 @@ function parse($TEXT, options) {
var end = prev();
end.comments_before = ex.end.comments_before;
[].push.apply(ex.end.comments_after, end.comments_after);
+ end.comments_after.length = 0;
end.comments_after = ex.end.comments_after;
ex.end = end;
if (ex instanceof AST_Call) mark_pure(ex);
diff --git a/test/mocha/comments.js b/test/mocha/comments.js
index 764f6db8..9a4b3be6 100644
--- a/test/mocha/comments.js
+++ b/test/mocha/comments.js
@@ -259,6 +259,30 @@ describe("comments", function() {
assert.strictEqual(result.code, code);
});
+ it("Should handle comments around parenthesis correctly", function() {
+ var code = [
+ "a();",
+ "/* foo */",
+ "(b())",
+ "/* bar */",
+ "c();",
+ ].join("\n");
+ var result = UglifyJS.minify(code, {
+ compress: false,
+ mangle: false,
+ output: {
+ comments: "all",
+ },
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "a();",
+ "/* foo */",
+ "b()",
+ "/* bar */;c();",
+ ].join("\n"));
+ });
+
it("Should preserve comments around IIFE", function() {
var result = UglifyJS.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", {
compress: false,