Skip to content

Commit f5ab6b1

Browse files
committed
chore: remove type assertion in getImportSpecifiers
1 parent 3aed785 commit f5ab6b1

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
import type { Collection, JSCodeshift, ObjectProperty, Property } from "jscodeshift";
2-
import { OBJECT_PROPERTY_TYPE_LIST } from "../../config";
1+
import type { Collection, JSCodeshift } from "jscodeshift";
32
import type { ImportSpecifierType } from "../types";
43
import { getRequireDeclarators } from "./getRequireDeclarators";
54

6-
const getImportSpecifiersFromObjectPattern = (properties: (Property | ObjectProperty)[]) => {
7-
const importSpecifiers = new Set<ImportSpecifierType>();
8-
9-
for (const property of properties) {
10-
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
11-
continue;
12-
}
13-
const objectProperty = property as Property | ObjectProperty;
14-
const key = objectProperty.key;
15-
const value = objectProperty.value;
16-
if (key.type === "Identifier" && value.type === "Identifier") {
17-
importSpecifiers.add({
18-
importedName: key.name,
19-
localName: value.name,
20-
});
21-
}
22-
}
23-
24-
return Array.from(importSpecifiers);
25-
};
26-
275
export const getImportSpecifiers = (
286
j: JSCodeshift,
297
source: Collection<unknown>,
@@ -54,9 +32,16 @@ export const getImportSpecifiers = (
5432
if (declaratorInit?.type !== "CallExpression") {
5533
continue;
5634
}
57-
const properties = declaratorId.properties as (Property | ObjectProperty)[];
58-
for (const importSpecifier of getImportSpecifiersFromObjectPattern(properties)) {
59-
importSpecifiers.add(importSpecifier);
35+
for (const property of declaratorId.properties) {
36+
if (property.type !== "Property" && property.type !== "ObjectProperty") {
37+
continue;
38+
}
39+
if (property.key.type === "Identifier" && property.value.type === "Identifier") {
40+
importSpecifiers.add({
41+
importedName: property.key.name,
42+
localName: property.value.name,
43+
});
44+
}
6045
}
6146
}
6247
}

0 commit comments

Comments
 (0)