mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
chore(jsdoc): update to reflect @babel/parser comment-attachment changes
This commit is contained in:
parent
ae9fc352c4
commit
29829196eb
@ -769,9 +769,6 @@ class Visitor {
|
|||||||
let comments;
|
let comments;
|
||||||
let e;
|
let e;
|
||||||
const isBlock = isBlockComment(node);
|
const isBlock = isBlockComment(node);
|
||||||
let lastTrailingComment;
|
|
||||||
let nextProgramNode;
|
|
||||||
let nextProgramNodeIndex;
|
|
||||||
let rawComment;
|
let rawComment;
|
||||||
|
|
||||||
function addComments(source) {
|
function addComments(source) {
|
||||||
@ -789,32 +786,11 @@ class Visitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trailing comments are always duplicates of leading comments unless they're attached to the
|
// trailing comments are always duplicates of leading comments unless they're attached to the
|
||||||
// Program node...
|
// Program node
|
||||||
if (node.type === Syntax.Program && node.trailingComments && node.trailingComments.length) {
|
if (node.type === Syntax.Program && node.trailingComments && node.trailingComments.length) {
|
||||||
addComments(node.trailingComments);
|
addComments(node.trailingComments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...or if they were comments from the end of the file that were erroneously attached to a
|
|
||||||
// `'use strict';` declaration (https://github.com/babel/babel/issues/6688).
|
|
||||||
if (
|
|
||||||
node.type === Syntax.ExpressionStatement &&
|
|
||||||
node.directive === 'use strict' &&
|
|
||||||
node.trailingComments &&
|
|
||||||
node.trailingComments.length
|
|
||||||
) {
|
|
||||||
// to be safe, we verify that the trailing comments came after the next node in the Program
|
|
||||||
// body, which means the comments were attached to the wrong node
|
|
||||||
if (node.parent.body.length > 1) {
|
|
||||||
nextProgramNodeIndex = node.parent.body.indexOf(node) + 1;
|
|
||||||
nextProgramNode = node.parent.body[nextProgramNodeIndex];
|
|
||||||
lastTrailingComment = node.trailingComments[node.trailingComments.length - 1];
|
|
||||||
|
|
||||||
if (lastTrailingComment.start > nextProgramNode.end) {
|
|
||||||
addComments(node.trailingComments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.innerComments && node.innerComments.length) {
|
if (node.innerComments && node.innerComments.length) {
|
||||||
addComments(node.innerComments);
|
addComments(node.innerComments);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user