Extract `export` names (ES/TS only) from file content. Imperfect but pragmatic.
(content: string)
| 138 | |
| 139 | /** Extract `export` names (ES/TS only) from file content. Imperfect but pragmatic. */ |
| 140 | function extractExports(content: string): { name: string; line: number }[] { |
| 141 | const out: { name: string; line: number }[] = []; |
| 142 | const lines = content.split('\n'); |
| 143 | const reExportNamed = /^\s*export\s+(?:async\s+)?(?:function|class|const|let|var|interface|type|enum)\s+([A-Za-z_$][\w$]*)/; |
| 144 | const reExportBlock = /^\s*export\s+\{([^}]+)\}/; |
| 145 | for (let i = 0; i < lines.length; i++) { |
| 146 | const line = lines[i]!; |
| 147 | const m1 = reExportNamed.exec(line); |
| 148 | if (m1) out.push({ name: m1[1]!, line: i + 1 }); |
| 149 | const m2 = reExportBlock.exec(line); |
| 150 | if (m2) { |
| 151 | for (const part of m2[1]!.split(',')) { |
| 152 | const name = part.trim().split(/\s+as\s+/)[0]!.trim(); |
| 153 | if (name) out.push({ name, line: i + 1 }); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | return out; |
| 158 | } |
| 159 | |
| 160 | /** Extract local (non-exported) function declarations. */ |
| 161 | function extractLocalFunctions(content: string): { name: string; line: number }[] { |