@@ -119,83 +119,6 @@ export async function extract(filePath: string): Promise<string> {
119119 }
120120}
121121
122- /**
123- * Extracts content between balanced opening and closing symbols, handling nested structures.
124- *
125- * @param text - The input text to process
126- * @param openSymbol - The opening symbol (e.g., '<', '{', '(')
127- * @param closeSymbol - The closing symbol (e.g., '>', '}', ')')
128- * @returns An object containing the extracted content and remaining text, or null if no match
129- *
130- * @example
131- * extractBalancedSymbols('(a, b) => void', '(', ')')
132- * // Returns: { content: '(a, b)', rest: ' => void' }
133- *
134- * @example
135- * extractBalancedSymbols('<T extends Record<K, V>>(arg: T)', '<', '>')
136- * // Returns: { content: '<T extends Record<K, V>>', rest: '(arg: T)' }
137- */
138- function extractBalancedSymbols ( text : string , openSymbol : string , closeSymbol : string ) : BalancedSymbolResult | null {
139- if ( ! text . startsWith ( openSymbol ) ) {
140- return null
141- }
142-
143- let depth = 0
144- let pos = 0
145- let inString = false
146- let stringChar = ''
147- const content : string [ ] = [ ]
148-
149- for ( let i = 0 ; i < text . length ; i ++ ) {
150- const char = text [ i ]
151- const prevChar = i > 0 ? text [ i - 1 ] : ''
152-
153- // Handle string boundaries
154- if ( ( char === '"' || char === '\'' || char === '`' ) && prevChar !== '\\' ) {
155- if ( ! inString ) {
156- inString = true
157- stringChar = char
158- }
159- else if ( char === stringChar ) {
160- inString = false
161- }
162- }
163-
164- // Track depth when not in string
165- if ( ! inString ) {
166- if ( char === openSymbol || char === '{' || char === '<' || char === '(' )
167- depth ++
168- if ( char === closeSymbol || char === '}' || char === '>' || char === ')' )
169- depth --
170- }
171-
172- content . push ( char )
173- pos = i
174-
175- // Found matching closing symbol at correct depth
176- if ( depth === 0 && content . length > 0 && char === closeSymbol ) {
177- return {
178- content : content . join ( '' ) ,
179- rest : text . slice ( pos + 1 ) ,
180- }
181- }
182- }
183-
184- // If we reach here without finding a match, return the best effort match
185- if ( content . length > 0 ) {
186- // Add closing symbol if missing
187- if ( content [ content . length - 1 ] !== closeSymbol ) {
188- content . push ( closeSymbol )
189- }
190- return {
191- content : content . join ( '' ) ,
192- rest : text . slice ( pos + 1 ) ,
193- }
194- }
195-
196- return null
197- }
198-
199122/**
200123 * Processes TypeScript source code and generates declaration types
201124 * @param sourceCode - TypeScript source code
@@ -228,7 +151,7 @@ export function extractDtsTypes(sourceCode: string): string {
228151 } )
229152
230153 // Generate optimized imports based on actual output
231- const optimizedImports = generateOptimizedImports ( state . importTracking , state . dtsLines )
154+ const optimizedImports = generateOptimizedImports ( state . importTracking )
232155 // debugLog(state, 'import-summary', `Generated ${optimizedImports.length} optimized imports`)
233156
234157 // Clear any existing imports and set up dtsLines with optimized imports
@@ -354,7 +277,7 @@ function extractGenerics(rest: string): { generics: string, rest: string } {
354277 // If we hit zero depth and the next char is also '>', include both
355278 if ( depth === 0 && nextChar === '>' ) {
356279 buffer += '>>' // Add both closing brackets
357- pos = i + 1 // Skip the next '>' since we've included it
280+ pos = i + 1 // Skip the next '>' since we've included it
358281 debugLog ( undefined , 'generics-complete' , `Found double closing bracket at pos ${ i } , final buffer: ${ buffer } ` )
359282 break
360283 }
@@ -419,7 +342,7 @@ function extractParams(rest: string): { params: string, rest: string } {
419342 return { params, rest }
420343}
421344
422- function extractReturnType ( rest : string , declaration : string ) : { returnType : string } {
345+ function extractReturnType ( rest : string ) : { returnType : string } {
423346 let returnType = 'void'
424347 if ( rest . startsWith ( ':' ) ) {
425348 debugLog ( undefined , 'return-start' , `Starting return type extraction with: ${ rest } ` )
@@ -437,10 +360,9 @@ function extractReturnType(rest: string, declaration: string): { returnType: str
437360 while ( i < rest . length && ! foundEnd ) {
438361 const char = rest [ i ]
439362 const prevChar = i > 0 ? rest [ i - 1 ] : ''
440- const nextChar = i < rest . length - 1 ? rest [ i + 1 ] : ''
363+ // const nextChar = i < rest.length - 1 ? rest[i + 1] : ''
441364
442- debugLog ( undefined , 'return-char' ,
443- `Pos ${ i } : Char "${ char } ", Depth ${ depth } , InString ${ inString } , Buffer length ${ buffer . length } ` )
365+ debugLog ( undefined , 'return-char' , `Pos ${ i } : Char "${ char } ", Depth ${ depth } , InString ${ inString } , Buffer length ${ buffer . length } ` )
444366
445367 // Handle string boundaries
446368 if ( ( char === '"' || char === '\'' || char === '`' ) && prevChar !== '\\' ) {
@@ -542,7 +464,7 @@ function extractFunctionType(value: string): string | null {
542464/**
543465 * Generate optimized imports based on usage
544466 */
545- function generateOptimizedImports ( state : ImportTrackingState , dtsLines : string [ ] ) : string [ ] {
467+ function generateOptimizedImports ( state : ImportTrackingState ) : string [ ] {
546468 const imports : string [ ] = [ ]
547469
548470 // Generate type imports
@@ -1291,7 +1213,7 @@ function processFunctionBlock(cleanDeclaration: string, state: ProcessingState):
12911213 let signatureEnd = 0
12921214 let parenDepth = 0
12931215 let angleDepth = 0
1294- const braceDepth = 0
1216+ // const braceDepth = 0
12951217
12961218 for ( let i = 0 ; i < cleanDeclaration . length ; i ++ ) {
12971219 const char = cleanDeclaration [ i ]
0 commit comments