Skip to content

Commit d3f130c

Browse files
authored
Create new object instead of modifying existing expression (#228)
1 parent 27a2f24 commit d3f130c

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

.changeset/great-walls-begin.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+
Create new object instead of modifying existing expression

src/transforms/v2-to-v3/utils/replace/replaceClientCreation.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ export const replaceClientCreation = (
1717
// Replace clients created with default module.
1818
source
1919
.find(j.NewExpression, getV2ClientNewExpression({ v2DefaultModuleName, v2ClientName }))
20-
.replaceWith((nodePath) => {
21-
const { node } = nodePath;
22-
node.callee = j.identifier(v3ClientName);
23-
return node;
24-
});
20+
.replaceWith((v2ClientNewExpression) =>
21+
j.newExpression(j.identifier(v3ClientName), v2ClientNewExpression.node.arguments)
22+
);
2523

2624
// Replace clients created with client module.
2725
source
2826
.find(j.NewExpression, getV2ClientNewExpression({ v2ClientName }))
29-
.replaceWith((nodePath) => {
30-
const { node } = nodePath;
31-
node.callee = j.identifier(v3ClientName);
32-
return node;
33-
});
27+
.replaceWith((v2ClientNewExpression) =>
28+
j.newExpression(j.identifier(v3ClientName), v2ClientNewExpression.node.arguments)
29+
);
3430
};

src/transforms/v2-to-v3/utils/replace/replaceTSTypeReference.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ export const replaceTSTypeReference = (
5151
right: { type: "Identifier", name: v2ClientName },
5252
},
5353
})
54-
.replaceWith((tsTypeRef) => {
55-
const { node } = tsTypeRef;
56-
node.typeName = j.identifier(v3ClientName);
57-
return node;
58-
});
54+
.replaceWith((v2ClientType) =>
55+
j.tsTypeReference(j.identifier(v3ClientName), v2ClientType.node.typeParameters)
56+
);
5957

6058
// Replace type reference to client input/output created with default module.
6159
source

0 commit comments

Comments
 (0)