@@ -1552,6 +1552,12 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
15521552 return false
15531553
15541554 // Handle various export types
1555+ if ( cleanDeclaration . startsWith ( 'export {' ) ) {
1556+ // Handle multiline exports by preserving the entire declaration
1557+ state . dtsLines . push ( declarationText )
1558+ return true
1559+ }
1560+
15551561 if ( processExportedClass ( cleanDeclaration , state ) )
15561562 return true
15571563 if ( processExportedEnum ( cleanDeclaration , state ) )
@@ -1560,7 +1566,7 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
15601566 return true
15611567
15621568 // Handle named exports
1563- if ( cleanDeclaration . startsWith ( 'export {' ) ) {
1569+ if ( cleanDeclaration . includes ( 'export {' ) ) {
15641570 state . dtsLines . push ( declarationText )
15651571 return true
15661572 }
@@ -1573,15 +1579,39 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
15731579function processExport ( line : string , state : ProcessingState ) : void {
15741580 debugLog ( 'export-processing' , `Processing export: ${ line } ` )
15751581
1582+ // Handle multiline exports by concatenating until we have a complete statement
1583+ if ( line . includes ( '{' ) && ! line . includes ( '}' ) ) {
1584+ state . currentDeclaration = line
1585+ return
1586+ }
1587+
1588+ // Continue building multiline export
1589+ if ( state . currentDeclaration ) {
1590+ state . currentDeclaration += ` ${ line } `
1591+ if ( ! line . includes ( '}' ) )
1592+ return
1593+ line = state . currentDeclaration
1594+ state . currentDeclaration = ''
1595+ }
1596+
15761597 const exportMatch = line . match ( / e x p o r t \s * \{ ( [ ^ } ] + ) \} (?: \s * f r o m \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] ) ? / )
15771598 if ( ! exportMatch ) {
15781599 debugLog ( 'export-error' , 'Failed to match export pattern' )
1600+ if ( line . startsWith ( 'export {' ) ) {
1601+ // If it's a malformed export statement, add it as-is to preserve the declaration
1602+ state . dtsLines . push ( line )
1603+ }
15791604 return
15801605 }
15811606
15821607 const [ , exports , sourceModule ] = exportMatch
15831608 debugLog ( 'export-found' , `Found exports: ${ exports } , source: ${ sourceModule || 'local' } ` )
15841609
1610+ // If it's a complete export statement, add it to dtsLines
1611+ if ( line . startsWith ( 'export {' ) ) {
1612+ state . dtsLines . push ( line )
1613+ }
1614+
15851615 exports . split ( ',' ) . forEach ( ( exp ) => {
15861616 const [ itemName , aliasName ] = exp . trim ( ) . split ( / \s + a s \s + / ) . map ( e => e . trim ( ) )
15871617
@@ -1798,6 +1828,7 @@ function processSourceFile(content: string, state: ProcessingState): void {
17981828 let bracketDepth = 0
17991829 let angleDepth = 0
18001830 let inDeclaration = false
1831+ let inExport = false
18011832 state . currentScope = 'top'
18021833
18031834 debugLog ( 'source-processing' , `Processing source file with ${ lines . length } lines` )
@@ -1807,7 +1838,27 @@ function processSourceFile(content: string, state: ProcessingState): void {
18071838 const line = lines [ i ]
18081839 const trimmedLine = line . trim ( )
18091840
1810- debugLog ( 'source-scan' , `First pass - Line ${ i + 1 } : ${ trimmedLine } ` )
1841+ // Handle export blocks
1842+ if ( trimmedLine . startsWith ( 'export {' ) ) {
1843+ if ( trimmedLine . includes ( '}' ) ) {
1844+ // Single-line export
1845+ state . dtsLines . push ( line )
1846+ continue
1847+ }
1848+ inExport = true
1849+ currentBlock = [ line ]
1850+ continue
1851+ }
1852+
1853+ if ( inExport ) {
1854+ currentBlock . push ( line )
1855+ if ( line . includes ( '}' ) ) {
1856+ state . dtsLines . push ( currentBlock . join ( '\n' ) )
1857+ currentBlock = [ ]
1858+ inExport = false
1859+ }
1860+ continue
1861+ }
18111862
18121863 // Process imports
18131864 if ( line . includes ( 'import ' ) ) {
@@ -1827,7 +1878,9 @@ function processSourceFile(content: string, state: ProcessingState): void {
18271878 if ( trimmedLine . startsWith ( 'export {' ) ) {
18281879 debugLog ( 'mixed-export' , `Found mixed export: ${ trimmedLine } ` )
18291880 processExport ( trimmedLine , state )
1830- state . dtsLines . push ( line )
1881+ if ( trimmedLine . includes ( '}' ) ) {
1882+ state . dtsLines . push ( line )
1883+ }
18311884 continue
18321885 }
18331886 }
0 commit comments