-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use filter API to delete identifiers from require object pattern (#322)
- Loading branch information
Showing
14 changed files
with
127 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Use filter API to delete identifiers from require object pattern |
20 changes: 18 additions & 2 deletions
20
scripts/generateNewClientTests/getServiceRequireDeepOutput.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,3 +1,19 @@ | ||
import { getServiceRequireOutput } from "./getServiceRequireOutput"; | ||
import { CLIENT_NAMES_MAP, CLIENT_PACKAGE_NAMES_MAP } from "../../src/transforms/v2-to-v3/config"; | ||
import { CLIENTS_TO_TEST } from "./config"; | ||
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode"; | ||
|
||
export const getServiceRequireDeepOutput = getServiceRequireOutput; | ||
export const getServiceRequireDeepOutput = (codegenComment: string) => { | ||
let serviceRequireDeepOutputContent = `${codegenComment}\n`; | ||
|
||
for (const v2ClientName of CLIENTS_TO_TEST) { | ||
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName]; | ||
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`; | ||
const v3RequireKeyValuePair = | ||
v3ClientName === v2ClientName ? v3ClientName : `${v3ClientName}: ${v2ClientName}`; | ||
serviceRequireDeepOutputContent += `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`; | ||
} | ||
serviceRequireDeepOutputContent += `\n`; | ||
serviceRequireDeepOutputContent += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST); | ||
|
||
return serviceRequireDeepOutputContent; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,3 @@ | ||
import { CLIENT_NAMES_MAP, CLIENT_PACKAGE_NAMES_MAP } from "../../src/transforms/v2-to-v3/config"; | ||
import { CLIENTS_TO_TEST } from "./config"; | ||
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode"; | ||
import { getGlobalRequireOutput } from "./getGlobalRequireOutput"; | ||
|
||
export const getServiceRequireOutput = (codegenComment: string) => { | ||
let serviceRequireOutputContent = `${codegenComment}\n`; | ||
|
||
for (const v2ClientName of CLIENTS_TO_TEST) { | ||
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName]; | ||
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`; | ||
const v3RequireKeyValuePair = | ||
v3ClientName === v2ClientName ? v3ClientName : `${v3ClientName}: ${v2ClientName}`; | ||
serviceRequireOutputContent += `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`; | ||
} | ||
serviceRequireOutputContent += `\n`; | ||
serviceRequireOutputContent += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST); | ||
|
||
return serviceRequireOutputContent; | ||
}; | ||
export const getServiceRequireOutput = getGlobalRequireOutput; |
4 changes: 1 addition & 3 deletions
4
src/transforms/v2-to-v3/__fixtures__/new-client/service-require.input.js
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
8 changes: 3 additions & 5 deletions
8
.../modules/getRequireVariableDeclarators.ts → ...v2-to-v3/modules/getRequireDeclarators.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
20 changes: 20 additions & 0 deletions
20
src/transforms/v2-to-v3/modules/getRequireDeclaratorsWithIdentifier.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { getRequireDeclarators } from "./getRequireDeclarators"; | ||
|
||
export interface GetRequireDeclaratorsWithIdentifier { | ||
identifierName: string; | ||
sourceValue: string; | ||
} | ||
|
||
export const getRequireDeclaratorsWithIdentifier = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
{ identifierName, sourceValue }: GetRequireDeclaratorsWithIdentifier | ||
) => | ||
getRequireDeclarators(j, source, sourceValue).filter((declarator) => { | ||
if (declarator.value.id.type !== "Identifier") { | ||
return false; | ||
} | ||
return declarator.value.id.name === identifierName; | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/transforms/v2-to-v3/modules/getRequireDeclaratorsWithObjectPattern.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { getRequireDeclarators } from "./getRequireDeclarators"; | ||
|
||
export interface GetRequireDeclaratorsWithObjectPattern { | ||
identifierName: string; | ||
sourceValue: string; | ||
} | ||
|
||
export const getRequireDeclaratorsWithObjectPattern = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
{ identifierName, sourceValue }: GetRequireDeclaratorsWithObjectPattern | ||
) => | ||
getRequireDeclarators(j, source, sourceValue).filter((declarator) => { | ||
if (declarator.value.id.type !== "ObjectPattern") { | ||
return false; | ||
} | ||
const { properties } = declarator.value.id; | ||
return properties.some( | ||
(property) => | ||
(property.type === "Property" || property.type === "ObjectProperty") && | ||
property.value.type === "Identifier" && | ||
property.value.name === identifierName | ||
); | ||
}); |
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