-
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
.promise()
from client API request stored in a variable (#184)
- Loading branch information
Showing
7 changed files
with
96 additions
and
29 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 | ||
--- | ||
|
||
Remove .promise() from client API request stored in a variable. |
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
31 changes: 31 additions & 0 deletions
31
src/transforms/v2-to-v3/utils/remove/removePromiseForCallExpression.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,31 @@ | ||
import { ASTPath, CallExpression, MemberExpression } from "jscodeshift"; | ||
|
||
export const removePromiseForCallExpression = (callExpression: ASTPath<CallExpression>) => { | ||
switch (callExpression.parentPath.value.type) { | ||
case "AwaitExpression": | ||
callExpression.parentPath.value.argument = ( | ||
callExpression.value.callee as MemberExpression | ||
).object; | ||
break; | ||
case "MemberExpression": | ||
callExpression.parentPath.value.object = ( | ||
callExpression.value.callee as MemberExpression | ||
).object; | ||
break; | ||
case "VariableDeclarator": | ||
callExpression.parentPath.value.init = ( | ||
callExpression.value.callee as MemberExpression | ||
).object; | ||
break; | ||
case "ArrowFunctionExpression": | ||
case "ReturnStatement": | ||
callExpression.value.callee = ( | ||
(callExpression.value.callee as MemberExpression).object as CallExpression | ||
).callee; | ||
break; | ||
default: | ||
throw new Error( | ||
`Removal of .promise() not implemented for ${callExpression.parentPath.value.type}` | ||
); | ||
} | ||
}; |