Skip to content

Commit

Permalink
Create new object instead of modifying existing expression (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 27, 2022
1 parent 27a2f24 commit d3f130c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-walls-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Create new object instead of modifying existing expression
16 changes: 6 additions & 10 deletions src/transforms/v2-to-v3/utils/replace/replaceClientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ export const replaceClientCreation = (
// Replace clients created with default module.
source
.find(j.NewExpression, getV2ClientNewExpression({ v2DefaultModuleName, v2ClientName }))
.replaceWith((nodePath) => {
const { node } = nodePath;
node.callee = j.identifier(v3ClientName);
return node;
});
.replaceWith((v2ClientNewExpression) =>
j.newExpression(j.identifier(v3ClientName), v2ClientNewExpression.node.arguments)
);

// Replace clients created with client module.
source
.find(j.NewExpression, getV2ClientNewExpression({ v2ClientName }))
.replaceWith((nodePath) => {
const { node } = nodePath;
node.callee = j.identifier(v3ClientName);
return node;
});
.replaceWith((v2ClientNewExpression) =>
j.newExpression(j.identifier(v3ClientName), v2ClientNewExpression.node.arguments)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ export const replaceTSTypeReference = (
right: { type: "Identifier", name: v2ClientName },
},
})
.replaceWith((tsTypeRef) => {
const { node } = tsTypeRef;
node.typeName = j.identifier(v3ClientName);
return node;
});
.replaceWith((v2ClientType) =>
j.tsTypeReference(j.identifier(v3ClientName), v2ClientType.node.typeParameters)
);

// Replace type reference to client input/output created with default module.
source
Expand Down

0 comments on commit d3f130c

Please sign in to comment.