UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

98 lines (97 loc) 2.79 kB
import ts from "typescript"; import { FunctionExtractionContext, ExtractedFunction } from "../types/function.types"; /** * Enhanced extractor that analyzes functions from a TypeScript source file */ export declare class FunctionExtractor { private functionFilter; private errorHandler; private typeResolver; private parameterParser; private bodyParser; private asyncDetector; private classifier; constructor(typeChecker?: ts.TypeChecker); /** * Extracts relevant functions from a specific component within a source file * @param context The extraction context with source file and component name * @returns Array of extracted function data */ extractFunctions(context: FunctionExtractionContext): { componentName: string; functionName: string; params: string[]; returnType: string; body: string; dependencies: string[]; calledFunctions: string[]; isAsync: boolean; }[]; /** * Find the specific component node in the source file */ private findComponentNode; /** * Find a declaration by name in the source file */ private findDeclarationInSourceFile; /** * Traverses AST and extracts functions, limited to the component scope */ private traverseAndExtract; /** * Check if a function node is within the component scope (not a separate component) */ private isFunctionWithinComponent; /** * Extracts a single function with comprehensive error handling */ private extractSingleFunction; /** * Type guard for function-like nodes */ private isFunctionLikeNode; /** * Extracts detailed function information (for advanced analysis) */ extractFunctionsDetailed(context: FunctionExtractionContext): ExtractedFunction[]; /** * Extracts detailed function information */ private extractDetailedFunction; /** * Gets extraction statistics */ getExtractionStats(): { totalErrors: number; errorsByCategory: Record<string, number>; canContinue: boolean; summary: string; }; /** * Clears all accumulated errors */ clearErrors(): void; /** * Gets all errors for debugging */ getErrors(): any[]; /** * Validates extraction results */ validateExtractionResults(results: { componentName: string; functionName: string; params: string[]; returnType: string; body: string; dependencies: string[]; calledFunctions: string[]; isAsync: boolean; }[]): { isValid: boolean; issues: string[]; validCount: number; invalidCount: number; }; }