/** * AST Utility Functions * Provides helper functions for working with tree-sitter AST nodes * * ## Migration: TypeScript Compiler API → tree-sitter * * All functions now use tree-sitter `ASTNode` via the `adapterBridge` facade. * The `ts.SourceFile` parameter has been replaced with `ASTNode` (root node). * For source-code-dependent operations, `sourceCode: string` is passed separately. */ import type { ASTNode, AST } from '../languages/types.js'; import { ImportInfo, ExportInfo, ImportMapping, UsageInfo } from '../types.js'; import { getNodeText as bridgeGetNodeText, getLineAndColumn as bridgeGetLineAndColumn, isExported as bridgeIsExported, calculateComplexity as bridgeCalculateComplexity } from '../languages/adapterBridge.js'; /** * Find all nodes matching a predicate in the AST subtree. * Replacement for the old `findNodesByKind(node, SyntaxKind)`. */ export declare function findNodesByType(root: ASTNode, predicate: (node: ASTNode) => boolean): ASTNode[]; /** * Get the text content of a node. * Uses sourceCode if provided; falls back to raw tree-sitter text. */ export { bridgeGetNodeText as getNodeText }; /** * Get line and column number for a tree-sitter ASTNode. */ export { bridgeGetLineAndColumn as getLineAndColumn }; export { bridgeIsExported as isExported }; export { bridgeCalculateComplexity as calculateComplexity }; /** * Extract import statements from an AST root node. * Uses tree-sitter import_statement structure: * import_statement → import_clause? → (identifier | named_imports) → string */ export declare function getImports(root: ASTNode): ImportInfo[]; /** * Extract export statements from an AST root node. * Uses tree-sitter export_statement structure. */ export declare function getExports(root: ASTNode): ExportInfo[]; /** * Find all function declarations in the AST. */ export declare function findFunctions(root: ASTNode): ASTNode[]; /** * Find all class declarations in the AST. */ export declare function findClasses(root: ASTNode): ASTNode[]; /** * Get AST node for inspection/debugging. */ export declare function getASTNode(node: ASTNode): any; /** * Check if a node has a specific decorator. * Tree-sitter parses decorators as `decorator` nodes. */ export declare function hasDecorator(node: ASTNode, decoratorName: string): boolean; /** * Get method names from a class declaration node. * Tree-sitter: class_declaration → class_body → method_definition / public_field_definition */ export declare function getClassMethods(classNode: ASTNode): string[]; /** * Count lines of code (excluding comments and empty lines). * Takes source text directly instead of ts.SourceFile. */ export declare function countLinesOfCode(sourceCode: string): number; /** * Find all variable declarations in the AST. * Tree-sitter: variable_declarator nodes. */ export declare function findVariableDeclarations(root: ASTNode): ASTNode[]; /** * Check if a function node is async. */ export declare function isAsyncFunction(node: ASTNode): boolean; /** * Get parameter count for a function/method node. * Tree-sitter: formal_parameters → required_parameter / optional_parameter. */ export declare function getParameterCount(node: ASTNode): number; /** * Find all type aliases in the AST. * Tree-sitter: type_alias_declaration nodes. */ export declare function findTypeAliases(root: ASTNode): ASTNode[]; /** * Find all interface declarations in the AST. * Tree-sitter: interface_declaration nodes. */ export declare function findInterfaces(root: ASTNode): ASTNode[]; /** * Parse a TypeScript file and return an AST. * Uses the adapterBridge parseFile function. */ export declare function parseTypeScriptFile(filePath: string): Promise<{ ast: AST; errors: { message: string; line?: number; column?: number; }[]; }>; /** * Enhanced version of getImports that returns detailed ImportMapping[]. * Uses tree-sitter import_statement traversal. */ export declare function getImportsDetailed(root: ASTNode): ImportMapping[]; /** * Get re-exports from a source file. * Tree-sitter: export_statement → string (module specifier). */ export declare function getReExports(root: ASTNode): Array<{ name: string; module: string; }>; /** * Extract identifier usage to track which imports are used. * Uses tree-sitter AST traversal with walkAST. */ export declare function extractIdentifierUsage(root: ASTNode, sourceCode: string, importNames: Set): Map; /** * Check if a function name is defined locally in the file. * Uses tree-sitter instead of TS API. */ export declare function isLocalFunction(name: string, root: ASTNode): boolean; /** * Normalize a function call target for consistent naming. * No TypeScript dependency — pure string manipulation. */ export declare function normalizeCallTarget(callee: string, filePath: string): string; /** * Backward-compatible findNodesByKind. * For code that used `findNodesByKind(sourceFile, ts.SyntaxKind.CallExpression)`, * the equivalent is `findNodesByKind(root, 'call_expression')`. * * Note: the type parameter is retained only for backward compatibility with * the generic-based call pattern; tree-sitter uses string types, not SyntaxKind enums. */ export declare function findNodesByKind(root: ASTNode, nodeType: string): T[]; //# sourceMappingURL=astUtils.d.ts.map