@@ -11,7 +11,7 @@ const { findTSTypeReferenceCollections } = require("./jscodeshift-bugfixes");
1111 * @returns {boolean }
1212 */
1313function renameType ( j , ast , sourceIdentifier , targetIdentifier ) {
14- return replaceType (
14+ return replaceReactType (
1515 j ,
1616 ast ,
1717 sourceIdentifier ,
@@ -47,7 +47,7 @@ function renameType(j, ast, sourceIdentifier, targetIdentifier) {
4747 * @param {(sourcePath: import("jscodeshift").TSTypeReference) => import("jscodeshift").TSTypeReference | import("jscodeshift").TSUnionType } buildTargetTypeReference
4848 * @param {string | null } addedType - `null` if no type was added
4949 */
50- function replaceType (
50+ function replaceReactType (
5151 j ,
5252 ast ,
5353 sourceIdentifier ,
@@ -66,15 +66,19 @@ function replaceType(
6666 ( local == null || local . name === addedType )
6767 ) ;
6868 } ) ;
69- const sourceIdentifierImports = ast . find ( j . ImportSpecifier , ( node ) => {
70- const { imported, local } = node ;
71- return (
72- imported . type === "Identifier" &&
73- imported . name === sourceIdentifier &&
74- // We don't support renames generally, so we don't handle them here
75- ( local == null || local . name === sourceIdentifier )
76- ) ;
77- } ) ;
69+ const sourceIdentifierImports = ast
70+ . find ( j . ImportDeclaration , ( declaration ) => {
71+ return declaration . source . value === "react" ;
72+ } )
73+ . find ( j . ImportSpecifier , ( node ) => {
74+ const { imported, local } = node ;
75+ return (
76+ imported . type === "Identifier" &&
77+ imported . name === sourceIdentifier &&
78+ // We don't support renames generally, so we don't handle them here
79+ ( local == null || local . name === sourceIdentifier )
80+ ) ;
81+ } ) ;
7882 if ( sourceIdentifierImports . length > 0 ) {
7983 hasChanges = true ;
8084
@@ -120,4 +124,4 @@ function replaceType(
120124 return hasChanges ;
121125}
122126
123- module . exports = { replaceType , renameType } ;
127+ module . exports = { replaceReactType , renameType } ;
0 commit comments