(commentPath: any, print: any)
| 264 | } |
| 265 | |
| 266 | function printLeadingComment(commentPath: any, print: any) { |
| 267 | const comment = commentPath.getValue(); |
| 268 | n.Comment.assert(comment); |
| 269 | |
| 270 | const loc = comment.loc; |
| 271 | const lines = loc && loc.lines; |
| 272 | const parts = [print(commentPath)]; |
| 273 | |
| 274 | if (comment.trailing) { |
| 275 | // When we print trailing comments as leading comments, we don't |
| 276 | // want to bring any trailing spaces along. |
| 277 | parts.push("\n"); |
| 278 | } else if (lines instanceof Lines) { |
| 279 | const trailingSpace = lines.slice( |
| 280 | loc.end, |
| 281 | lines.skipSpaces(loc.end) || lines.lastPos(), |
| 282 | ); |
| 283 | |
| 284 | if (trailingSpace.length === 1) { |
| 285 | // If the trailing space contains no newlines, then we want to |
| 286 | // preserve it exactly as we found it. |
| 287 | parts.push(trailingSpace); |
| 288 | } else { |
| 289 | // If the trailing space contains newlines, then replace it |
| 290 | // with just that many newlines, with all other spaces removed. |
| 291 | parts.push(new Array(trailingSpace.length).join("\n")); |
| 292 | } |
| 293 | } else { |
| 294 | parts.push("\n"); |
| 295 | } |
| 296 | |
| 297 | return concat(parts); |
| 298 | } |
| 299 | |
| 300 | function printTrailingComment(commentPath: any, print: any) { |
| 301 | const comment = commentPath.getValue(commentPath); |
no test coverage detected
searching dependent graphs…