File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,16 +14,19 @@ export class MultiLineComment extends CommentNode {
1414
1515 value : string ;
1616
17+ lines : string [ ] ;
18+
1719 constructor ( ast : TerminalNode , offset : number ) {
1820 super ( ast , offset ) ;
1921
2022 this . value = ast . unparse ( ) ;
23+ this . lines = this . value . slice ( 1 ) . split ( '\n' ) ;
2124 }
2225
2326 print ( ) : Doc {
2427 if ( isIndentableBlockComment ( this ) ) {
2528 return printIndentableBlockComment ( this ) ;
2629 }
27- return join ( literalline , this . value . split ( '\n' ) ) ;
30+ return [ '/' , join ( literalline , this . lines ) ] ;
2831 }
2932}
Original file line number Diff line number Diff line change @@ -14,16 +14,19 @@ export class MultiLineNatSpecComment extends CommentNode {
1414
1515 value : string ;
1616
17+ lines : string [ ] ;
18+
1719 constructor ( ast : TerminalNode , offset : number ) {
1820 super ( ast , offset ) ;
1921
2022 this . value = ast . unparse ( ) ;
23+ this . lines = this . value . slice ( 1 ) . split ( '\n' ) ;
2124 }
2225
2326 print ( ) : Doc {
2427 if ( isIndentableBlockComment ( this ) ) {
2528 return printIndentableBlockComment ( this ) ;
2629 }
27- return join ( literalline , this . value . split ( '\n' ) ) ;
30+ return [ '/' , join ( literalline , this . lines ) ] ;
2831 }
2932}
Original file line number Diff line number Diff line change @@ -5,14 +5,12 @@ import type { BlockComment } from '../slang-nodes/types.d.ts';
55
66const { hardline, join } = doc . builders ;
77
8- export function printIndentableBlockComment ( comment : BlockComment ) : Doc {
9- const lines = comment . value . split ( '\n' ) ;
10-
8+ export function printIndentableBlockComment ( { lines } : BlockComment ) : Doc {
119 return join (
1210 hardline ,
1311 lines . map ( ( line , index ) =>
1412 index === 0
15- ? line . trimEnd ( )
13+ ? `/ ${ line . trimEnd ( ) } `
1614 : ` ${ index < lines . length - 1 ? line . trim ( ) : line . trimStart ( ) } `
1715 )
1816 ) ;
Original file line number Diff line number Diff line change 11import type { BlockComment } from '../slang-nodes/types.d.ts' ;
22
3- export function isIndentableBlockComment ( comment : BlockComment ) : boolean {
3+ export function isIndentableBlockComment ( { lines } : BlockComment ) : boolean {
44 // If the comment has multiple lines and every line starts with a star
55 // we can fix the indentation of each line. The stars in the `/*` and
66 // `*/` delimiters are not included in the comment value, so add them
77 // back first.
8- const lines = comment . value . slice ( 1 , - 1 ) . split ( '\n' ) ;
98 return lines . length > 1 && lines . every ( ( line ) => line . trimStart ( ) [ 0 ] === '*' ) ;
109}
You can’t perform that action at this time.
0 commit comments