@@ -380,9 +380,25 @@ export function format(input: string, options: Partial<FormatOptions> = {}): str
380380 }
381381 indentLevel -- ;
382382
383- // Check if there's an inline comment immediately after the closing paren (no newline in between)
383+ // Build closing line with ) and check for trailing comma or comment
384384 let closingLine = indent ( ) + ')' ;
385385 let nextIdx = idx + 1 ;
386+
387+ // Skip newlines to find next meaningful token
388+ while ( nextIdx < tokens . length && tokens [ nextIdx ] . type === TokenType . NEWLINE ) {
389+ nextIdx ++ ;
390+ }
391+
392+ // Check if next token is comma - include it on same line
393+ if ( nextIdx < tokens . length && tokens [ nextIdx ] . type === TokenType . COMMA ) {
394+ closingLine += ',' ;
395+ lines . push ( closingLine ) ;
396+ lastOutputWasComment = false ;
397+ return nextIdx + 1 ; // Skip past the comma
398+ }
399+
400+ // Check if there's an inline comment immediately after the closing paren (no newline in between)
401+ nextIdx = idx + 1 ;
386402 // Only attach comment if it's the immediate next token (not after newline)
387403 if ( nextIdx < tokens . length && tokens [ nextIdx ] . type === TokenType . COMMENT ) {
388404 // Append inline comment to closing paren
@@ -689,9 +705,23 @@ export function format(input: string, options: Partial<FormatOptions> = {}): str
689705 continue ;
690706 }
691707
692- lines . push ( indent ( ) + ')' ) ;
693- lastProcessedToken = token ; // RPAREN
694- i ++ ;
708+ // Output ) and check if there's a comma that should be on the same line
709+ let lineContent = indent ( ) + ')' ;
710+ let nextIdx = i + 1 ;
711+ // Skip newlines to find next meaningful token
712+ while ( nextIdx < tokens . length && tokens [ nextIdx ] . type === TokenType . NEWLINE ) {
713+ nextIdx ++ ;
714+ }
715+ // If next token is comma, include it on the same line
716+ if ( nextIdx < tokens . length && tokens [ nextIdx ] . type === TokenType . COMMA ) {
717+ lineContent += ',' ;
718+ i = nextIdx + 1 ; // Skip past the comma
719+ lastProcessedToken = tokens [ nextIdx ] ;
720+ } else {
721+ i ++ ;
722+ lastProcessedToken = token ; // RPAREN
723+ }
724+ lines . push ( lineContent ) ;
695725 continue ;
696726 }
697727 }
0 commit comments