11import { doc } from 'prettier' ;
2- import { isBlockComment , isLineComment } from '../slang-utils/is-comment.js' ;
2+ import { isComment } from '../slang-utils/is-comment.js' ;
33
44import type { AstPath , Doc } from 'prettier' ;
5- import type { AstNode } from '../slang-nodes' ;
6- import type { Comment } from '../types' ;
5+ import type { AstNode , BlockComment } from '../slang-nodes' ;
76
8- const { hardline, join, literalline } = doc . builders ;
7+ const { hardline, join } = doc . builders ;
98
10- function isIndentableBlockComment ( comment : Comment ) : boolean {
9+ export function isIndentableBlockComment ( comment : BlockComment ) : boolean {
1110 // If the comment has multiple lines and every line starts with a star
1211 // we can fix the indentation of each line. The stars in the `/*` and
1312 // `*/` delimiters are not included in the comment value, so add them
@@ -16,7 +15,7 @@ function isIndentableBlockComment(comment: Comment): boolean {
1615 return lines . length > 1 && lines . every ( ( line ) => line . trimStart ( ) [ 0 ] === '*' ) ;
1716}
1817
19- function printIndentableBlockComment ( comment : Comment ) : Doc {
18+ export function printIndentableBlockComment ( comment : BlockComment ) : Doc {
2019 const lines = comment . value . split ( '\n' ) ;
2120
2221 return join (
@@ -29,19 +28,11 @@ function printIndentableBlockComment(comment: Comment): Doc {
2928 ) ;
3029}
3130
32- export function printComment ( commentPath : AstPath < AstNode | Comment > ) : Doc {
31+ export function printComment ( commentPath : AstPath < AstNode > ) : Doc {
3332 const comment = commentPath . getNode ( ) ! ;
3433
35- if ( isLineComment ( comment ) ) {
36- return comment . value . trimEnd ( ) ;
37- }
38-
39- if ( isBlockComment ( comment ) ) {
40- if ( isIndentableBlockComment ( comment ) ) {
41- return printIndentableBlockComment ( comment ) ;
42- }
43-
44- return join ( literalline , comment . value . split ( '\n' ) ) ;
34+ if ( isComment ( comment ) ) {
35+ return comment . print ( ) ;
4536 }
4637
4738 throw new Error ( `Not a comment: ${ JSON . stringify ( comment ) } ` ) ;
0 commit comments