(source: ts.SourceFile)
| 158 | |
| 159 | /** Find all migrate-able ClassDeclarations in a file. */ |
| 160 | const findClassDecls = (source: ts.SourceFile): ClassDeclInfo[] => { |
| 161 | const out: ClassDeclInfo[] = []; |
| 162 | const visit = (node: ts.Node) => { |
| 163 | if (ts.isClassDeclaration(node) && node.heritageClauses && node.name) { |
| 164 | const extendsClause = node.heritageClauses.find( |
| 165 | (c) => c.token === ts.SyntaxKind.ExtendsKeyword, |
| 166 | ); |
| 167 | if (extendsClause && extendsClause.types.length === 1) { |
| 168 | const parsed = parseSchemaClassExtends(extendsClause.types[0].expression); |
| 169 | if (parsed) { |
| 170 | // Only handle classes with empty bodies — anything with custom methods |
| 171 | // needs human attention. |
| 172 | if (node.members.length > 0) { |
| 173 | console.warn( |
| 174 | ` ⚠ ${node.name.text} has ${node.members.length} member(s); skipping (manual review)`, |
| 175 | ); |
| 176 | } else { |
| 177 | const isExported = |
| 178 | node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false; |
| 179 | out.push({ |
| 180 | name: node.name.text, |
| 181 | kind: parsed.kind, |
| 182 | identifier: parsed.identifier, |
| 183 | fieldsText: parsed.fieldsText, |
| 184 | isExported, |
| 185 | fullStart: node.getStart(source), |
| 186 | end: node.getEnd(), |
| 187 | }); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | ts.forEachChild(node, visit); |
| 193 | }; |
| 194 | visit(source); |
| 195 | return out; |
| 196 | }; |
| 197 | |
| 198 | /** Collect a per-file map from local binding name → original imported name, |
| 199 | * so `import { X as Y }` resolves Y back to X for the migrated-name check. */ |
no test coverage detected