Initialize the Parser Orchestrator.
Registers available parser strategies:
Strategies are ordered by preference (StandardParser first for performance).
ts-morph Project instance for parsing
Optionaloptions: { verboseLogging?: boolean }Configuration options
Get cache statistics for monitoring.
Cache statistics object
Selections answered from the cache.
cacheHits / totalSelections (0 to 1; 0 without selections).
Number of cached parser selections.
Number of recorded parser selections.
Get parser selection history for feedback analysis.
Limited to last 100 selections to prevent memory leaks.
Array of parser selection decisions
const history = orchestrator.getSelectionHistory();
console.info(`Total selections: ${history.length}`);
console.info(`Cache hit rate: ${history.filter(h => h.fromCache).length / history.length}`);
history.forEach(decision => {
console.info(`${decision.timestamp}: ${decision.selectedParser} (${decision.reliability})`);
});
Parse a file with automatic fallback on failure.
Fallback algorithm:
Resilience: Gracefully degrades to alternative parsers on failure Performance: No overhead unless primary parser fails
File path to parse
File content to parse
Project characteristics
Promise resolving to parse result with fallback metadata
const result = await orchestrator.parseWithFallback(file, content, context);
console.info(`Parsed by: ${result.parserUsed}`); // 'enhanced'
console.info(`Fallback used: ${result.fallbackUsed}`); // false
console.info(`Errors: ${result.ast.errors.length}`); // 0
// If EnhancedParser fails, StandardParser used as fallback
const result = await orchestrator.parseWithFallback(file, content, context);
if (result.fallbackUsed) {
console.warn(`Primary parser failed, using ${result.parserUsed}`);
result.failedParsers?.forEach(({ parserName, error }) => {
console.error(`${parserName} failed: ${error}`);
});
}
Select the best parser for the given project context.
Selection algorithm:
Performance:
Project characteristics
Promise resolving to selected ParserStrategy
const context: ProjectContext = {
projectRoot: '/app',
hasCustomDecorators: false,
hasPathAliases: false,
hasComplexConstructors: false,
angularVersion: '17.0.0'
};
const parser = await orchestrator.selectParser(context);
console.info(parser.name); // 'standard'
console.info(parser.getReliability(context)); // 0.95
const context: ProjectContext = {
projectRoot: '/app',
hasCustomDecorators: true,
hasPathAliases: true,
hasComplexConstructors: false,
angularVersion: '16.0.0'
};
const parser = await orchestrator.selectParser(context);
console.info(parser.name); // 'enhanced'
console.info(parser.getReliability(context)); // 0.65
Transform an AST with the selected parser.
Delegates to the currently selected parser's transform method.
Abstract Syntax Tree to transform
Transformation rules to apply
Promise resolving to transformation result
Parser Orchestrator
Coordinates parser selection and fallback mechanisms for resilient parsing across different project types. Automatically selects the best parser based on project characteristics and falls back gracefully on failures.
Architecture:
Selection Algorithm:
Fallback Algorithm:
Example: Basic usage
Example: With fallback