Skip to content

Commit 84c337a

Browse files
authored
Remove .promise() from API calls in variable declarator (#44)
1 parent cfb0110 commit 84c337a

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.changeset/curvy-emus-occur.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() from API calls in variable declarator
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.DynamoDB();
4+
5+
const listTablesPromise = client.listTables().promise();
6+
listTablesPromise
7+
.then((data) => console.log(data))
8+
.catch((err) => console.log(err, err.stack));
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
2+
3+
const client = new DynamoDB();
4+
5+
const listTablesPromise = client.listTables();
6+
listTablesPromise
7+
.then((data) => console.log(data))
8+
.catch((err) => console.log(err, err.stack));

src/transforms/v2-to-v3/utils/removePromiseCalls.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ export const removePromiseCalls = (
4343
})
4444
.forEach((callExpressionPath) => {
4545
switch (callExpressionPath.parentPath.value.type) {
46+
case "AwaitExpression":
47+
callExpressionPath.parentPath.value.argument = (
48+
callExpressionPath.value.callee as MemberExpression
49+
).object;
50+
break;
4651
case "MemberExpression":
4752
callExpressionPath.parentPath.value.object = (
4853
callExpressionPath.value.callee as MemberExpression
4954
).object;
5055
break;
51-
case "AwaitExpression":
52-
callExpressionPath.parentPath.value.argument = (
56+
case "VariableDeclarator":
57+
callExpressionPath.parentPath.value.init = (
5358
callExpressionPath.value.callee as MemberExpression
5459
).object;
5560
break;

0 commit comments

Comments
 (0)