@@ -311,7 +311,7 @@ export function processLine(line: string, state: ProcessingState): void {
311
311
}
312
312
313
313
if ( trimmedLine . startsWith ( 'export default' ) ) {
314
- state . defaultExport = `\n ${ trimmedLine } ;`
314
+ state . defaultExport = trimmedLine . endsWith ( ';' ) ? trimmedLine : ` ${ trimmedLine } ;`
315
315
return
316
316
}
317
317
@@ -590,6 +590,16 @@ export function processDeclarationBlock(
590
590
return
591
591
}
592
592
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
+
593
603
if (
594
604
declarationWithoutComments . startsWith ( 'export const' )
595
605
|| declarationWithoutComments . startsWith ( 'const' )
@@ -1964,18 +1974,24 @@ function getDeclarationType(line: string): 'interface' | 'type' | 'const' | 'fun
1964
1974
* Format the final output with proper spacing and organization
1965
1975
*/
1966
1976
function formatOutput ( state : ProcessingState ) : string {
1967
- const output = state . dtsLines
1977
+ const outputLines = state . dtsLines
1968
1978
// Remove more than two consecutive empty lines
1969
1979
. reduce ( ( acc , line , index , arr ) => {
1970
1980
if ( line === '' && arr [ index - 1 ] === '' && arr [ index - 2 ] === '' ) {
1971
1981
return acc
1972
1982
}
1973
1983
return [ ...acc , line ]
1974
1984
} , [ ] as string [ ] )
1975
- . join ( '\n' )
1976
1985
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`
1979
1995
}
1980
1996
1981
1997
function getIndentation ( line : string ) : string {
0 commit comments