Skip to content

Commit bdf04b8

Browse files
authored
Transform AWS.util.copy (#586)
1 parent 2515ffc commit bdf04b8

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

.changeset/bright-hats-obey.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+
Transform AWS.util.copy
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AWS from "aws-sdk";
2+
3+
const clone = AWS.util.copy({ foo: "bar" });
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const clone = Object.assign({}, { foo: "bar" });
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Collection, JSCodeshift } from "jscodeshift";
2+
import { getAwsUtilCallExpression } from "./getAwsUtilCallExpression";
3+
4+
export const replaceAwsUtilCopy = (
5+
j: JSCodeshift,
6+
source: Collection<unknown>,
7+
v2GlobalName: string
8+
) => {
9+
getAwsUtilCallExpression(j, source, { v2GlobalName, functionName: "copy" })
10+
.filter(({ node }) => node.arguments.length === 1)
11+
.replaceWith(({ node }) => {
12+
const objectAssign = j.memberExpression(j.identifier("Object"), j.identifier("assign"));
13+
return j.callExpression(objectAssign, [j.objectExpression([]), node.arguments[0]]);
14+
});
15+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22
import { replaceAwsUtilArrayFunctions } from "./replaceAwsUtilArrayFunctions";
3+
import { replaceAwsUtilCopy } from "./replaceAwsUtilCopy";
34

45
export const replaceAwsUtilFunctions = (
56
j: JSCodeshift,
67
source: Collection<unknown>,
78
v2GlobalName?: string
89
) => {
910
if (!v2GlobalName) return;
11+
1012
replaceAwsUtilArrayFunctions(j, source, v2GlobalName);
13+
replaceAwsUtilCopy(j, source, v2GlobalName);
1114
};

0 commit comments

Comments
 (0)