File tree Expand file tree Collapse file tree 4 files changed +39
-3
lines changed
Expand file tree Collapse file tree 4 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " aws-sdk-js-codemod " : patch
3+ ---
4+
5+ Remove .promise() from API calls which use await
Original file line number Diff line number Diff line change 1+ import AWS from "aws-sdk" ;
2+
3+ const client = new AWS . DynamoDB ( ) ;
4+ try {
5+ const data = await client . listTables ( ) . promise ( ) ;
6+ console . log ( data ) ;
7+ } catch ( err ) {
8+ console . log ( err , err . stack ) ;
9+ }
Original file line number Diff line number Diff line change 1+ import { DynamoDB } from "@aws-sdk/client-dynamodb" ;
2+
3+ const client = new DynamoDB ( ) ;
4+ try {
5+ const data = await client . listTables ( ) ;
6+ console . log ( data ) ;
7+ } catch ( err ) {
8+ console . log ( err , err . stack ) ;
9+ }
Original file line number Diff line number Diff line change @@ -42,9 +42,22 @@ export const removePromiseCalls = (
4242 } ,
4343 } )
4444 . forEach ( ( callExpressionPath ) => {
45- callExpressionPath . parentPath . value . object = (
46- callExpressionPath . value . callee as MemberExpression
47- ) . object ;
45+ switch ( callExpressionPath . parentPath . value . type ) {
46+ case "MemberExpression" :
47+ callExpressionPath . parentPath . value . object = (
48+ callExpressionPath . value . callee as MemberExpression
49+ ) . object ;
50+ break ;
51+ case "AwaitExpression" :
52+ callExpressionPath . parentPath . value . argument = (
53+ callExpressionPath . value . callee as MemberExpression
54+ ) . object ;
55+ break ;
56+ default :
57+ throw new Error (
58+ `Removal of .promise() not implemented for ${ callExpressionPath . parentPath . value . type } `
59+ ) ;
60+ }
4861 } ) ;
4962 } ) ;
5063} ;
You can’t perform that action at this time.
0 commit comments