UNPKG

knip

Version:

Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects

87 lines (86 loc) 3.82 kB
import { Visitor, type Class, type Function as FunctionNode, type Program, type Span, type VariableDeclarator } from 'oxc-parser'; import type { PluginVisitorObject } from '../../types/config.ts'; import type { GetImportsAndExportsOptions } from '../../types/config.ts'; import type { Fix } from '../../types/exports.ts'; import type { IssueSymbol, SymbolType } from '../../types/issues.ts'; import type { Export, ExportMember, ImportMap, ImportMaps } from '../../types/module-graph.ts'; import { type ResolveModule } from '../ast-nodes.ts'; interface WalkContext { lineStarts: number[]; skipExports: boolean; options: GetImportsAndExportsOptions; exports: Map<string, Export>; aliasedExports: Map<string, IssueSymbol[]>; specifierExportNames: Set<string>; scripts: Set<string>; addImport: (specifier: string, identifier: string | undefined, alias: string | undefined, namespace: string | undefined, pos: number, modifiers: number, specifierPos?: number, jsDocTags?: Set<string>) => void; addNsMemberRefs: (internalImport: ImportMaps, namespace: string, member: string | string[]) => void; addImportAlias: (aliasName: string, id: string, filePath: string) => void; internal: ImportMap; localImportMap: Map<string, { importedName: string; filePath: string; isNamespace: boolean; isDynamicImport?: boolean; }>; localDeclarationTypes: Map<string, SymbolType>; importAliases: Map<string, Set<{ id: string; filePath: string; }>>; referencedInExport: Map<string, Set<string>>; skipBareExprRefs: boolean; localRefs: Set<string> | undefined; destructuredExports: Set<string>; hasNodeModuleImport: boolean; hasWorkerThreadsImport: boolean; hasChildProcessImport: boolean; hasPathJoinImport: boolean; hasPathResolveImport: boolean; resolveModule: ResolveModule; programFiles: Set<string>; entryFiles: Set<string>; visitor: Visitor; getJSDocTags: (nodeStart: number) => Set<string>; } export interface WalkState extends WalkContext { filePath: string; sourceText: string; isJS: boolean; handledImportExpressions: Set<number>; bareExprRefs: Set<string>; accessedAliases: Set<string>; nsContainers: Map<string, Map<string, string>>; accessedNsContainers: Set<string>; chainedMemberExprs: WeakSet<object>; currentVarDeclStart: number; nsRanges: [number, number][]; memberRefsInFile: string[]; scopeDepth: number; scopeStarts: number[]; scopeEnds: number[]; shadowScopes: Map<string, [number, number][]>; localDeclarations: Map<string, FunctionNode | Class | VariableDeclarator>; pendingCallRefs: Array<{ name: string; exportName: string; seen: Set<string>; }>; pendingMemberCallRefs: Array<{ objectName: string; propertyName: string; exportName: string; seen: Set<string>; }>; addExport: (identifier: string, type: SymbolType, pos: number, members: ExportMember[], fix: Fix, isReExport: boolean, jsDocTags: Set<string>) => void; getFix: (start: number, end: number, flags?: number) => Fix; getTypeFix: (start: number, end: number) => Fix; collectRefsInType: (node: any, exportName: string, signatureOnly: boolean) => void; addRefInExport: (name: string, exportName: string) => void; isInNamespace: (node: Span) => boolean; } export declare const isShadowed: (name: string, pos: number) => boolean; export declare function buildVisitor(pluginVisitorObjects: PluginVisitorObject[], includeLocalRefs?: boolean): Visitor; declare function walkAST(program: Program, sourceText: string, filePath: string, ctx: WalkContext): Set<string> | undefined; export declare const _walkAST: typeof walkAST; export {};