[Pkg-javascript-commits] [uglifyjs] 417/491: fix output of imported AST (#2771)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:59 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 6a696d0a7ba88483a31e243d27b006c8c9ae0ec2
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Jan 12 01:05:49 2018 +0800

    fix output of imported AST (#2771)
---
 lib/output.js | 180 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 89 insertions(+), 91 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index 83cd37b..1b1ba2a 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -454,78 +454,78 @@ function OutputStream(options) {
     function prepend_comments(node) {
         var self = this;
         var start = node.start;
-        if (!(start.comments_before && start.comments_before._dumped === self)) {
-            var comments = start.comments_before;
-            if (!comments) {
-                comments = start.comments_before = [];
-            }
-            comments._dumped = self;
-
-            if (node instanceof AST_Exit && node.value) {
-                var tw = new TreeWalker(function(node) {
-                    var parent = tw.parent();
-                    if (parent instanceof AST_Exit
-                        || parent instanceof AST_Binary && parent.left === node
-                        || parent.TYPE == "Call" && parent.expression === node
-                        || parent instanceof AST_Conditional && parent.condition === node
-                        || parent instanceof AST_Dot && parent.expression === node
-                        || parent instanceof AST_Sequence && parent.expressions[0] === node
-                        || parent instanceof AST_Sub && parent.expression === node
-                        || parent instanceof AST_UnaryPostfix) {
-                        var text = node.start.comments_before;
-                        if (text && text._dumped !== self) {
-                            text._dumped = self;
-                            comments = comments.concat(text);
-                        }
-                    } else {
-                        return true;
+        if (!start) return;
+        if (start.comments_before && start.comments_before._dumped === self) return;
+        var comments = start.comments_before;
+        if (!comments) {
+            comments = start.comments_before = [];
+        }
+        comments._dumped = self;
+
+        if (node instanceof AST_Exit && node.value) {
+            var tw = new TreeWalker(function(node) {
+                var parent = tw.parent();
+                if (parent instanceof AST_Exit
+                    || parent instanceof AST_Binary && parent.left === node
+                    || parent.TYPE == "Call" && parent.expression === node
+                    || parent instanceof AST_Conditional && parent.condition === node
+                    || parent instanceof AST_Dot && parent.expression === node
+                    || parent instanceof AST_Sequence && parent.expressions[0] === node
+                    || parent instanceof AST_Sub && parent.expression === node
+                    || parent instanceof AST_UnaryPostfix) {
+                    var text = node.start.comments_before;
+                    if (text && text._dumped !== self) {
+                        text._dumped = self;
+                        comments = comments.concat(text);
                     }
-                });
-                tw.push(node);
-                node.value.walk(tw);
-            }
-
-            if (current_pos == 0) {
-                if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
-                    print("#!" + comments.shift().value + "\n");
-                    indent();
-                }
-                var preamble = options.preamble;
-                if (preamble) {
-                    print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
+                } else {
+                    return true;
                 }
+            });
+            tw.push(node);
+            node.value.walk(tw);
+        }
+
+        if (current_pos == 0) {
+            if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
+                print("#!" + comments.shift().value + "\n");
+                indent();
             }
+            var preamble = options.preamble;
+            if (preamble) {
+                print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
+            }
+        }
 
-            comments = comments.filter(comment_filter, node);
-            if (comments.length == 0) return;
-            var last_nlb = /(^|\n) *$/.test(OUTPUT);
-            comments.forEach(function(c, i) {
-                if (!last_nlb) {
-                    if (c.nlb) {
-                        print("\n");
-                        indent();
-                        last_nlb = true;
-                    } else if (i > 0) {
-                        space();
-                    }
-                }
-                if (/comment[134]/.test(c.type)) {
-                    print("//" + c.value.replace(/[@#]__PURE__/g, ' ') + "\n");
-                    indent();
-                    last_nlb = true;
-                } else if (c.type == "comment2") {
-                    print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
-                    last_nlb = false;
-                }
-            });
+        comments = comments.filter(comment_filter, node);
+        if (comments.length == 0) return;
+        var last_nlb = /(^|\n) *$/.test(OUTPUT);
+        comments.forEach(function(c, i) {
             if (!last_nlb) {
-                if (start.nlb) {
+                if (c.nlb) {
                     print("\n");
                     indent();
-                } else {
+                    last_nlb = true;
+                } else if (i > 0) {
                     space();
                 }
             }
+            if (/comment[134]/.test(c.type)) {
+                print("//" + c.value.replace(/[@#]__PURE__/g, ' ') + "\n");
+                indent();
+                last_nlb = true;
+            } else if (c.type == "comment2") {
+                print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
+                last_nlb = false;
+            }
+        });
+        if (!last_nlb) {
+            if (start.nlb) {
+                print("\n");
+                indent();
+            } else {
+                space();
+            }
         }
     }
 
@@ -534,35 +534,33 @@ function OutputStream(options) {
         var token = node.end;
         if (!token) return;
         var comments = token[tail ? "comments_before" : "comments_after"];
-        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) {
-                need_space = false;
-                if (need_newline_indented) {
-                    print("\n");
-                    indent();
-                    need_newline_indented = false;
-                } else if (c.nlb && (i > 0 || !/(^|\n) *$/.test(OUTPUT))) {
-                    print("\n");
-                    indent();
-                } else if (i > 0 || !tail) {
-                    space();
-                }
-                if (/comment[134]/.test(c.type)) {
-                    print("//" + c.value.replace(/[@#]__PURE__/g, ' '));
-                    need_newline_indented = true;
-                } else if (c.type == "comment2") {
-                    print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
-                    need_space = true;
-                }
-            });
-            if (OUTPUT.length > insert) newline_insert = insert;
-        }
+        if (!comments || comments._dumped === self) return;
+        if (!(node instanceof AST_Statement || all(comments, function(c) {
+            return !/comment[134]/.test(c.type);
+        }))) return;
+        comments._dumped = self;
+        var insert = OUTPUT.length;
+        comments.filter(comment_filter, node).forEach(function(c, i) {
+            need_space = false;
+            if (need_newline_indented) {
+                print("\n");
+                indent();
+                need_newline_indented = false;
+            } else if (c.nlb && (i > 0 || !/(^|\n) *$/.test(OUTPUT))) {
+                print("\n");
+                indent();
+            } else if (i > 0 || !tail) {
+                space();
+            }
+            if (/comment[134]/.test(c.type)) {
+                print("//" + c.value.replace(/[@#]__PURE__/g, ' '));
+                need_newline_indented = true;
+            } else if (c.type == "comment2") {
+                print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
+                need_space = true;
+            }
+        });
+        if (OUTPUT.length > insert) newline_insert = insert;
     }
 
     var stack = [];

-- 
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