Skip to content

Commit dbf3a3f

Browse files
authored
Remove promise calls when parentPath is CallExpression (#574)
1 parent fef89e4 commit dbf3a3f

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

.changeset/warm-flowers-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Remove promise calls when parentPath is CallExpression
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.DynamoDB();
4+
5+
const promiseArray = [];
6+
promiseArray.push(client.listTables().promise());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
2+
3+
const client = new DynamoDB();
4+
5+
const promiseArray = [];
6+
promiseArray.push(client.listTables());

src/transforms/v2-to-v3/apis/removePromiseForCallExpression.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export const removePromiseForCallExpression = (
55
j: JSCodeshift,
66
callExpression: ASTPath<CallExpression>
77
) => {
8-
switch (callExpression.parentPath.value.type) {
8+
const parentPathValue = Array.isArray(callExpression.parentPath.value)
9+
? callExpression.parentPath.value[0]
10+
: callExpression.parentPath.value;
11+
switch (parentPathValue.type) {
912
case "MemberExpression": {
1013
callExpression.parentPath.value.object = (
1114
callExpression.value.callee as MemberExpression
@@ -34,6 +37,7 @@ export const removePromiseForCallExpression = (
3437
// eslint-disable-next-line no-fallthrough
3538
case "ArrowFunctionExpression":
3639
case "AwaitExpression":
40+
case "CallExpression":
3741
case "ExpressionStatement":
3842
case "ObjectProperty":
3943
case "ReturnStatement":

0 commit comments

Comments
 (0)