knip 6.6.1 → 6.6.2
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.
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { frontmatterMatcher, scriptBodies } from '../../compilers/compilers.js';
|
|
2
|
+
const propsDeclMatcher = /(?:^|[\s;])(?:interface|type)\s+Props\b/;
|
|
2
3
|
const compiler = (text, path) => {
|
|
3
4
|
const scripts = [];
|
|
4
5
|
const frontmatter = text.match(frontmatterMatcher);
|
|
5
|
-
if (frontmatter?.[1])
|
|
6
|
-
|
|
6
|
+
if (frontmatter?.[1]) {
|
|
7
|
+
let fm = frontmatter[1];
|
|
8
|
+
if (propsDeclMatcher.test(fm) && text.includes('Astro.props'))
|
|
9
|
+
fm += '\ntype __knip_astro_props = Props;';
|
|
10
|
+
scripts.push(fm);
|
|
11
|
+
}
|
|
7
12
|
const scriptContent = scriptBodies(text, path);
|
|
8
13
|
if (scriptContent)
|
|
9
14
|
scripts.push(scriptContent);
|
|
@@ -63,7 +63,7 @@ export interface WalkState extends WalkContext {
|
|
|
63
63
|
addExport: (identifier: string, type: SymbolType, pos: number, members: ExportMember[], fix: Fix, isReExport: boolean, jsDocTags: Set<string>) => void;
|
|
64
64
|
getFix: (start: number, end: number, flags?: number) => Fix;
|
|
65
65
|
getTypeFix: (start: number, end: number) => Fix;
|
|
66
|
-
collectRefsInType: (node: any, exportName: string, signatureOnly: boolean) => void;
|
|
66
|
+
collectRefsInType: (node: any, exportName: string, signatureOnly: boolean, inMember?: boolean) => void;
|
|
67
67
|
addRefInExport: (name: string, exportName: string) => void;
|
|
68
68
|
isInNamespace: (node: Span) => boolean;
|
|
69
69
|
}
|
|
@@ -47,17 +47,26 @@ const _addExport = (identifier, type, pos, members, fix, isReExport, jsDocTags)
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
const
|
|
50
|
+
const MEMBER_CONTAINERS = new Set([
|
|
51
|
+
'TSPropertySignature',
|
|
52
|
+
'TSMethodSignature',
|
|
53
|
+
'TSIndexSignature',
|
|
54
|
+
'TSCallSignatureDeclaration',
|
|
55
|
+
'TSConstructSignatureDeclaration',
|
|
56
|
+
]);
|
|
57
|
+
const _collectRefsInType = (node, exportName, signatureOnly, inMember = false) => {
|
|
51
58
|
if (!node || typeof node !== 'object')
|
|
52
59
|
return;
|
|
53
60
|
if (node.type === 'TSTypeQuery') {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
refs
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
if (inMember) {
|
|
62
|
+
const name = node.exprName.type === 'Identifier' ? node.exprName.name : undefined;
|
|
63
|
+
if (name) {
|
|
64
|
+
const refs = state.referencedInExport.get(name);
|
|
65
|
+
if (refs)
|
|
66
|
+
refs.add(exportName);
|
|
67
|
+
else
|
|
68
|
+
state.referencedInExport.set(name, new Set([exportName]));
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
return;
|
|
63
72
|
}
|
|
@@ -71,6 +80,7 @@ const _collectRefsInType = (node, exportName, signatureOnly) => {
|
|
|
71
80
|
else
|
|
72
81
|
state.referencedInExport.set(name, new Set([exportName]));
|
|
73
82
|
}
|
|
83
|
+
const nextInMember = inMember || MEMBER_CONTAINERS.has(node.type);
|
|
74
84
|
for (const key in node) {
|
|
75
85
|
if (key === 'type' || key === 'parent')
|
|
76
86
|
continue;
|
|
@@ -78,11 +88,11 @@ const _collectRefsInType = (node, exportName, signatureOnly) => {
|
|
|
78
88
|
if (Array.isArray(val)) {
|
|
79
89
|
for (const item of val) {
|
|
80
90
|
if (item && typeof item === 'object' && item.type)
|
|
81
|
-
_collectRefsInType(item, exportName, signatureOnly);
|
|
91
|
+
_collectRefsInType(item, exportName, signatureOnly, nextInMember);
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
else if (val && typeof val === 'object' && val.type) {
|
|
85
|
-
_collectRefsInType(val, exportName, signatureOnly);
|
|
95
|
+
_collectRefsInType(val, exportName, signatureOnly, nextInMember);
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.6.
|
|
1
|
+
export declare const version = "6.6.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '6.6.
|
|
1
|
+
export const version = '6.6.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.2",
|
|
4
4
|
"description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analysis",
|
|
@@ -82,13 +82,13 @@
|
|
|
82
82
|
"get-tsconfig": "4.14.0",
|
|
83
83
|
"jiti": "^2.6.0",
|
|
84
84
|
"minimist": "^1.2.8",
|
|
85
|
-
"oxc-parser": "^0.
|
|
85
|
+
"oxc-parser": "^0.127.0",
|
|
86
86
|
"oxc-resolver": "^11.19.1",
|
|
87
87
|
"picomatch": "^4.0.4",
|
|
88
88
|
"smol-toml": "^1.6.1",
|
|
89
89
|
"strip-json-comments": "5.0.3",
|
|
90
90
|
"tinyglobby": "^0.2.16",
|
|
91
|
-
"unbash": "^
|
|
91
|
+
"unbash": "^3.0.0",
|
|
92
92
|
"yaml": "^2.8.2",
|
|
93
93
|
"zod": "^4.1.11"
|
|
94
94
|
},
|