@@ -311,7 +311,7 @@ export function processLine(line: string, state: ProcessingState): void {
311311 }
312312
313313 if ( trimmedLine . startsWith ( 'export default' ) ) {
314- state . defaultExport = `\n ${ trimmedLine } ;`
314+ state . defaultExport = trimmedLine . endsWith ( ';' ) ? trimmedLine : ` ${ trimmedLine } ;`
315315 return
316316 }
317317
@@ -590,6 +590,16 @@ export function processDeclarationBlock(
590590 return
591591 }
592592
593+ if (
594+ declarationWithoutComments . startsWith ( 'export default' )
595+ ) {
596+ // Handle export default statements
597+ state . defaultExport = declarationWithoutComments . endsWith ( ';' )
598+ ? declarationWithoutComments
599+ : `${ declarationWithoutComments } ;`
600+ return
601+ }
602+
593603 if (
594604 declarationWithoutComments . startsWith ( 'export const' )
595605 || declarationWithoutComments . startsWith ( 'const' )
@@ -1964,18 +1974,24 @@ function getDeclarationType(line: string): 'interface' | 'type' | 'const' | 'fun
19641974 * Format the final output with proper spacing and organization
19651975 */
19661976function formatOutput ( state : ProcessingState ) : string {
1967- const output = state . dtsLines
1977+ const outputLines = state . dtsLines
19681978 // Remove more than two consecutive empty lines
19691979 . reduce ( ( acc , line , index , arr ) => {
19701980 if ( line === '' && arr [ index - 1 ] === '' && arr [ index - 2 ] === '' ) {
19711981 return acc
19721982 }
19731983 return [ ...acc , line ]
19741984 } , [ ] as string [ ] )
1975- . join ( '\n' )
19761985
1977- // Ensure file ends with single newline
1978- return `${ output . trim ( ) } \n`
1986+ // Ensure file ends with a single newline
1987+ let output = outputLines . join ( '\n' ) . trim ( )
1988+
1989+ // Append default export at the end if it exists
1990+ if ( state . defaultExport ) {
1991+ output += `\n\n${ state . defaultExport . trim ( ) } `
1992+ }
1993+
1994+ return `${ output } \n`
19791995}
19801996
19811997function getIndentation ( line : string ) : string {
0 commit comments