|
|
@ -58,7 +58,6 @@ export function get_comment_handlers(source) {
|
|
|
|
* @typedef {import('estree').Comment & {
|
|
|
|
* @typedef {import('estree').Comment & {
|
|
|
|
* start: number;
|
|
|
|
* start: number;
|
|
|
|
* end: number;
|
|
|
|
* end: number;
|
|
|
|
* has_trailing_newline?: boolean
|
|
|
|
|
|
|
|
* }} CommentWithLocation
|
|
|
|
* }} CommentWithLocation
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
@ -91,35 +90,26 @@ export function get_comment_handlers(source) {
|
|
|
|
add_comments(ast) {
|
|
|
|
add_comments(ast) {
|
|
|
|
if (comments.length === 0) return;
|
|
|
|
if (comments.length === 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
walk(
|
|
|
|
walk(ast, null, {
|
|
|
|
ast,
|
|
|
|
_(node, { next }) {
|
|
|
|
{},
|
|
|
|
let comment;
|
|
|
|
{
|
|
|
|
|
|
|
|
_(node, { next }) {
|
|
|
|
|
|
|
|
let comment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (comments[0] && comments[0].start < node.start) {
|
|
|
|
while (comments[0] && comments[0].start < node.start) {
|
|
|
|
comment = /** @type {CommentWithLocation} */ (comments.shift());
|
|
|
|
comment = /** @type {CommentWithLocation} */ (comments.shift());
|
|
|
|
|
|
|
|
(node.leadingComments ||= []).push(comment);
|
|
|
|
const next = comments[0] || node;
|
|
|
|
}
|
|
|
|
comment.has_trailing_newline =
|
|
|
|
|
|
|
|
comment.type === 'Line' || /\n/.test(source.slice(comment.end, next.start));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(node.leadingComments ||= []).push(comment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
|
|
|
|
|
|
|
|
if (comments[0]) {
|
|
|
|
if (comments[0]) {
|
|
|
|
const slice = source.slice(node.end, comments[0].start);
|
|
|
|
const slice = source.slice(node.end, comments[0].start);
|
|
|
|
|
|
|
|
|
|
|
|
if (/^[,) \t]*$/.test(slice)) {
|
|
|
|
if (/^[,) \t]*$/.test(slice)) {
|
|
|
|
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
|
|
|
|
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|