fix output of imported AST (#2771)

This commit is contained in:
Alex Lam S.L
2018-01-12 01:05:49 +08:00
committed by GitHub
parent 1c9e13f47d
commit 6a696d0a7b

View File

@@ -454,7 +454,8 @@ function OutputStream(options) {
function prepend_comments(node) { function prepend_comments(node) {
var self = this; var self = this;
var start = node.start; var start = node.start;
if (!(start.comments_before && start.comments_before._dumped === self)) { if (!start) return;
if (start.comments_before && start.comments_before._dumped === self) return;
var comments = start.comments_before; var comments = start.comments_before;
if (!comments) { if (!comments) {
comments = start.comments_before = []; comments = start.comments_before = [];
@@ -527,18 +528,16 @@ function OutputStream(options) {
} }
} }
} }
}
function append_comments(node, tail) { function append_comments(node, tail) {
var self = this; var self = this;
var token = node.end; var token = node.end;
if (!token) return; if (!token) return;
var comments = token[tail ? "comments_before" : "comments_after"]; var comments = token[tail ? "comments_before" : "comments_after"];
if (comments if (!comments || comments._dumped === self) return;
&& comments._dumped !== self if (!(node instanceof AST_Statement || all(comments, function(c) {
&& (node instanceof AST_Statement || all(comments, function(c) {
return !/comment[134]/.test(c.type); return !/comment[134]/.test(c.type);
}))) { }))) return;
comments._dumped = self; comments._dumped = self;
var insert = OUTPUT.length; var insert = OUTPUT.length;
comments.filter(comment_filter, node).forEach(function(c, i) { comments.filter(comment_filter, node).forEach(function(c, i) {
@@ -563,7 +562,6 @@ function OutputStream(options) {
}); });
if (OUTPUT.length > insert) newline_insert = insert; if (OUTPUT.length > insert) newline_insert = insert;
} }
}
var stack = []; var stack = [];
return { return {