@@ -196,7 +196,7 @@ function extractFunctionSignature(declaration: string, verbose?: boolean | strin
196196 rest = restAfterGenerics . trim ( )
197197 debugLog ( 'signature-after-generics' , `Remaining content: ${ rest } ` , verbose )
198198
199- // Extract parameters
199+ // Extract parameters with full object type support
200200 const { params, rest : restAfterParams } = extractParams ( rest , verbose )
201201 rest = restAfterParams . trim ( )
202202 debugLog ( 'signature-after-params' , `Remaining content: ${ rest } ` , verbose )
@@ -205,10 +205,20 @@ function extractFunctionSignature(declaration: string, verbose?: boolean | strin
205205 const { returnType } = extractReturnType ( rest )
206206 debugLog ( 'signature-return' , `Extracted return type: ${ returnType } ` , verbose )
207207
208+ // Handle object parameter types
209+ let processedParams = params
210+ if ( params . includes ( '{' ) ) {
211+ const objectMatch = params . match ( / \{ ( [ ^ } ] + ) \} : \s * ( [ ^ ) ] + ) / )
212+ if ( objectMatch ) {
213+ const [ , paramList , typeRef ] = objectMatch
214+ processedParams = `{ ${ paramList } }: ${ typeRef } `
215+ }
216+ }
217+
208218 const signature = {
209219 name,
210220 generics,
211- params,
221+ params : processedParams ,
212222 returnType,
213223 }
214224
@@ -2046,12 +2056,89 @@ function processVariable(declaration: string, isExported: boolean, state: Proces
20462056 * Process function declarations with overloads
20472057 */
20482058function processFunction ( declaration : string , usedTypes ?: Set < string > , isExported = true , verbose ?: boolean | string [ ] ) : string {
2049- const normalizedDeclaration = declaration . trim ( ) . replace ( / \s + / g , ' ' )
2059+ const normalizedDeclaration = declaration . trim ( )
20502060 const signature = extractFunctionSignature ( normalizedDeclaration , verbose )
20512061
2052- // Clean up params
2062+ // Clean up all parameters - both object destructuring and regular parameters
20532063 if ( signature . params ) {
2054- signature . params = cleanParameterTypes ( signature . params )
2064+ // Handle regular parameters
2065+ if ( ! signature . params . includes ( '{' ) ) {
2066+ const cleanedParams = signature . params
2067+ . split ( ',' )
2068+ . map ( ( param ) => {
2069+ const paramTrimmed = param . trim ( )
2070+ if ( ! paramTrimmed )
2071+ return null
2072+
2073+ // Handle parameters with default values and type annotations
2074+ if ( paramTrimmed . includes ( '=' ) ) {
2075+ const [ paramPart ] = paramTrimmed . split ( / \s * = \s * / )
2076+ const paramWithoutDefault = paramPart . trim ( )
2077+
2078+ // If there's an explicit type annotation, use it
2079+ if ( paramWithoutDefault . includes ( ':' ) ) {
2080+ const [ paramName , paramType ] = paramWithoutDefault . split ( ':' ) . map ( p => p . trim ( ) )
2081+ return `${ paramName } ?: ${ paramType } `
2082+ }
2083+
2084+ // Infer type from default value if no explicit type
2085+ const defaultValue = paramTrimmed . split ( / \s * = \s * / ) [ 1 ] . trim ( )
2086+ const inferredType = defaultValue === '{}'
2087+ ? paramTrimmed . includes ( ':' ) ? paramTrimmed . split ( ':' ) [ 1 ] . trim ( ) . split ( '=' ) [ 0 ] . trim ( ) : 'Record<string, unknown>'
2088+ : defaultValue === ''
2089+ ? 'string'
2090+ : typeof eval ( defaultValue )
2091+
2092+ return `${ paramWithoutDefault } ?: ${ inferredType } `
2093+ }
2094+
2095+ // Handle parameters without default values
2096+ if ( paramTrimmed . includes ( ':' ) ) {
2097+ const [ paramName , paramType ] = paramTrimmed . split ( ':' ) . map ( p => p . trim ( ) )
2098+ const isOptional = paramName . endsWith ( '?' )
2099+ const cleanName = paramName . replace ( / \? $ / , '' )
2100+ return `${ cleanName } ${ isOptional ? '?' : '' } : ${ paramType } `
2101+ }
2102+
2103+ return paramTrimmed
2104+ } )
2105+ . filter ( Boolean )
2106+ . join ( ', ' )
2107+
2108+ signature . params = cleanedParams
2109+ }
2110+ // Handle object destructuring (existing code)
2111+ else {
2112+ const paramMatch = declaration . match ( / \{ ( [ ^ } ] + ) \} : \s * ( [ ^ ) ] + ) / )
2113+ if ( paramMatch ) {
2114+ const [ , paramList , typeRef ] = paramMatch
2115+
2116+ const cleanedParams = paramList
2117+ . split ( ',' )
2118+ . map ( ( param ) => {
2119+ const paramTrimmed = param . trim ( )
2120+ if ( ! paramTrimmed )
2121+ return null
2122+
2123+ const hasDefaultValue = paramTrimmed . includes ( '=' )
2124+ const [ paramName ] = paramTrimmed . split ( / \s * = \s * / )
2125+ const nameOnly = paramName . trim ( )
2126+
2127+ const isOptional = hasDefaultValue || nameOnly . endsWith ( '?' )
2128+ const cleanName = nameOnly . replace ( / \? $ / , '' )
2129+
2130+ if ( cleanName . includes ( ':' ) ) {
2131+ const [ name , type ] = cleanName . split ( ':' ) . map ( p => p . trim ( ) )
2132+ return `${ name } ${ isOptional ? '?' : '' } : ${ type } `
2133+ }
2134+
2135+ return `${ cleanName } ${ isOptional ? '?' : '' } `
2136+ } )
2137+ . filter ( Boolean )
2138+
2139+ signature . params = `{ ${ cleanedParams . join ( ', ' ) } }: ${ typeRef . trim ( ) } `
2140+ }
2141+ }
20552142 }
20562143
20572144 // Preserve type predicates and complete return types
0 commit comments