Skip to content

Commit bba25f3

Browse files
committed
Move block to group top-level patterns
1 parent b19282b commit bba25f3

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

packages/knip/src/typescript/get-imports-and-exports.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ const getImportsAndExports = (
321321
const result = visitor(node, options);
322322
result && (Array.isArray(result) ? result.forEach(addExport) : addExport(result));
323323
}
324+
325+
if (
326+
ts.isImportEqualsDeclaration(node) &&
327+
ts.isQualifiedName(node.moduleReference) &&
328+
ts.isIdentifier(node.moduleReference.left)
329+
) {
330+
// Pattern: import name = NS.identifier
331+
const { left, right } = node.moduleReference;
332+
const namespace = left.text;
333+
const { filePath } = getImport(namespace, node);
334+
if (filePath) {
335+
const internalImport = internal.get(filePath);
336+
if (internalImport) addNsMemberRefs(internalImport, namespace, right.text);
337+
}
338+
}
324339
}
325340

326341
for (const visitor of visitors.dynamicImport) {
@@ -407,22 +422,6 @@ const getImportsAndExports = (
407422
}
408423
}
409424

410-
if (
411-
isTopLevel &&
412-
ts.isImportEqualsDeclaration(node) &&
413-
ts.isQualifiedName(node.moduleReference) &&
414-
ts.isIdentifier(node.moduleReference.left)
415-
) {
416-
// Pattern: import name = NS.identifier
417-
const { left, right } = node.moduleReference;
418-
const namespace = left.text;
419-
const { filePath } = getImport(namespace, node);
420-
if (filePath) {
421-
const internalImport = internal.get(filePath);
422-
if (internalImport) addNsMemberRefs(internalImport, namespace, right.text);
423-
}
424-
}
425-
426425
ts.forEachChild(node, visit);
427426
};
428427

0 commit comments

Comments
 (0)