File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,20 +22,19 @@ export function printComments(
2222 options : ParserOptions < AstNode >
2323) : Doc [ ] {
2424 if ( node . comments === undefined ) return [ ] ;
25+ const lastPrintableIndex = node . comments . findLastIndex ( isPrintable ) ;
2526 return joinExisting (
2627 line ,
27- path . map ( ( commentPath , index , comments : Comment [ ] ) => {
28+ path . map ( ( commentPath , index ) => {
2829 const comment = commentPath . node ;
2930 if ( ! isPrintable ( comment ) ) {
3031 return '' ;
3132 }
3233 comment . printed = true ;
33- const isLast =
34- index === comments . length - 1 ||
35- comments . slice ( index + 1 ) . findIndex ( isPrintable ) === - 1 ;
3634 return [
3735 printComment ( commentPath ) ,
38- ! isLast && util . isNextLineEmpty ( options . originalText , locEnd ( comment ) )
36+ index !== lastPrintableIndex &&
37+ util . isNextLineEmpty ( options . originalText , locEnd ( comment ) )
3938 ? hardline
4039 : ''
4140 ] ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ function hasNodeIgnoreComment({ comments }: StrictAstNode): boolean {
2222 ) ;
2323}
2424
25- function ignoreComments ( path : AstPath < AstNode > ) : void {
25+ function ignoreComments ( path : AstPath < StrictAstNode > ) : void {
2626 const node = path . node ;
2727 // We ignore anything that is not an object
2828 if ( node === null || typeof node !== 'object' ) return ;
@@ -38,7 +38,9 @@ function ignoreComments(path: AstPath<AstNode>): void {
3838 break ;
3939 // The key `comments` will contain every comment for this node.
4040 case 'comments' :
41- path . each ( ( commentPath ) => ( commentPath . node . printed = true ) , key ) ;
41+ if ( node . comments !== undefined ) {
42+ path . each ( ( commentPath ) => ( commentPath . node . printed = true ) , key ) ;
43+ }
4244 break ;
4345 default :
4446 // If the value for that key is an Array or an Object we go deeper.
Original file line number Diff line number Diff line change 55 "noImplicitAny" : true ,
66 "strictPropertyInitialization" : true ,
77 "sourceMap" : true ,
8- "target" : " es6 " ,
8+ "target" : " es2023 " ,
99 "module" : " NodeNext" ,
1010 "moduleResolution" : " NodeNext" ,
1111 "strict" : true ,
You can’t perform that action at this time.
0 commit comments