Skip to content

Commit 99db636

Browse files
committed
Remove Literal type assertion from getRequireDeclarators
1 parent 6df0723 commit 99db636

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/transforms/v2-to-v3/modules/requireModule/getRequireDeclarators.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import type {
2-
CallExpression,
3-
Collection,
4-
JSCodeshift,
5-
Literal,
6-
VariableDeclarator,
7-
} from "jscodeshift";
1+
import type { CallExpression, Collection, JSCodeshift, VariableDeclarator } from "jscodeshift";
82
import { PACKAGE_NAME } from "../../config";
93

104
const isValidRequireCallExpression = (callExpression: CallExpression, path?: string) => {
115
if (callExpression.arguments.length !== 1) {
126
return false;
137
}
148

15-
const { value: sourceValue } = callExpression.arguments[0] as Literal;
9+
const callExpressionArg = callExpression.arguments[0];
10+
if (callExpressionArg.type !== "Literal" && callExpressionArg.type !== "StringLiteral") {
11+
return false;
12+
}
13+
14+
const sourceValue = callExpressionArg.value;
1615
if (typeof sourceValue !== "string") {
1716
return false;
1817
}

0 commit comments

Comments
 (0)