|
| 1 | +import type { Edit, SgNode } from '@codemod.com/jssg-types/main'; |
1 | 2 | import type { Transform } from 'codemod:ast-grep'; |
2 | 3 | import type TSX from 'codemod:ast-grep/langs/tsx'; |
3 | | -import type { Edit, SgNode } from '@codemod.com/jssg-types/main'; |
4 | 4 |
|
5 | 5 | const FUNCTIONS_TO_MAKE_ASYNC = new Set(['render', 'renderHook', 'act', 'fireEvent']); |
6 | 6 | const FIRE_EVENT_METHODS_TO_MAKE_ASYNC = new Set(['press', 'changeText', 'scroll']); |
@@ -241,10 +241,16 @@ function extractImportedFunctionNames( |
241 | 241 | edits: Edit[], |
242 | 242 | ): { |
243 | 243 | importedFunctions: Set<string>; |
244 | | - specifiersToRemove: Array<{ specifier: SgNode<TSX>; importStmt: SgNode<TSX> }>; |
| 244 | + specifiersToRemove: Array<{ |
| 245 | + specifier: SgNode<TSX>; |
| 246 | + importStmt: SgNode<TSX>; |
| 247 | + }>; |
245 | 248 | } { |
246 | 249 | const importedFunctions = new Set<string>(); |
247 | | - const specifiersToRemove: Array<{ specifier: SgNode<TSX>; importStmt: SgNode<TSX> }> = []; |
| 250 | + const specifiersToRemove: Array<{ |
| 251 | + specifier: SgNode<TSX>; |
| 252 | + importStmt: SgNode<TSX>; |
| 253 | + }> = []; |
248 | 254 |
|
249 | 255 | for (const importStmt of rntlImports) { |
250 | 256 | const importClause = importStmt.find({ |
@@ -332,7 +338,10 @@ function extractImportedFunctionNames( |
332 | 338 | * @param edits - Array to collect edit operations |
333 | 339 | */ |
334 | 340 | function removeDuplicateImportSpecifiers( |
335 | | - specifiersToRemove: Array<{ specifier: SgNode<TSX>; importStmt: SgNode<TSX> }>, |
| 341 | + specifiersToRemove: Array<{ |
| 342 | + specifier: SgNode<TSX>; |
| 343 | + importStmt: SgNode<TSX>; |
| 344 | + }>, |
336 | 345 | rootNode: SgNode<TSX>, |
337 | 346 | edits: Edit[], |
338 | 347 | ): void { |
@@ -464,11 +473,17 @@ function findFireEventMethodCalls( |
464 | 473 | for (const [asyncName, syncName] of ASYNC_FUNCTIONS_TO_RENAME.entries()) { |
465 | 474 | if (syncName === 'fireEvent') { |
466 | 475 | const wasImported = rntlImports.some((importStmt) => { |
467 | | - const importClause = importStmt.find({ rule: { kind: 'import_clause' } }); |
| 476 | + const importClause = importStmt.find({ |
| 477 | + rule: { kind: 'import_clause' }, |
| 478 | + }); |
468 | 479 | if (!importClause) return false; |
469 | | - const namedImports = importClause.find({ rule: { kind: 'named_imports' } }); |
| 480 | + const namedImports = importClause.find({ |
| 481 | + rule: { kind: 'named_imports' }, |
| 482 | + }); |
470 | 483 | if (!namedImports) return false; |
471 | | - const specifiers = namedImports.findAll({ rule: { kind: 'import_specifier' } }); |
| 484 | + const specifiers = namedImports.findAll({ |
| 485 | + rule: { kind: 'import_specifier' }, |
| 486 | + }); |
472 | 487 | return specifiers.some((spec) => { |
473 | 488 | const identifier = spec.find({ rule: { kind: 'identifier' } }); |
474 | 489 | return identifier && identifier.text() === asyncName; |
|
0 commit comments