* @param {AstPath} path * @param {CommentPrintOptions & { * indent?: boolean, * marker?: symbol | string, * }} [danglingCommentsPrintOptions] * @returns {Doc}
(
path,
options,
danglingCommentsPrintOptions = {},
)
| 121 | * @returns {Doc} |
| 122 | */ |
| 123 | function printDanglingComments( |
| 124 | path, |
| 125 | options, |
| 126 | danglingCommentsPrintOptions = {}, |
| 127 | ) { |
| 128 | const { |
| 129 | indent: shouldIndent = false, |
| 130 | marker, |
| 131 | filter = returnTrue, |
| 132 | } = danglingCommentsPrintOptions; |
| 133 | const danglingComments = new Set( |
| 134 | path.node?.comments?.filter( |
| 135 | (comment) => |
| 136 | !( |
| 137 | comment.leading || |
| 138 | comment.trailing || |
| 139 | comment.marker !== marker || |
| 140 | !filter(comment) |
| 141 | ), |
| 142 | ), |
| 143 | ); |
| 144 | |
| 145 | if (danglingComments.size === 0) { |
| 146 | return ""; |
| 147 | } |
| 148 | |
| 149 | const parts = path |
| 150 | .map( |
| 151 | ({ node: comment }) => |
| 152 | danglingComments.has(comment) ? printComment(path, options) : "", |
| 153 | "comments", |
| 154 | ) |
| 155 | .filter(Boolean); |
| 156 | |
| 157 | const doc = join(hardline, parts); |
| 158 | return shouldIndent ? indent([hardline, doc]) : doc; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | @param {AstPath} path |
no test coverage detected
searching dependent graphs…