Skip to content

Commit

Permalink
Remove .promise() from API calls in variable declarator (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Mar 7, 2022
1 parent cfb0110 commit 84c337a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-emus-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Remove .promise() from API calls in variable declarator
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AWS from "aws-sdk";

const client = new AWS.DynamoDB();

const listTablesPromise = client.listTables().promise();
listTablesPromise
.then((data) => console.log(data))
.catch((err) => console.log(err, err.stack));

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const client = new DynamoDB();

const listTablesPromise = client.listTables();
listTablesPromise
.then((data) => console.log(data))
.catch((err) => console.log(err, err.stack));
9 changes: 7 additions & 2 deletions src/transforms/v2-to-v3/utils/removePromiseCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ export const removePromiseCalls = (
})
.forEach((callExpressionPath) => {
switch (callExpressionPath.parentPath.value.type) {
case "AwaitExpression":
callExpressionPath.parentPath.value.argument = (
callExpressionPath.value.callee as MemberExpression
).object;
break;
case "MemberExpression":
callExpressionPath.parentPath.value.object = (
callExpressionPath.value.callee as MemberExpression
).object;
break;
case "AwaitExpression":
callExpressionPath.parentPath.value.argument = (
case "VariableDeclarator":
callExpressionPath.parentPath.value.init = (
callExpressionPath.value.callee as MemberExpression
).object;
break;
Expand Down

0 comments on commit 84c337a

Please sign in to comment.