[Pkg-javascript-commits] [uglifyjs] 402/491: handle trailing line comments correctly (#2736)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:57 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 659c8a763265dfb6d567f5a41422f5f9095af4d8
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Jan 6 21:05:21 2018 +0800

    handle trailing line comments correctly (#2736)
    
    fixes #2734
---
 lib/output.js         |  8 ++++++--
 test/mocha/comment.js | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index 58521e3..83cd37b 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -534,7 +534,11 @@ function OutputStream(options) {
         var token = node.end;
         if (!token) return;
         var comments = token[tail ? "comments_before" : "comments_after"];
-        if (comments && comments._dumped !== self) {
+        if (comments
+            && comments._dumped !== self
+            && (node instanceof AST_Statement || all(comments, function(c) {
+                return !/comment[134]/.test(c.type);
+            }))) {
             comments._dumped = self;
             var insert = OUTPUT.length;
             comments.filter(comment_filter, node).forEach(function(c, i) {
@@ -599,7 +603,7 @@ function OutputStream(options) {
         add_mapping     : add_mapping,
         option          : function(opt) { return options[opt] },
         prepend_comments: readonly ? noop : prepend_comments,
-        append_comments : readonly ? noop : append_comments,
+        append_comments : readonly || comment_filter === return_false ? noop : append_comments,
         line            : function() { return current_line },
         col             : function() { return current_col },
         pos             : function() { return current_pos },
diff --git a/test/mocha/comment.js b/test/mocha/comment.js
index 3bad9e0..4db46b5 100644
--- a/test/mocha/comment.js
+++ b/test/mocha/comment.js
@@ -219,4 +219,24 @@ describe("Comment", function() {
         if (result.error) throw result.error;
         assert.strictEqual(result.code, "/*a*/ /*b*/(function(){/*c*/}/*d*/ /*e*/)();");
     });
+
+    it("Should output line comments after statements", function() {
+        var result = uglify.minify([
+            "x()//foo",
+            "{y()//bar",
+            "}",
+        ].join("\n"), {
+            compress: false,
+            mangle: false,
+            output: {
+                comments: "all",
+            },
+        });
+        if (result.error) throw result.error;
+        assert.strictEqual(result.code, [
+            "x();//foo",
+            "{y();//bar",
+            "}",
+        ].join("\n"));
+    });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list