Skip to content

Commit 0542a8c

Browse files
authored
Check for NewExpression on v2ClientLocalName (#303)
1 parent 538c7a5 commit 0542a8c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ export const getV2ClientIdNamesFromNewExpr = (
4343
const namesFromServiceModule = [];
4444

4545
for (const getNames of [getNamesFromVariableDeclarator, getNamesFromAssignmentPattern]) {
46-
namesFromGlobalModule.push(
47-
...getNames(j, source, getV2ClientNewExpression({ v2GlobalName, v2ClientName }))
48-
);
46+
if (v2GlobalName) {
47+
namesFromGlobalModule.push(
48+
...getNames(j, source, getV2ClientNewExpression({ v2GlobalName, v2ClientName }))
49+
);
50+
}
4951
namesFromServiceModule.push(
50-
...getNames(j, source, getV2ClientNewExpression({ v2ClientName: v2ClientLocalName }))
52+
...getNames(j, source, getV2ClientNewExpression({ v2ClientLocalName }))
5153
);
5254
}
5355

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { NewExpression } from "jscodeshift";
22

33
export interface ClientNewExpressionOptions {
4-
v2GlobalName?: string;
4+
v2ClientLocalName?: string;
55
v2ClientName?: string;
6+
v2GlobalName?: string;
67
}
78

89
export const getV2ClientNewExpression = ({
9-
v2GlobalName,
10+
v2ClientLocalName,
1011
v2ClientName,
12+
v2GlobalName,
1113
}: ClientNewExpressionOptions): NewExpression => {
12-
if (!v2GlobalName && !v2ClientName) {
14+
if (!v2GlobalName && !v2ClientLocalName) {
1315
throw new Error(
14-
`At least one of the following options must be provided: v2GlobalName, v2ClientName`
16+
`At least one of the following options must be provided: v2ClientLocalName, v2GlobalName`
1517
);
1618
}
1719

@@ -27,6 +29,6 @@ export const getV2ClientNewExpression = ({
2729

2830
return {
2931
type: "NewExpression",
30-
callee: { type: "Identifier", name: v2ClientName },
32+
callee: { type: "Identifier", name: v2ClientLocalName },
3133
} as NewExpression;
3234
};

0 commit comments

Comments
 (0)