faster output of comments (#2806)
This commit is contained in:
@@ -451,6 +451,11 @@ function OutputStream(options) {
|
|||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function has_nlb() {
|
||||||
|
var index = OUTPUT.lastIndexOf("\n");
|
||||||
|
return /^ *$/.test(OUTPUT.slice(index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
function prepend_comments(node) {
|
function prepend_comments(node) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var start = node.start;
|
var start = node.start;
|
||||||
@@ -499,7 +504,7 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
comments = comments.filter(comment_filter, node);
|
comments = comments.filter(comment_filter, node);
|
||||||
if (comments.length == 0) return;
|
if (comments.length == 0) return;
|
||||||
var last_nlb = /(^|\n) *$/.test(OUTPUT);
|
var last_nlb = has_nlb();
|
||||||
comments.forEach(function(c, i) {
|
comments.forEach(function(c, i) {
|
||||||
if (!last_nlb) {
|
if (!last_nlb) {
|
||||||
if (c.nlb) {
|
if (c.nlb) {
|
||||||
@@ -546,7 +551,7 @@ function OutputStream(options) {
|
|||||||
print("\n");
|
print("\n");
|
||||||
indent();
|
indent();
|
||||||
need_newline_indented = false;
|
need_newline_indented = false;
|
||||||
} else if (c.nlb && (i > 0 || !/(^|\n) *$/.test(OUTPUT))) {
|
} else if (c.nlb && (i > 0 || !has_nlb())) {
|
||||||
print("\n");
|
print("\n");
|
||||||
indent();
|
indent();
|
||||||
} else if (i > 0 || !tail) {
|
} else if (i > 0 || !tail) {
|
||||||
|
|||||||
Reference in New Issue
Block a user