Extract local (non-exported) function declarations.
(content: string)
| 159 | |
| 160 | /** Extract local (non-exported) function declarations. */ |
| 161 | function extractLocalFunctions(content: string): { name: string; line: number }[] { |
| 162 | const out: { name: string; line: number }[] = []; |
| 163 | const lines = content.split('\n'); |
| 164 | const reLocal = /^\s*(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/; |
| 165 | const reArrow = /^\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?\(/; |
| 166 | for (let i = 0; i < lines.length; i++) { |
| 167 | const line = lines[i]!; |
| 168 | // Skip exports — those are covered by extractExports |
| 169 | if (/^\s*export\s/.test(line)) continue; |
| 170 | const m1 = reLocal.exec(line); |
| 171 | if (m1) out.push({ name: m1[1]!, line: i + 1 }); |
| 172 | const m2 = reArrow.exec(line); |
| 173 | if (m2) out.push({ name: m2[1]!, line: i + 1 }); |
| 174 | } |
| 175 | return out; |
| 176 | } |
| 177 | |
| 178 | export class FindDeadCodeTool extends Tool<z.infer<typeof FindDeadCodeArgs>> { |
| 179 | name = 'find_dead_code'; |