/** * Module reference collection. * * `SourceFile.getImportDeclarations()` only sees *static* `import` statements, so * anything loaded lazily — `await import('./x')`, `React.lazy(() => import('./x'))`, * `next/dynamic`, `require('./x')`, `import x = require('./x')` — is invisible to * usage analysis and gets falsely reported as dead code. * * This module walks those call forms and reports, per load site: * - the local names the module (or its exports) is bound to, * - members read straight off the module object, * so the usage analyzer can bind them exactly like static imports. */ import { Node, type SourceFile, type StringLiteral } from 'ts-morph'; /** A local name bound to some part of a dynamically loaded module. */ export interface ImportBinding { /** Local identifier in the consuming file. */ local: string; kind: 'named' | 'default' | 'namespace'; /** Exported name when `kind === 'named'`. */ imported?: string; } /** `(await import('m')).foo` — an export read directly off the module object. */ export interface MemberRead { name: string; /** Node the reference is attributed to (location + kind). */ node: Node; } export interface DynamicModuleRef { spec: string; specNode: StringLiteral; syntax: 'import' | 'require'; bindings: ImportBinding[]; members: MemberRead[]; /** The load site, used when nothing else binds (e.g. `lazy: () => import('./X')`). */ site: Node; /** Export standing in for `default` in a `.then(m => ({ default: m.X }))` chain. */ defaultAlias?: string; } /** * Every module specifier the file references, in any syntax: static imports, * `export … from`, `import x = require()`, `import()` and `require()` calls. * Used for third-party dependency usage counting. */ export declare function collectModuleSpecifiers(file: SourceFile): string[]; /** All dynamic (`import()` / `require()`) module loads in a file, with their bindings. */ export declare function collectDynamicModuleRefs(file: SourceFile): DynamicModuleRef[]; /** * Resolve a module specifier to a project source file. The type checker handles * `import()` (including tsconfig `paths` and package `exports`); `require()` * specifiers carry no symbol, so those fall back to the module resolver. */ export declare function resolveModuleFile(file: SourceFile, specNode: StringLiteral): SourceFile | undefined;