( source: ts.SourceFile, migrated: ReadonlySet<string>, aliases: ReadonlyMap<string, string>, )
| 217 | * origin) is in the migrated set. Rewrites to `<LocalName>.make(...)` so |
| 218 | * the local binding stays consistent. */ |
| 219 | const findConstructorCalls = ( |
| 220 | source: ts.SourceFile, |
| 221 | migrated: ReadonlySet<string>, |
| 222 | aliases: ReadonlyMap<string, string>, |
| 223 | ): Edit[] => { |
| 224 | const edits: Edit[] = []; |
| 225 | const visit = (node: ts.Node) => { |
| 226 | if (ts.isNewExpression(node) && ts.isIdentifier(node.expression)) { |
| 227 | const localName = node.expression.text; |
| 228 | const importedName = aliases.get(localName) ?? localName; |
| 229 | if (migrated.has(importedName)) { |
| 230 | const startOfNew = node.getStart(source); |
| 231 | const expressionEnd = node.expression.getEnd(); |
| 232 | // Replace `new ClassName` with `ClassName.make` using the local |
| 233 | // binding name so the rewrite respects `import { X as Y }`. |
| 234 | edits.push({ |
| 235 | start: startOfNew, |
| 236 | end: expressionEnd, |
| 237 | replacement: `${localName}.make`, |
| 238 | }); |
| 239 | } |
| 240 | } |
| 241 | ts.forEachChild(node, visit); |
| 242 | }; |
| 243 | visit(source); |
| 244 | return edits; |
| 245 | }; |
| 246 | |
| 247 | const applyEdits = (text: string, edits: Edit[]): string => { |
| 248 | // Apply in reverse order so positions stay valid. |
no test coverage detected