-
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.
Add an empty param if value is not passed for optional params in call…
…back (#806)
- Loading branch information
Showing
5 changed files
with
42 additions
and
1 deletion.
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 | ||
--- | ||
|
||
Add an empty param if value is not passed for optional params in callback |
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
33 changes: 33 additions & 0 deletions
33
src/transforms/v2-to-v3/apis/addEmptyObjectForUndefined.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,33 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { ClientIdentifier } from "../types"; | ||
|
||
// Adds an empty object, if undefined is passed for optional parameters. | ||
export const addEmptyObjectForUndefined = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
clientIdentifiers: ClientIdentifier[] | ||
): void => { | ||
for (const clientId of clientIdentifiers) { | ||
// Remove .promise() from client API calls. | ||
source | ||
.find(j.CallExpression, { | ||
callee: { | ||
type: "MemberExpression", | ||
object: clientId, | ||
}, | ||
}) | ||
.filter((callExpression) => { | ||
return ( | ||
callExpression.value.arguments.length === 1 && | ||
["FunctionExpression", "ArrowFunctionExpression"].includes( | ||
callExpression.value.arguments[0].type | ||
) | ||
); | ||
}) | ||
.replaceWith((callExpression) => { | ||
callExpression.value.arguments.unshift(j.objectExpression([])); | ||
return callExpression.value; | ||
}); | ||
} | ||
}; |
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