aetherlight-analyzer
Version:
Code analysis tool to generate ÆtherLight sprint plans from any codebase
87 lines • 3.53 kB
TypeScript
/**
* DESIGN DECISION: Use ts-morph for TypeScript AST parsing
* WHY: ts-morph provides high-level API over TypeScript compiler, easier than raw ts.createProgram()
*
* REASONING CHAIN:
* 1. Need to parse TypeScript/JavaScript files accurately
* 2. TypeScript compiler API is low-level and verbose
* 3. ts-morph wraps compiler API with intuitive methods
* 4. Provides traversal helpers (getClasses(), getFunctions(), etc.)
* 5. Result: 10k+ LOC/s parsing speed with simple code
*
* PATTERN: Pattern-ANALYZER-001 (AST-Based Code Analysis)
* RELATED: PHASE_0_CODE_ANALYZER.md (Task A-001)
* PERFORMANCE: Target <5s for 50k LOC
*/
import { ParseResult } from './types';
export declare class TypeScriptParser {
private project;
constructor(tsConfigPath?: string);
/**
* Parse all TypeScript/JavaScript files in directory (STREAMING with BATCHING)
*
* DESIGN DECISION: Batch processing to prevent memory exhaustion
* WHY: Loading all files at once causes heap overflow on projects >300 files
*
* REASONING CHAIN:
* 1. Find all file paths first (cheap - just file paths, not ASTs)
* 2. Split into batches of 50 files (tunable via batchSize parameter)
* 3. For each batch: load → parse → extract results → dispose ASTs
* 4. Aggregate results across all batches
* 5. Result: Constant memory (~500MB) instead of growing (4-5GB)
*
* PATTERN: Pattern-ANALYZER-008 (Streaming Parser for Large Codebases)
* DOGFOODING: Discovered via dogfooding on our own 519-file codebase
* PERFORMANCE: 519 files in 11 batches → completes in ~9s vs crashing at 8.5min
*
* @param directoryPath - Root directory to scan
* @param extensions - File extensions to include (default: .ts, .tsx, .js, .jsx)
* @param batchSize - Number of files to process per batch (default: 50)
* @param onProgress - Optional callback for progress updates
* @returns ParseResult with all parsed files and dependencies
*/
parse(directoryPath: string, extensions?: string[], batchSize?: number, onProgress?: (current: number, total: number) => void): Promise<ParseResult>;
/**
* Find all matching files recursively
*
* DESIGN DECISION: Use fs.readdirSync for recursive traversal
* WHY: Faster than glob for simple extension matching, no dependencies
*
* @param directoryPath - Root directory
* @param extensions - File extensions to match
* @returns Array of absolute file paths
*/
private findFiles;
/**
* Parse single source file
*
* REASONING CHAIN:
* 1. Extract all code elements (classes, functions, etc.)
* 2. Extract dependencies (imports)
* 3. Calculate LOC (excluding comments/whitespace)
* 4. Collect parse errors
* 5. Return unified ParsedFile structure
*/
private parseFile;
private parseFunction;
private parseMethod;
private parseProperty;
private parseParameter;
private getLocation;
private getDocumentation;
private getVisibility;
/**
* Calculate cyclomatic complexity
*
* DESIGN DECISION: Count decision points (if, while, for, case, &&, ||, ?:)
* WHY: Industry standard for measuring code complexity
*
* Complexity = 1 (base) + decision points
*/
private calculateComplexity;
/**
* Calculate lines of code (excluding comments and blank lines)
*/
private calculateLinesOfCode;
}
//# sourceMappingURL=typescript-parser.d.ts.map