Skip to content

Commit 5d24161

Browse files
authored
Remove utility getClientTSTypeRef (#470)
1 parent 191b89b commit 5d24161

File tree

5 files changed

+49
-75
lines changed

5 files changed

+49
-75
lines changed

src/transforms/v2-to-v3/modules/getClientTSTypeRefCount.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

3-
import { getClientTSTypeRef } from "../utils";
43
import { ClientModulesOptions } from "./types";
54

65
export const getClientTSTypeRefCount = (
@@ -11,17 +10,18 @@ export const getClientTSTypeRefCount = (
1110
let clientTSTypeRefCount = 0;
1211

1312
if (v2GlobalName) {
14-
const clienTSTypeRefFromGlobalName = source.find(
15-
j.TSTypeReference,
16-
getClientTSTypeRef({ v2ClientName, v2GlobalName })
17-
);
13+
const clienTSTypeRefFromGlobalName = source.find(j.TSTypeReference, {
14+
typeName: {
15+
left: { type: "Identifier", name: v2GlobalName },
16+
right: { type: "Identifier", name: v2ClientName },
17+
},
18+
});
1819
clientTSTypeRefCount += clienTSTypeRefFromGlobalName.length;
1920
}
2021

21-
const clienTSTypeRefFromClientLocalName = source.find(
22-
j.TSTypeReference,
23-
getClientTSTypeRef({ v2ClientLocalName })
24-
);
22+
const clienTSTypeRefFromClientLocalName = source.find(j.TSTypeReference, {
23+
typeName: { type: "Identifier", name: v2ClientLocalName },
24+
});
2525
clientTSTypeRefCount += clienTSTypeRefFromClientLocalName.length;
2626

2727
return clientTSTypeRefCount;

src/transforms/v2-to-v3/ts-type/getClientTypeNames.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Collection, Identifier, JSCodeshift, TSQualifiedName, TSTypeReference } from "jscodeshift";
22

33
import { getImportSpecifiers } from "../modules";
4-
import { getClientDeepImportPath, getClientTSTypeRef } from "../utils";
4+
import { getClientDeepImportPath } from "../utils";
55

66
export interface GetClientTypeNamesOptions {
77
v2ClientName: string;
88
v2GlobalName?: string;
99
v2ClientLocalName: string;
1010
}
1111

12+
type DeepPartial<T> = Partial<{ [P in keyof T]: DeepPartial<T[P]> }>;
13+
1214
const getRightIdentifierName = (
1315
j: JSCodeshift,
1416
source: Collection<unknown>,
15-
tsTypeRef: TSTypeReference
17+
tsTypeRef: DeepPartial<TSTypeReference>
1618
) =>
1719
source
1820
.find(j.TSTypeReference, tsTypeRef)
@@ -29,16 +31,25 @@ export const getClientTypeNames = (
2931
const clientTypeNames = [];
3032

3133
if (v2GlobalName) {
32-
const globalTSTypeRef = getClientTSTypeRef({
33-
v2ClientName,
34-
v2GlobalName,
35-
withoutRightSection: true,
36-
});
37-
clientTypeNames.push(...getRightIdentifierName(j, source, globalTSTypeRef));
34+
clientTypeNames.push(
35+
...getRightIdentifierName(j, source, {
36+
typeName: {
37+
left: {
38+
left: { type: "Identifier", name: v2GlobalName },
39+
right: { type: "Identifier", name: v2ClientName },
40+
},
41+
},
42+
})
43+
);
3844
}
3945

40-
const clientTSTypeRef = getClientTSTypeRef({ v2ClientLocalName, withoutRightSection: true });
41-
clientTypeNames.push(...getRightIdentifierName(j, source, clientTSTypeRef));
46+
clientTypeNames.push(
47+
...getRightIdentifierName(j, source, {
48+
typeName: {
49+
left: { type: "Identifier", name: v2ClientLocalName },
50+
},
51+
})
52+
);
4253

4354
clientTypeNames.push(
4455
...getImportSpecifiers(j, source, getClientDeepImportPath(v2ClientName))

src/transforms/v2-to-v3/ts-type/replaceTSTypeReference.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Collection, Identifier, JSCodeshift, TSQualifiedName, TSTypeReference } from "jscodeshift";
22

3-
import { getClientTSTypeRef } from "../utils";
43
import { getClientTypeNames } from "./getClientTypeNames";
54
import { getV3ClientTypeReference } from "./getV3ClientTypeReference";
65

@@ -28,17 +27,26 @@ export const replaceTSTypeReference = (
2827
// Replace type reference to client created with global name.
2928
if (v2GlobalName) {
3029
source
31-
.find(j.TSTypeReference, getClientTSTypeRef({ v2ClientName, v2GlobalName }))
30+
.find(j.TSTypeReference, {
31+
typeName: {
32+
left: { type: "Identifier", name: v2GlobalName },
33+
right: { type: "Identifier", name: v2ClientName },
34+
},
35+
})
3236
.replaceWith((v2ClientType) =>
3337
j.tsTypeReference(j.identifier(v3ClientName), v2ClientType.node.typeParameters)
3438
);
3539

3640
// Replace reference to client types created with global name.
3741
source
38-
.find(
39-
j.TSTypeReference,
40-
getClientTSTypeRef({ v2ClientName, v2GlobalName, withoutRightSection: true })
41-
)
42+
.find(j.TSTypeReference, {
43+
typeName: {
44+
left: {
45+
left: { type: "Identifier", name: v2GlobalName },
46+
right: { type: "Identifier", name: v2ClientName },
47+
},
48+
},
49+
})
4250
.filter((v2ClientType) => isRightSectionIdentifier(v2ClientType.node))
4351
.replaceWith((v2ClientType) => {
4452
const v2ClientTypeName = getRightIdentifierName(v2ClientType.node);
@@ -48,7 +56,11 @@ export const replaceTSTypeReference = (
4856

4957
// Replace reference to client types created with client module.
5058
source
51-
.find(j.TSTypeReference, getClientTSTypeRef({ v2ClientLocalName, withoutRightSection: true }))
59+
.find(j.TSTypeReference, {
60+
typeName: {
61+
left: { type: "Identifier", name: v2ClientLocalName },
62+
},
63+
})
5264
.filter((v2ClientType) => isRightSectionIdentifier(v2ClientType.node))
5365
.replaceWith((v2ClientType) => {
5466
const v2ClientTypeName = getRightIdentifierName(v2ClientType.node);

src/transforms/v2-to-v3/utils/getClientTSTypeRef.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from "./getClientDeepImportPath";
22
export * from "./getClientNewExpression";
3-
export * from "./getClientTSTypeRef";
43
export * from "./getDefaultLocalName";
54
export * from "./getDocClientNewExpression";
65
export * from "./isTypeScriptFile";

0 commit comments

Comments
 (0)