Skip to content

Commit a61eb1b

Browse files
authored
Rename getV2*Declaration to get*Declaration (#462)
1 parent 17581c0 commit a61eb1b

15 files changed

+75
-75
lines changed

src/transforms/v2-to-v3/client-names/getV2ClientNamesRecordFromImport.ts

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

33
import { CLIENT_NAMES, PACKAGE_NAME } from "../config";
4-
import { getImportEqualsDeclaration } from "../modules";
4+
import { getImportEqualsDeclarationType } from "../modules";
55
import { getImportSpecifiers } from "../modules";
66
import { getClientDeepImportPath } from "../utils";
77

@@ -37,7 +37,7 @@ export const getV2ClientNamesRecordFromImport = (
3737

3838
const identifiersFromImportEquals = source.find(
3939
j.TSImportEqualsDeclaration,
40-
getImportEqualsDeclaration(deepImportPath)
40+
getImportEqualsDeclarationType(deepImportPath)
4141
);
4242
if (identifiersFromImportEquals.length > 0) {
4343
v2ClientNamesRecord[clientName] = identifiersFromImportEquals.nodes()[0]?.id.name;

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

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

33
import { getDefaultLocalName } from "../utils";
4+
import { getImportDeclaration } from "./getImportDeclaration";
45
import { getImportSpecifiers } from "./getImportSpecifiers";
5-
import { getV2ImportDeclaration } from "./getV2ImportDeclaration";
66
import { ClientModulesOptions } from "./types";
77

88
export const addClientDefaultImport = (
@@ -29,7 +29,7 @@ export const addClientDefaultImport = (
2929
}
3030

3131
// Insert after global import, or service import.
32-
const v2ImportDeclaration = getV2ImportDeclaration(j, source, {
32+
const v2ImportDeclaration = getImportDeclaration(j, source, {
3333
v2ClientName,
3434
v2ClientLocalName,
3535
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Collection, JSCodeshift } from "jscodeshift";
22

33
import { getDefaultLocalName } from "../utils";
44
import { getImportEqualsDeclaration } from "./getImportEqualsDeclaration";
5+
import { getImportEqualsDeclarationType } from "./getImportEqualsDeclarationType";
56
import { getImportEqualsLocalNameSuffix } from "./getImportEqualsLocalNameSuffix";
6-
import { getV2ImportEqualsDeclaration } from "./getV2ImportEqualsDeclaration";
77
import { ClientModulesOptions } from "./types";
88

99
export const addClientDefaultImportEquals = (
@@ -15,7 +15,7 @@ export const addClientDefaultImportEquals = (
1515
const defaultLocalName = getDefaultLocalName(localNameSuffix);
1616
const existingImportEquals = source.find(
1717
j.TSImportEqualsDeclaration,
18-
getImportEqualsDeclaration(v3ClientPackageName)
18+
getImportEqualsDeclarationType(v3ClientPackageName)
1919
);
2020

2121
if (existingImportEquals.size()) {
@@ -29,7 +29,7 @@ export const addClientDefaultImportEquals = (
2929
}
3030

3131
// Insert after global, or service import equals.
32-
const v2ImportEqualsDeclaration = getV2ImportEqualsDeclaration(j, source, {
32+
const v2ImportEqualsDeclaration = getImportEqualsDeclaration(j, source, {
3333
v2ClientName,
3434
v2ClientLocalName,
3535
v2GlobalName,

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

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

33
import { getDefaultLocalName } from "../utils";
4+
import { getRequireDeclarator } from "./getRequireDeclarator";
45
import { getRequireDeclarators } from "./getRequireDeclarators";
5-
import { getV2RequireDeclarator } from "./getV2RequireDeclarator";
66
import { ClientModulesOptions } from "./types";
77

88
export const addClientDefaultRequire = (
@@ -29,7 +29,7 @@ export const addClientDefaultRequire = (
2929

3030
// prettier-ignore
3131
const v2RequireDeclarator =
32-
getV2RequireDeclarator(j, source, { v2ClientName, v2ClientLocalName, v2GlobalName });
32+
getRequireDeclarator(j, source, { v2ClientName, v2ClientLocalName, v2GlobalName });
3333

3434
const v3RequireDeclarator = j.variableDeclarator(
3535
j.identifier(defaultLocalName),

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

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

3+
import { getImportDeclaration } from "./getImportDeclaration";
34
import { getImportSpecifier } from "./getImportSpecifier";
45
import { getImportSpecifiers } from "./getImportSpecifiers";
5-
import { getV2ImportDeclaration } from "./getV2ImportDeclaration";
66
import { importSpecifierCompareFn } from "./importSpecifierCompareFn";
77
import { ClientModulesOptions, ImportSpecifierOptions } from "./types";
88

@@ -41,7 +41,7 @@ export const addClientNamedImport = (
4141
}
4242

4343
// Insert after global import, or service import.
44-
const v2ImportDeclaration = getV2ImportDeclaration(j, source, {
44+
const v2ImportDeclaration = getImportDeclaration(j, source, {
4545
v2ClientName,
4646
v2ClientLocalName,
4747
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Collection, JSCodeshift } from "jscodeshift";
22

33
import { getDefaultLocalName } from "../utils";
44
import { addClientDefaultImportEquals } from "./addClientDefaultImportEquals";
5-
import { getImportEqualsDeclaration } from "./getImportEqualsDeclaration";
5+
import { getImportEqualsDeclarationType } from "./getImportEqualsDeclarationType";
66
import { getImportEqualsLocalNameSuffix } from "./getImportEqualsLocalNameSuffix";
77
import { getRequireProperty } from "./getRequireProperty";
88
import { objectPatternPropertyCompareFn } from "./objectPatternPropertyCompareFn";
@@ -32,7 +32,7 @@ export const addClientNamedImportEquals = (
3232
return;
3333
}
3434

35-
const importEqualsDeclaration = getImportEqualsDeclaration(v3ClientPackageName);
35+
const importEqualsDeclaration = getImportEqualsDeclarationType(v3ClientPackageName);
3636
if (source.find(j.TSImportEqualsDeclaration, importEqualsDeclaration).size() === 0) {
3737
addClientDefaultImportEquals(j, source, v3ClientModulesOptions);
3838
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Collection, JSCodeshift, ObjectPattern, ObjectProperty, Property } from
22

33
import { OBJECT_PROPERTY_TYPE_LIST } from "../config";
44
import { getDefaultLocalName } from "../utils";
5+
import { getRequireDeclarator } from "./getRequireDeclarator";
56
import { getRequireDeclarators } from "./getRequireDeclarators";
67
import { getRequireDeclaratorsWithIdentifier } from "./getRequireDeclaratorsWithIdentifier";
78
import { getRequireProperty } from "./getRequireProperty";
8-
import { getV2RequireDeclarator } from "./getV2RequireDeclarator";
99
import { objectPatternPropertyCompareFn } from "./objectPatternPropertyCompareFn";
1010
import { ClientModulesOptions, RequirePropertyOptions } from "./types";
1111

@@ -75,7 +75,7 @@ export const addClientNamedRequire = (
7575

7676
// prettier-ignore
7777
const v2RequireDeclarator =
78-
getV2RequireDeclarator(j, source, { v2ClientName, v2ClientLocalName, v2GlobalName });
78+
getRequireDeclarator(j, source, { v2ClientName, v2ClientLocalName, v2GlobalName });
7979

8080
if (v2RequireDeclarator && v2RequireDeclarator.nodes().length > 0) {
8181
v2RequireDeclarator.insertAfter(v3RequireDeclarator);

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

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

33
import { PACKAGE_NAME } from "../config";
4-
import { getImportEqualsDeclaration } from "./getImportEqualsDeclaration";
4+
import { getImportEqualsDeclarationType } from "./getImportEqualsDeclarationType";
55
import { getImportSpecifiers } from "./getImportSpecifiers";
66
import { hasRequire } from "./hasRequire";
77

@@ -36,7 +36,7 @@ export const getGlobalNameFromModule = (
3636

3737
const importEqualsDeclarations = source.find(
3838
j.TSImportEqualsDeclaration,
39-
getImportEqualsDeclaration(PACKAGE_NAME)
39+
getImportEqualsDeclarationType(PACKAGE_NAME)
4040
);
4141

4242
if (importEqualsDeclarations.length > 0) {

src/transforms/v2-to-v3/modules/getV2ImportDeclaration.ts renamed to src/transforms/v2-to-v3/modules/getImportDeclaration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Collection, JSCodeshift } from "jscodeshift";
33
import { PACKAGE_NAME } from "../config";
44
import { getClientDeepImportPath } from "../utils";
55

6-
export interface GetV2ImportDeclarationOptions {
6+
export interface GetImportDeclarationOptions {
77
v2ClientName: string;
88
v2ClientLocalName: string;
99
}
1010

11-
export const getV2ImportDeclaration = (
11+
export const getImportDeclaration = (
1212
j: JSCodeshift,
1313
source: Collection<unknown>,
14-
{ v2ClientName, v2ClientLocalName }: GetV2ImportDeclarationOptions
14+
{ v2ClientName, v2ClientLocalName }: GetImportDeclarationOptions
1515
) =>
1616
// Return global or service import declaration.
1717
source.find(j.ImportDeclaration).filter((importDeclaration) => {
Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1-
import { TSImportEqualsDeclaration } from "jscodeshift";
2-
3-
export const getImportEqualsDeclaration = (expressionValue?: string) =>
4-
({
5-
type: "TSImportEqualsDeclaration",
6-
moduleReference: {
7-
type: "TSExternalModuleReference",
8-
expression: { type: "StringLiteral", ...(expressionValue && { value: expressionValue }) },
9-
},
10-
} as TSImportEqualsDeclaration);
1+
import { Collection, JSCodeshift, TSExternalModuleReference } from "jscodeshift";
2+
3+
import { PACKAGE_NAME } from "../config";
4+
import { getClientDeepImportPath } from "../utils";
5+
import { getImportEqualsDeclarationType } from "./getImportEqualsDeclarationType";
6+
7+
export interface GetImportEqualsDeclarationOptions {
8+
v2ClientName: string;
9+
v2ClientLocalName: string;
10+
v2GlobalName?: string;
11+
}
12+
13+
export const getImportEqualsDeclaration = (
14+
j: JSCodeshift,
15+
source: Collection<unknown>,
16+
{ v2ClientName, v2ClientLocalName, v2GlobalName }: GetImportEqualsDeclarationOptions
17+
) =>
18+
// Return global or service import declaration.
19+
source
20+
.find(j.TSImportEqualsDeclaration, getImportEqualsDeclarationType())
21+
.filter((importEqualsDeclaration) => {
22+
const identifierName = importEqualsDeclaration.value.id.name;
23+
const importEqualsModuleRef = importEqualsDeclaration.value
24+
.moduleReference as TSExternalModuleReference;
25+
const expressionValue = importEqualsModuleRef.expression.value;
26+
27+
if (expressionValue === PACKAGE_NAME && identifierName === v2GlobalName) {
28+
return true;
29+
}
30+
31+
if (
32+
expressionValue === getClientDeepImportPath(v2ClientName) &&
33+
identifierName === v2ClientLocalName
34+
) {
35+
return true;
36+
}
37+
38+
return false;
39+
});

0 commit comments

Comments
 (0)