knip 5.1.3 → 5.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@ import ts from 'typescript';
|
|
|
2
2
|
import { FOREIGN_FILE_EXTENSIONS } from '../constants.js';
|
|
3
3
|
import { debugLog } from '../util/debug.js';
|
|
4
4
|
import { extname, isInNodeModules, isInternal } from '../util/path.js';
|
|
5
|
+
import { isDeclarationFileExtension } from './ast-helpers.js';
|
|
5
6
|
export class SourceFileManager {
|
|
6
7
|
isSkipLibs;
|
|
7
8
|
sourceFileCache = new Map();
|
|
@@ -22,8 +23,11 @@ export class SourceFileManager {
|
|
|
22
23
|
getSourceFile(filePath) {
|
|
23
24
|
if (FOREIGN_FILE_EXTENSIONS.has(extname(filePath)))
|
|
24
25
|
return undefined;
|
|
25
|
-
if (this.isSkipLibs && isInNodeModules(filePath))
|
|
26
|
-
|
|
26
|
+
if (this.isSkipLibs && isInNodeModules(filePath)) {
|
|
27
|
+
if (isDeclarationFileExtension(extname(filePath)))
|
|
28
|
+
return undefined;
|
|
29
|
+
return this.createSourceFile(filePath, '');
|
|
30
|
+
}
|
|
27
31
|
if (this.sourceFileCache.has(filePath))
|
|
28
32
|
return this.sourceFileCache.get(filePath);
|
|
29
33
|
const contents = ts.sys.readFile(filePath);
|
|
@@ -290,10 +290,12 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
290
290
|
return;
|
|
291
291
|
for (const match of sourceFile.text.matchAll(new RegExp(item.identifier.replace(/\$/g, '\\$'), 'g'))) {
|
|
292
292
|
const isDeclaration = match.index === item.pos || match.index === item.pos + 1;
|
|
293
|
-
if (!isDeclaration
|
|
294
|
-
typeChecker.getSymbolAtLocation(ts.getTokenAtPosition(sourceFile, match.index))
|
|
295
|
-
item.
|
|
296
|
-
|
|
293
|
+
if (!isDeclaration) {
|
|
294
|
+
const smbl = typeChecker.getSymbolAtLocation(ts.getTokenAtPosition(sourceFile, match.index));
|
|
295
|
+
if (smbl && (item.symbol === smbl || item.symbol === smbl.declarations?.[0]?.name?.flowNode?.node?.symbol)) {
|
|
296
|
+
item.refs = 1;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
297
299
|
}
|
|
298
300
|
}
|
|
299
301
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.1.
|
|
1
|
+
export declare const version = "5.1.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.1.
|
|
1
|
+
export const version = '5.1.4';
|