-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove passing and using importType in leaf functions
- Loading branch information
Showing
16 changed files
with
41 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 4 additions & 20 deletions
24
src/transforms/v2-to-v3/client-instances/replaceClientCreation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,32 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { ImportType } from "../modules"; | ||
import { getV3ClientTypeName } from "../ts-type"; | ||
import { getClientNewExpression } from "../utils"; | ||
|
||
export interface ReplaceClientCreationOptions { | ||
v2ClientName: string; | ||
v2ClientLocalName: string; | ||
v2GlobalName?: string; | ||
v3ClientName: string; | ||
importType: ImportType; | ||
} | ||
|
||
// Replace v2 client creation with v3 client creation. | ||
export const replaceClientCreation = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
{ | ||
v2ClientName, | ||
v2ClientLocalName, | ||
v2GlobalName, | ||
v3ClientName, | ||
importType, | ||
}: ReplaceClientCreationOptions | ||
{ v2ClientName, v2ClientLocalName, v2GlobalName, v3ClientName }: ReplaceClientCreationOptions | ||
): void => { | ||
const clientName = | ||
importType === ImportType.IMPORT_EQUALS || v2ClientName === v2ClientLocalName | ||
? v3ClientName | ||
: v2ClientLocalName; | ||
const clientLocalName = | ||
importType === ImportType.IMPORT_EQUALS ? v2ClientName : v2ClientLocalName; | ||
const v3ClientConstructor = getV3ClientTypeName(clientName, clientLocalName, importType); | ||
const clientName = v2ClientName === v2ClientLocalName ? v3ClientName : v2ClientLocalName; | ||
|
||
if (v2GlobalName) { | ||
source | ||
.find(j.NewExpression, getClientNewExpression({ v2GlobalName, v2ClientName })) | ||
.replaceWith((v2ClientNewExpression) => | ||
j.newExpression(j.identifier(v3ClientConstructor), v2ClientNewExpression.node.arguments) | ||
j.newExpression(j.identifier(clientName), v2ClientNewExpression.node.arguments) | ||
); | ||
} | ||
|
||
source | ||
.find(j.NewExpression, getClientNewExpression({ v2ClientName, v2ClientLocalName })) | ||
.replaceWith((v2ClientNewExpression) => | ||
j.newExpression(j.identifier(v3ClientConstructor), v2ClientNewExpression.node.arguments) | ||
j.newExpression(j.identifier(clientName), v2ClientNewExpression.node.arguments) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.