@@ -59,6 +59,14 @@ interface ImportTrackingState {
59
59
usedValues : Set < string > // All used value names
60
60
}
61
61
62
+ interface MethodSignature {
63
+ name : string
64
+ async : boolean
65
+ generics : string
66
+ params : string
67
+ returnType : string
68
+ }
69
+
62
70
/**
63
71
* Regular expression patterns used throughout the module
64
72
* @remarks These patterns are optimized for performance and reliability
@@ -116,6 +124,7 @@ export interface PropertyInfo {
116
124
type : string
117
125
/** Nested property definitions */
118
126
nested ?: PropertyInfo [ ]
127
+ method ?: MethodSignature
119
128
}
120
129
121
130
/**
@@ -402,9 +411,22 @@ export function processLine(line: string, state: ProcessingState): void {
402
411
console . log ( 'Unprocessed line:' , trimmedLine )
403
412
}
404
413
405
- function processValue ( value : string ) : { type : string , nested ?: PropertyInfo [ ] } {
414
+ function processValue ( value : string ) : { type : string , nested ?: PropertyInfo [ ] , method ?: MethodSignature } {
406
415
const trimmed = value . trim ( )
407
416
417
+ // Handle method declarations
418
+ if ( trimmed . includes ( '(' ) && ! trimmed . startsWith ( '(' ) ) {
419
+ const methodSig = parseMethodSignature ( trimmed )
420
+ if ( methodSig ) {
421
+ const { async, generics, params, returnType } = methodSig
422
+ const genericPart = generics ? `<${ generics } >` : ''
423
+ const returnTypePart = returnType || 'void'
424
+ const type = `${ async ? 'async ' : '' } ${ genericPart } (${ params } ) => ${ returnTypePart } `
425
+ return { type, method : methodSig }
426
+ }
427
+ }
428
+
429
+ // Rest of the existing processValue logic...
408
430
if ( trimmed . startsWith ( '{' ) ) {
409
431
const nestedProperties = extractObjectProperties ( trimmed )
410
432
return {
@@ -1554,6 +1576,36 @@ export function parseObjectLiteral(objStr: string): PropertyInfo[] {
1554
1576
return extractObjectProperties ( content )
1555
1577
}
1556
1578
1579
+ function parseMethodSignature ( value : string ) : MethodSignature | null {
1580
+ // Match async methods
1581
+ const asyncMatch = value . match ( / ^ a s y n c \s + ( [ ^ < ( ] + ) (?: < ( [ ^ > ] + ) > ) ? \s * \( ( [ \s \S ] * ?) \) (?: \s * : \s * ( [ \s \S ] + ) ) ? $ / )
1582
+ if ( asyncMatch ) {
1583
+ const [ , name , generics , params , returnType ] = asyncMatch
1584
+ return {
1585
+ name,
1586
+ async : true ,
1587
+ generics : generics || '' ,
1588
+ params,
1589
+ returnType : returnType || 'Promise<void>' ,
1590
+ }
1591
+ }
1592
+
1593
+ // Match regular methods
1594
+ const methodMatch = value . match ( / ^ ( [ ^ < ( ] + ) (?: < ( [ ^ > ] + ) > ) ? \s * \( ( [ \s \S ] * ?) \) (?: \s * : \s * ( [ \s \S ] + ) ) ? $ / )
1595
+ if ( methodMatch ) {
1596
+ const [ , name , generics , params , returnType ] = methodMatch
1597
+ return {
1598
+ name,
1599
+ async : false ,
1600
+ generics : generics || '' ,
1601
+ params,
1602
+ returnType : returnType || 'void' ,
1603
+ }
1604
+ }
1605
+
1606
+ return null
1607
+ }
1608
+
1557
1609
/**
1558
1610
* Process object type literals
1559
1611
*/
@@ -2105,6 +2157,12 @@ export function formatObjectType(properties: PropertyInfo[]): string {
2105
2157
2106
2158
const formattedProps = properties
2107
2159
. map ( ( prop ) => {
2160
+ if ( prop . method ) {
2161
+ const { async, generics, params, returnType } = prop . method
2162
+ const genericPart = generics ? `<${ generics } >` : ''
2163
+ return `${ prop . key } ${ genericPart } (${ params } )${ returnType ? `: ${ returnType } ` : '' } `
2164
+ }
2165
+
2108
2166
const type = prop . nested ? formatNestedType ( prop . nested ) : prop . type
2109
2167
return `${ prop . key } : ${ type } `
2110
2168
} )
0 commit comments