@@ -476,4 +476,71 @@ interface RegexPatterns {
476
476
readonly moduleAugmentation : RegExp
477
477
}
478
478
479
+ /**
480
+ * Extract complete function signature using regex
481
+ */
482
+ export function extractFunctionSignature ( declaration : string ) : FunctionSignature {
483
+ // Remove comments and clean up the declaration
484
+ const cleanDeclaration = removeLeadingComments ( declaration ) . trim ( )
485
+
486
+ const functionPattern = / ^ \s * ( e x p o r t \s + ) ? ( a s y n c \s + ) ? f u n c t i o n \s * ( \* ) ? \s * ( [ ^ ( < \s ] + ) /
487
+ const functionMatch = cleanDeclaration . match ( functionPattern )
488
+
489
+ if ( ! functionMatch ) {
490
+ console . error ( 'Function name could not be extracted from declaration:' , declaration )
491
+ return {
492
+ name : '' ,
493
+ params : '' ,
494
+ returnType : 'void' ,
495
+ generics : '' ,
496
+ }
497
+ }
498
+
499
+ const name = functionMatch [ 4 ]
500
+ let rest = cleanDeclaration . slice ( cleanDeclaration . indexOf ( name ) + name . length ) . trim ( )
501
+
502
+ // Extract generics
503
+ let generics = ''
504
+ if ( rest . startsWith ( '<' ) ) {
505
+ const genericsResult = extractBalancedSymbols ( rest , '<' , '>' )
506
+ if ( genericsResult ) {
507
+ generics = genericsResult . content
508
+ rest = genericsResult . rest . trim ( )
509
+ }
510
+ }
511
+
512
+ // Extract parameters
513
+ let params = ''
514
+ if ( rest . startsWith ( '(' ) ) {
515
+ const paramsResult = extractBalancedSymbols ( rest , '(' , ')' )
516
+ if ( paramsResult ) {
517
+ params = paramsResult . content . slice ( 1 , - 1 ) . trim ( )
518
+ rest = paramsResult . rest . trim ( )
519
+ }
520
+ }
521
+
522
+ // Extract return type - keep it exactly as specified
523
+ let returnType = 'void'
524
+ if ( rest . startsWith ( ':' ) ) {
525
+ const match = rest . match ( / ^ : \s * ( [ ^ { ] + ) / )
526
+ if ( match ) {
527
+ returnType = match [ 1 ] . trim ( )
528
+ }
529
+ }
530
+
531
+ return {
532
+ name,
533
+ params,
534
+ returnType : normalizeType ( returnType ) ,
535
+ generics,
536
+ }
537
+ }
538
+
539
+ // export interface ImportTrackingState {
540
+ // typeImports: Map<string, Set<string>>
541
+ // valueImports: Map<string, Set<string>>
542
+ // usedTypes: Set<string>
543
+ // usedValues: Set<string>
544
+ // }
545
+
479
546
export default dts
0 commit comments