UNPKG

knip

Version:

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

70 lines (69 loc) 3.22 kB
import { Visitor, type Program, type Span } 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 './helpers.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; 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][]>; 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; export declare function walkAST(program: Program, sourceText: string, filePath: string, ctx: WalkContext): Set<string> | undefined; export {};