@@ -1552,6 +1552,12 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
1552
1552
return false
1553
1553
1554
1554
// 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
+
1555
1561
if ( processExportedClass ( cleanDeclaration , state ) )
1556
1562
return true
1557
1563
if ( processExportedEnum ( cleanDeclaration , state ) )
@@ -1560,7 +1566,7 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
1560
1566
return true
1561
1567
1562
1568
// Handle named exports
1563
- if ( cleanDeclaration . startsWith ( 'export {' ) ) {
1569
+ if ( cleanDeclaration . includes ( 'export {' ) ) {
1564
1570
state . dtsLines . push ( declarationText )
1565
1571
return true
1566
1572
}
@@ -1573,15 +1579,39 @@ function processExportBlock(cleanDeclaration: string, declarationText: string, s
1573
1579
function processExport ( line : string , state : ProcessingState ) : void {
1574
1580
debugLog ( 'export-processing' , `Processing export: ${ line } ` )
1575
1581
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
+
1576
1597
const exportMatch = line . match ( / e x p o r t \s * \{ ( [ ^ } ] + ) \} (?: \s * f r o m \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] ) ? / )
1577
1598
if ( ! exportMatch ) {
1578
1599
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
+ }
1579
1604
return
1580
1605
}
1581
1606
1582
1607
const [ , exports , sourceModule ] = exportMatch
1583
1608
debugLog ( 'export-found' , `Found exports: ${ exports } , source: ${ sourceModule || 'local' } ` )
1584
1609
1610
+ // If it's a complete export statement, add it to dtsLines
1611
+ if ( line . startsWith ( 'export {' ) ) {
1612
+ state . dtsLines . push ( line )
1613
+ }
1614
+
1585
1615
exports . split ( ',' ) . forEach ( ( exp ) => {
1586
1616
const [ itemName , aliasName ] = exp . trim ( ) . split ( / \s + a s \s + / ) . map ( e => e . trim ( ) )
1587
1617
@@ -1798,6 +1828,7 @@ function processSourceFile(content: string, state: ProcessingState): void {
1798
1828
let bracketDepth = 0
1799
1829
let angleDepth = 0
1800
1830
let inDeclaration = false
1831
+ let inExport = false
1801
1832
state . currentScope = 'top'
1802
1833
1803
1834
debugLog ( 'source-processing' , `Processing source file with ${ lines . length } lines` )
@@ -1807,7 +1838,27 @@ function processSourceFile(content: string, state: ProcessingState): void {
1807
1838
const line = lines [ i ]
1808
1839
const trimmedLine = line . trim ( )
1809
1840
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
+ }
1811
1862
1812
1863
// Process imports
1813
1864
if ( line . includes ( 'import ' ) ) {
@@ -1827,7 +1878,9 @@ function processSourceFile(content: string, state: ProcessingState): void {
1827
1878
if ( trimmedLine . startsWith ( 'export {' ) ) {
1828
1879
debugLog ( 'mixed-export' , `Found mixed export: ${ trimmedLine } ` )
1829
1880
processExport ( trimmedLine , state )
1830
- state . dtsLines . push ( line )
1881
+ if ( trimmedLine . includes ( '}' ) ) {
1882
+ state . dtsLines . push ( line )
1883
+ }
1831
1884
continue
1832
1885
}
1833
1886
}
0 commit comments