@@ -119,83 +119,6 @@ export async function extract(filePath: string): Promise<string> {
119
119
}
120
120
}
121
121
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
-
199
122
/**
200
123
* Processes TypeScript source code and generates declaration types
201
124
* @param sourceCode - TypeScript source code
@@ -228,7 +151,7 @@ export function extractDtsTypes(sourceCode: string): string {
228
151
} )
229
152
230
153
// Generate optimized imports based on actual output
231
- const optimizedImports = generateOptimizedImports ( state . importTracking , state . dtsLines )
154
+ const optimizedImports = generateOptimizedImports ( state . importTracking )
232
155
// debugLog(state, 'import-summary', `Generated ${optimizedImports.length} optimized imports`)
233
156
234
157
// Clear any existing imports and set up dtsLines with optimized imports
@@ -354,7 +277,7 @@ function extractGenerics(rest: string): { generics: string, rest: string } {
354
277
// If we hit zero depth and the next char is also '>', include both
355
278
if ( depth === 0 && nextChar === '>' ) {
356
279
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
358
281
debugLog ( undefined , 'generics-complete' , `Found double closing bracket at pos ${ i } , final buffer: ${ buffer } ` )
359
282
break
360
283
}
@@ -419,7 +342,7 @@ function extractParams(rest: string): { params: string, rest: string } {
419
342
return { params, rest }
420
343
}
421
344
422
- function extractReturnType ( rest : string , declaration : string ) : { returnType : string } {
345
+ function extractReturnType ( rest : string ) : { returnType : string } {
423
346
let returnType = 'void'
424
347
if ( rest . startsWith ( ':' ) ) {
425
348
debugLog ( undefined , 'return-start' , `Starting return type extraction with: ${ rest } ` )
@@ -437,10 +360,9 @@ function extractReturnType(rest: string, declaration: string): { returnType: str
437
360
while ( i < rest . length && ! foundEnd ) {
438
361
const char = rest [ i ]
439
362
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] : ''
441
364
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 } ` )
444
366
445
367
// Handle string boundaries
446
368
if ( ( char === '"' || char === '\'' || char === '`' ) && prevChar !== '\\' ) {
@@ -542,7 +464,7 @@ function extractFunctionType(value: string): string | null {
542
464
/**
543
465
* Generate optimized imports based on usage
544
466
*/
545
- function generateOptimizedImports ( state : ImportTrackingState , dtsLines : string [ ] ) : string [ ] {
467
+ function generateOptimizedImports ( state : ImportTrackingState ) : string [ ] {
546
468
const imports : string [ ] = [ ]
547
469
548
470
// Generate type imports
@@ -1291,7 +1213,7 @@ function processFunctionBlock(cleanDeclaration: string, state: ProcessingState):
1291
1213
let signatureEnd = 0
1292
1214
let parenDepth = 0
1293
1215
let angleDepth = 0
1294
- const braceDepth = 0
1216
+ // const braceDepth = 0
1295
1217
1296
1218
for ( let i = 0 ; i < cleanDeclaration . length ; i ++ ) {
1297
1219
const char = cleanDeclaration [ i ]
0 commit comments