Skip to content

Commit

Permalink
Remove promise calls when parentPath is CallExpression (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Sep 7, 2023
1 parent fef89e4 commit dbf3a3f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/warm-flowers-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Remove promise calls when parentPath is CallExpression
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import AWS from "aws-sdk";

const client = new AWS.DynamoDB();

const promiseArray = [];
promiseArray.push(client.listTables().promise());
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const client = new DynamoDB();

const promiseArray = [];
promiseArray.push(client.listTables());
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export const removePromiseForCallExpression = (
j: JSCodeshift,
callExpression: ASTPath<CallExpression>
) => {
switch (callExpression.parentPath.value.type) {
const parentPathValue = Array.isArray(callExpression.parentPath.value)
? callExpression.parentPath.value[0]
: callExpression.parentPath.value;
switch (parentPathValue.type) {
case "MemberExpression": {
callExpression.parentPath.value.object = (
callExpression.value.callee as MemberExpression
Expand Down Expand Up @@ -34,6 +37,7 @@ export const removePromiseForCallExpression = (
// eslint-disable-next-line no-fallthrough
case "ArrowFunctionExpression":
case "AwaitExpression":
case "CallExpression":
case "ExpressionStatement":
case "ObjectProperty":
case "ReturnStatement":
Expand Down

0 comments on commit dbf3a3f

Please sign in to comment.