11import { ASTPath , Identifier , JSCodeshift , TSQualifiedName , TSTypeReference } from "jscodeshift" ;
2- import { addTsTypeQueryToRefType } from "./addTsTypeQueryToRefType" ;
32import { getV3ClientType } from "./getV3ClientType" ;
43
54const nativeTsRefTypes = [ "TSAnyKeyword" , "TSStringKeyword" , "TSNumberKeyword" , "TSBooleanKeyword" ] ;
6- const nativeTsUnionTypes = [ "Array" , "Record" ] ;
7- const nativeTsIdentifierTypes = [ "Date" , "Uint8Array" , ...nativeTsUnionTypes ] ;
5+ const nativeTsIdentifierTypes = [ "Date" , "Uint8Array" , "Array" , "Record" ] ;
86
97interface UpdateV2ClientTypeOptions {
108 v2ClientName : string ;
@@ -19,26 +17,17 @@ export const updateV2ClientType = (
1917) => {
2018 const v3ClientType = getV3ClientType ( j , options ) ;
2119
22- if ( v2ClientType . parentPath ?. value . type === "TSTypeQuery" ) {
23- if ( nativeTsRefTypes . includes ( v3ClientType . type ) ) {
24- v2ClientType . parentPath ?. replace ( v3ClientType ) ;
25- return ;
26- }
27-
28- if ( v3ClientType . type === "TSTypeReference" ) {
29- const v3ClientTypeRef = v3ClientType as TSTypeReference ;
30- if ( v3ClientTypeRef . typeName . type === "Identifier" ) {
31- const v3ClientTypeRefIdentifier = v3ClientTypeRef . typeName as Identifier ;
32- if ( nativeTsIdentifierTypes . includes ( v3ClientTypeRefIdentifier . name ) ) {
33- if ( nativeTsUnionTypes . includes ( v3ClientTypeRefIdentifier . name ) ) {
34- addTsTypeQueryToRefType ( j , v3ClientTypeRef ) ;
35- }
36- v2ClientType . parentPath ?. replace ( v3ClientType ) ;
37- return ;
38- }
39- }
40- }
20+ if (
21+ ( v2ClientType . parentPath ?. value . type === "TSTypeQuery" &&
22+ nativeTsRefTypes . includes ( v3ClientType . type ) ) ||
23+ ( v3ClientType . type === "TSTypeReference" &&
24+ ( v3ClientType as TSTypeReference ) . typeName . type === "Identifier" &&
25+ nativeTsIdentifierTypes . includes (
26+ ( ( v3ClientType as TSTypeReference ) . typeName as Identifier ) . name
27+ ) )
28+ ) {
29+ v2ClientType . parentPath ?. replace ( v3ClientType ) ;
30+ } else {
31+ v2ClientType . replace ( v3ClientType ) ;
4132 }
42-
43- v2ClientType . replace ( v3ClientType ) ;
4433} ;
0 commit comments