File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { doc } from 'prettier' ;
21import { isComment } from '../slang-utils/is-comment.js' ;
32
43import type { AstPath , Doc } from 'prettier' ;
5- import type { AstNode , BlockComment } from '../slang-nodes' ;
6-
7- const { hardline, join } = doc . builders ;
8-
9- export function isIndentableBlockComment ( comment : BlockComment ) : boolean {
10- // If the comment has multiple lines and every line starts with a star
11- // we can fix the indentation of each line. The stars in the `/*` and
12- // `*/` delimiters are not included in the comment value, so add them
13- // back first.
14- const lines = comment . value . slice ( 1 , - 1 ) . split ( '\n' ) ;
15- return lines . length > 1 && lines . every ( ( line ) => line . trimStart ( ) [ 0 ] === '*' ) ;
16- }
17-
18- export function printIndentableBlockComment ( comment : BlockComment ) : Doc {
19- const lines = comment . value . split ( '\n' ) ;
20-
21- return join (
22- hardline ,
23- lines . map ( ( line , index ) =>
24- index === 0
25- ? line . trimEnd ( )
26- : ` ${ index < lines . length - 1 ? line . trim ( ) : line . trimStart ( ) } `
27- )
28- ) ;
29- }
4+ import type { AstNode } from '../slang-nodes' ;
305
316export function printComment ( commentPath : AstPath < AstNode > ) : Doc {
327 const comment = commentPath . getNode ( ) ! ;
Original file line number Diff line number Diff line change 11import { TerminalNode } from '@nomicfoundation/slang/cst/index.js' ;
22import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
33import { doc } from 'prettier' ;
4- import {
5- isIndentableBlockComment ,
6- printIndentableBlockComment
7- } from '../slang-comments/printer.js' ;
4+ import { isIndentableBlockComment } from '../slang-utils/is-indentable-block-comment.js' ;
5+ import { printIndentableBlockComment } from '../slang-printers/print-indentable-block-comment.js' ;
86
97import type { Doc } from 'prettier' ;
108import type { BaseComment , Location , SlangNode } from '../types' ;
Original file line number Diff line number Diff line change 11import { TerminalNode } from '@nomicfoundation/slang/cst/index.js' ;
22import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
33import { doc } from 'prettier' ;
4- import {
5- isIndentableBlockComment ,
6- printIndentableBlockComment
7- } from '../slang-comments/printer.js' ;
4+ import { isIndentableBlockComment } from '../slang-utils/is-indentable-block-comment.js' ;
5+ import { printIndentableBlockComment } from '../slang-printers/print-indentable-block-comment.js' ;
86
97import type { Doc } from 'prettier' ;
108import type { BaseComment , Location , SlangNode } from '../types' ;
Original file line number Diff line number Diff line change 1+ import { doc } from 'prettier' ;
2+
3+ import type { Doc } from 'prettier' ;
4+ import type { BlockComment } from '../slang-nodes' ;
5+
6+ const { hardline, join } = doc . builders ;
7+
8+ export function printIndentableBlockComment ( comment : BlockComment ) : Doc {
9+ const lines = comment . value . split ( '\n' ) ;
10+
11+ return join (
12+ hardline ,
13+ lines . map ( ( line , index ) =>
14+ index === 0
15+ ? line . trimEnd ( )
16+ : ` ${ index < lines . length - 1 ? line . trim ( ) : line . trimStart ( ) } `
17+ )
18+ ) ;
19+ }
Original file line number Diff line number Diff line change 1+ import { BlockComment } from '../slang-nodes' ;
2+
3+ export function isIndentableBlockComment ( comment : BlockComment ) : boolean {
4+ // If the comment has multiple lines and every line starts with a star
5+ // we can fix the indentation of each line. The stars in the `/*` and
6+ // `*/` delimiters are not included in the comment value, so add them
7+ // back first.
8+ const lines = comment . value . slice ( 1 , - 1 ) . split ( '\n' ) ;
9+ return lines . length > 1 && lines . every ( ( line ) => line . trimStart ( ) [ 0 ] === '*' ) ;
10+ }
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ function getLeadingOffset(children: Node[]): number {
3838export function getNodeMetadata (
3939 ast : SlangAstNode ,
4040 initialOffset : number ,
41- includePeripheralComments = false
41+ enclosePeripheralComments = false
4242) : Metadata {
4343 if ( typeof initialOffset === 'undefined' ) {
4444 throw new Error ( "Can't initiate metadata with an undefined initialOffset" ) ;
@@ -86,10 +86,10 @@ export function getNodeMetadata(
8686 return offsetsArray ;
8787 } , [ ] ) ;
8888
89- const leadingOffset = includePeripheralComments
89+ const leadingOffset = enclosePeripheralComments
9090 ? 0
9191 : getLeadingOffset ( children ) ;
92- const trailingOffset = includePeripheralComments
92+ const trailingOffset = enclosePeripheralComments
9393 ? 0
9494 : getLeadingOffset ( children . reverse ( ) ) ;
9595 const loc = {
You can’t perform that action at this time.
0 commit comments