Skip to content

Commit c6fa5e4

Browse files
committed
Timerify hasRefsInFile (#1435)
1 parent 61305e7 commit c6fa5e4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/knip/src/typescript/find-internal-references.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ts from 'typescript';
2+
import { timerify } from '../util/Performance.js';
23
import { isIdChar } from '../util/regex.js';
34
import type { ExportWithSymbol, MemberWithSymbol } from './get-imports-and-exports.js';
45

@@ -10,7 +11,7 @@ const findInFlow = (flowNode: any, targetSymbol: ts.Symbol): boolean => {
1011

1112
// Find internal references to export item
1213
// Detect usage of non-types within types (e.g. class or typeof within interface/type) to keep those exported
13-
export const hasRefsInFile = (
14+
const hasRefsInFile = (
1415
item: ExportWithSymbol | MemberWithSymbol,
1516
sourceFile: ts.SourceFile,
1617
typeChecker: ts.TypeChecker
@@ -57,3 +58,5 @@ export const hasRefsInFile = (
5758

5859
return false;
5960
};
61+
62+
export const _hasRefsInFile = timerify(hasRefsInFile);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
isObjectEnumerationCallExpressionArgument,
2626
isReferencedInExport,
2727
} from './ast-helpers.js';
28-
import { hasRefsInFile } from './find-internal-references.js';
28+
import { _hasRefsInFile } from './find-internal-references.js';
2929
import { getImportsFromPragmas } from './pragmas/index.js';
3030
import type { BoundSourceFile } from './SourceFile.js';
3131
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
@@ -548,12 +548,12 @@ const getImportsAndExports = (
548548
shouldCountRefs(ignoreExportsUsedInFile, item.type) ||
549549
(item.symbol?.valueDeclaration && ts.isBindingElement(item.symbol.valueDeclaration))
550550
) {
551-
item.hasRefsInFile = hasRefsInFile(item, sourceFile, typeChecker);
551+
item.hasRefsInFile = _hasRefsInFile(item, sourceFile, typeChecker);
552552
}
553553

554554
for (const member of item.members) {
555555
if (item.type === 'enum' || shouldCountRefs(ignoreExportsUsedInFile, member.type)) {
556-
member.hasRefsInFile = hasRefsInFile(member, sourceFile, typeChecker);
556+
member.hasRefsInFile = _hasRefsInFile(member, sourceFile, typeChecker);
557557
}
558558
delete member.symbol;
559559
}

0 commit comments

Comments
 (0)