@@ -5992,15 +5992,25 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
59925992 }
59935993 }
59945994
5995- function shouldWriteComment ( text : string , pos : number ) {
5995+ function shouldWriteComment ( text : string , pos : number , end ?: number ) {
59965996 if ( printerOptions . onlyPrintJsDocStyle ) {
5997- return ( isJSDocLikeText ( text , pos ) || isPinnedComment ( text , pos ) ) ;
5997+ if ( ! isJSDocLikeText ( text , pos ) && ! isPinnedComment ( text , pos ) ) {
5998+ return false ;
5999+ }
6000+ // Skip @typedef and @callback comments - they're converted to type declarations
6001+ if ( end !== undefined ) {
6002+ const commentText = text . slice ( pos , end ) ;
6003+ if ( commentText . includes ( "@typedef" ) || commentText . includes ( "@callback" ) ) {
6004+ return false ;
6005+ }
6006+ }
6007+ return true ;
59986008 }
59996009 return true ;
60006010 }
60016011
60026012 function emitLeadingComment ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) {
6003- if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
6013+ if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos , commentEnd ) ) return ;
60046014 if ( ! hasWrittenComment ) {
60056015 emitNewLineBeforeLeadingCommentOfPosition ( getCurrentLineMap ( ) , writer , rangePos , commentPos ) ;
60066016 hasWrittenComment = true ;
@@ -6032,7 +6042,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
60326042 }
60336043
60346044 function emitTrailingComment ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
6035- if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
6045+ if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos , commentEnd ) ) return ;
60366046 // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
60376047 if ( ! writer . isAtStartOfLine ( ) ) {
60386048 writer . writeSpace ( " " ) ;
@@ -6135,7 +6145,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
61356145 }
61366146
61376147 function emitComment ( text : string , lineMap : readonly number [ ] , writer : EmitTextWriter , commentPos : number , commentEnd : number , newLine : string ) {
6138- if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
6148+ if ( ! currentSourceFile || ! shouldWriteComment ( currentSourceFile . text , commentPos , commentEnd ) ) return ;
61396149 emitPos ( commentPos ) ;
61406150 writeCommentRange ( text , lineMap , writer , commentPos , commentEnd , newLine ) ;
61416151 emitPos ( commentEnd ) ;
0 commit comments