import * as t from '@babel/types'; import { Node } from '@babel/types'; export { t }; import { Primitive } from 'type-fest'; import { NodeItem } from 'to-path-tree'; declare function isNotPath(path: string): boolean; declare function buildImportFileResult(node: TreeNodeItem | null): { type: "importFile"; node: TreeNodeItem | null; }; declare function getTargetNodeByPath(path: string, node: TreeNodeItem): ReturnType | null | { type: 'importModule'; importModule: string; }; interface AnalyzePrimitive extends PrimitiveVariableValue { } interface AnalyzeIdentifier extends IdentifierVariableValue { fromImport: ScanImportResult | null; fromExport: ScanExportResult | null; importFile: string | null; } interface AnalyzeCallExpression extends CallExpressionVariableValue { calleeFrom: ScanImportResult | null; } interface AnalyzeArrayExpression extends ArrayExpressionVariableValue { values: AnalyzeResultType[]; } interface AnalyzeObjectExpression extends ObjectExpressionVariableValue { values: AnalyzeResultType[]; } type AnalyzeResultType = AnalyzePrimitive | AnalyzeIdentifier | AnalyzeCallExpression | AnalyzeArrayExpression | AnalyzeObjectExpression; interface AnalyzeConfig { importFrom: string[]; } declare class Analyzer { #private; constructor(node: TreeNodeItem, stmts: TreeNodeData['scan'], config?: AnalyzeConfig); analyze(): void; findImportLocation(name: string): { type: string; importModule: string; importFile?: undefined; fromImport?: undefined; fromExport?: undefined; } | { type: string; importFile: string; fromImport: ScanImportResult; fromExport: ScanExportResult; importModule?: undefined; } | null; findImportByIdentifyName(name: string): ScanImportResult | null; getResults(): Map; } interface TreeNodeData { code: string; scan: { imports: ScanImportResult[]; exports: ScanExportResult[]; variables: ScanVariableDeclarationResult[]; }; } type TreeNodeItem = NodeItem; interface MapData { source: { code: string; lang: AcceptableLang; offsetContent: string; }; referToNode?: TreeNodeItem; analyzer?: Analyzer; } interface PrepareConfig { variables: { type?: VariableType[]; importFrom?: string[]; }; } declare class Project { #private; get name(): string; constructor(name: string); /** * * @param fileName must be **absolute** file name * @param fileCode */ addFile(fileName: string, fileCode: string, fileLang?: AcceptableLang, offsetContent?: string): void; addFiles(files: { path: string; code: string; lang?: AcceptableLang; offsetContent?: string; }[]): void; onProgress(callback: (progress: number) => void): void; prepare(config?: PrepareConfig): Promise; getTreeNode(filename: string): TreeNodeItem | undefined; getAnalyzeResults(filename: string): Map | undefined; getMapping(): Map; getFilePaths(): string[]; } interface WalkerContext { skip: () => void; remove: () => void; replace: (node: Node) => void; } type ASTNode = Node; type WalkCallback = (this: WalkerContext, node: Node, parent: Node | null, key: string | number | symbol | null | undefined, index: number | null | undefined) => void; type AcceptableLang = 'js' | 'jsx' | 'ts' | 'tsx'; interface ASTNodeLocation { start: { line: number; column: number; index: number; }; end: { line: number; column: number; index: number; }; } type VariableType = 'StringLiteral' | 'NumericLiteral' | 'BooleanLiteral' | 'NullLiteral' | 'ObjectExpression' | 'ArrayExpression' | 'CallExpression' | 'Identifier'; type PrimitiveValue = Primitive | null | undefined; interface PrimitiveVariableValue { type: 'StringLiteral' | 'NumericLiteral' | 'BooleanLiteral' | 'NullLiteral'; value: PrimitiveValue | ResolveVariableDeclaration; } interface ObjectExpressionVariableValue { type: 'ObjectExpression'; value: { [key: string]: ResolveVariableDeclaration; }; } interface ArrayExpressionVariableValue { type: 'ArrayExpression'; value: ResolveVariableDeclaration[]; } interface CallExpressionVariableValue { type: 'CallExpression'; callee: string; arguments: ResolveVariableDeclaration[]; } interface IdentifierVariableValue { type: 'Identifier'; id: string; } type ResolveVariableDeclaration = PrimitiveVariableValue | CallExpressionVariableValue | ObjectExpressionVariableValue | ArrayExpressionVariableValue | IdentifierVariableValue | null; type ScanExportType = 'ExportNamedDeclaration' | 'ExportAllDeclaration' | 'ExportDefaultDeclaration'; interface ScanExportNamedDeclarationResult { type: 'ExportNamedDeclaration'; subType: 'VariableDeclaration'; kind: t.VariableDeclaration['kind']; declarations: { name: string; init: ResolveVariableDeclaration; }[]; } interface ScanExportNamedSpecifiersResult { type: 'ExportNamedDeclaration'; subType: 'Specifiers'; specifiers: { local: string; exported: string; }[]; source: string | null; } interface ScanExportAllResult { type: 'ExportAllDeclaration'; source: string; } interface ScanExportDefaultIdentifierResult { type: 'ExportDefaultDeclaration'; subType: 'Identifier'; id: string; } interface ScanExportDefaultObjectResult { type: 'ExportDefaultDeclaration'; subType: 'ObjectExpression'; properties: { key: string; value: ResolveVariableDeclaration; }[]; } type ScanExportResult = (ScanExportNamedDeclarationResult | ScanExportNamedSpecifiersResult | ScanExportAllResult | ScanExportDefaultIdentifierResult | ScanExportDefaultObjectResult) & { loc: ASTNodeLocation; }; interface ScanExportConfig { includeType?: ScanExportType[]; excludeType?: ScanExportType[]; } declare function scanExport(node: ASTNode, config?: ScanExportConfig, offsetContent?: string): ScanExportResult | null; declare function getExportByName(name: string, exportsStmt: ScanExportResult[]): ScanExportResult | undefined; interface ScanResultBase { source: string; loc: ASTNodeLocation; } interface ScanImportResultDefault extends ScanResultBase { type: 'default'; local: string; } interface ScanImportResultNamespace extends ScanResultBase { type: 'namespace'; local: string; } interface ScanImportResultImport extends ScanResultBase { type: 'import'; subType: 'id' | 'string'; isType: boolean; local: string; imported: string; } type ScanImportResult = ScanImportResultDefault | ScanImportResultNamespace | ScanImportResultImport; interface ScanImportConfig { includeSource?: string[]; excludeSource?: string[]; skipType?: boolean; offset?: number; } declare const defaultConfig: Required; declare function scanImport(node: ASTNode, config?: ScanImportConfig, offsetContent?: string): ScanImportResult[] | null; declare function getImportByName(name: string, imports: ScanImportResult[]): ScanImportResult | null; interface ScanVariableDeclarationResult { loc: ASTNodeLocation; kind: t.VariableDeclaration['kind']; name: string; init: ResolveVariableDeclaration; } interface ScanVariableDeclarationConfig { includeType?: VariableType[]; excludeType?: VariableType[]; } declare function scanVariableDeclaration(node: ASTNode, config?: ScanVariableDeclarationConfig, offsetContent?: string): ScanVariableDeclarationResult[] | null; type NonNullable = T extends null | undefined ? never : T; type Flat = T extends (infer U)[] ? Flat : T; type LoadScannerReturnType any)[]> = (Flat>>)[][]; declare function loadScanners any | null = (node: ASTNode, ...args: any[]) => any | null, Funcs extends Func[] = Func[]>(code: string, lang: string, scanner: Funcs): LoadScannerReturnType; declare function loadScanner any | null = (node: ASTNode, ...args: any[]) => any | null>(code: string, lang: string, scanner: Func): Flat>>[]; interface ScanConfig { import?: ScanImportConfig; variable?: ScanVariableDeclarationConfig; export?: ScanExportConfig; } declare function scan(code: string, lang: AcceptableLang, config?: ScanConfig, offsetContent?: string): { imports: ScanImportResult[]; variables: ScanVariableDeclarationResult[]; exports: ScanExportResult[]; }; export { type ASTNode, type ASTNodeLocation, type AcceptableLang, type AnalyzeArrayExpression, type AnalyzeCallExpression, type AnalyzeConfig, type AnalyzeIdentifier, type AnalyzeObjectExpression, type AnalyzePrimitive, type AnalyzeResultType, Analyzer, type ArrayExpressionVariableValue, type CallExpressionVariableValue, type IdentifierVariableValue, type ObjectExpressionVariableValue, type PrepareConfig, type PrimitiveVariableValue, Project, type ResolveVariableDeclaration, type ScanExportAllResult, type ScanExportConfig, type ScanExportDefaultIdentifierResult, type ScanExportDefaultObjectResult, type ScanExportNamedDeclarationResult, type ScanExportNamedSpecifiersResult, type ScanExportResult, type ScanExportType, type ScanImportConfig, type ScanImportResult, type ScanImportResultDefault, type ScanImportResultImport, type ScanImportResultNamespace, type ScanVariableDeclarationConfig, type ScanVariableDeclarationResult, type TreeNodeData, type TreeNodeItem, type VariableType, type WalkCallback, type WalkerContext, defaultConfig, getExportByName, getImportByName, getTargetNodeByPath, isNotPath, loadScanner, loadScanners, scan, scanExport, scanImport, scanVariableDeclaration };