Initialize the Enhanced Parser Strategy.
Uses SharedProjectManager's singleton Project by default for standalone usage. Accepts optional Project parameter for Kernel integration (backward compatible).
Optionalproject: ProjectOptional ts-morph Project instance (defaults to SharedProjectManager)
Optionalconfig: EnhancedParserStrategyConfigConfiguration options for enhanced parser
ReadonlynameParser name identifier.
Used for logging, metrics, and parser selection.
Check if this parser can handle the given project context.
The enhanced parser handles projects with:
@PageComponent)Decision Logic:
true if project has any custom patternsfalse if project is standard Angular CLI (use StandardParser instead)Performance: <1ms (simple boolean checks)
Project characteristics detected by ProjectCompatibilityValidator
true if parser can handle this project, false otherwise
Get preprocessing statistics for monitoring and debugging.
Returns cumulative statistics about preprocessing operations:
Preprocessing statistics object
Average preprocessing time per file in milliseconds (0 without files).
Syntax errors removed as false positives.
Files parsed since the last reset.
Path aliases resolved across those files.
const stats = parser.getPreprocessingStats();
console.info(`Processed ${stats.filesProcessed} files`);
console.info(`Resolved ${stats.pathAliasesResolved} path aliases`);
console.info(`Filtered ${stats.falsePositivesFiltered} false positives`);
console.info(`Avg time: ${stats.avgPreprocessingTime}ms per file`);
Calculate reliability score for this parser on the given project.
The enhanced parser provides moderate reliability (0.6-0.8) based on project complexity. More complex projects have lower reliability scores.
Reliability Calculation:
Performance: <1ms (simple arithmetic)
Project characteristics
Reliability score between 0.6 and 0.8
Parse a file and return an Abstract Syntax Tree with preprocessing.
This method implements the preprocessing pipeline:
Preprocessing Steps:
Error Handling:
Performance:
File path (used for error reporting and relative path calculation)
File content to parse
Promise resolving to AST with SourceFile, diagnostics, and preprocessing metadata
const content = `
import { SharedModule } from '@shared/modules';
import { PageComponent } from '@shared/decorators/page';
@PageComponent({ id: 'user-component' })
@Component({ selector: 'app-user', template: '' })
export class UserComponent {}
`;
const ast = await parser.parse('src/app/user.component.ts', content);
console.info(`Path aliases resolved: ${ast.pathAliasesResolved}`); // 2
console.info(`False positives filtered: ${ast.falsePositivesFiltered}`); // 1
console.info(`Errors: ${ast.errors.length}`); // 0
const content = `
import { Component } from '@angular/core';
@Component({ selector: 'app-user' }) // Missing closing brace
export class UserComponent {
`;
const ast = await parser.parse('user.component.ts', content);
console.info(`Errors: ${ast.errors.length}`); // 1+ (genuine syntax error)
ast.errors.forEach(err => console.error(`Line ${err.line}: ${err.message}`));
Apply transformation rules to an AST.
This method executes transformation rules on the parsed AST and returns the transformation result with metadata. Path aliases are preserved or resolved based on configuration.
Transformation Process:
Alias Handling:
preserveAliases is true: Aliases are never resolved (preprocessing skipped)preserveAliases is false: Aliases are resolved before parsing (default)Error Handling:
Performance:
Abstract Syntax Tree from parse()
Array of transformation rules to apply
Promise resolving to transformation result
const ast = await parser.parse('component.ts', content);
const rules = [standaloneRule];
const result = await parser.transform(ast, rules);
if (result.modified) {
console.info(`Applied ${rules.length} rules`);
console.info(`Changed ${result.changeCount} lines`);
console.info(`Parser: ${result.metadata?.parserStrategy}`);
console.info(`False positives filtered: ${result.metadata?.falsePositivesFiltered}`);
console.info(`Output: ${ast.sourceFile.getFullText()}`);
}
Enhanced Parser Strategy - ts-morph with preprocessing for complex projects.
This parser is optimized for projects with custom patterns that standard ts-morph cannot handle directly. It provides preprocessing to:
Compatibility:
@PageComponent)Reliability:
Performance Characteristics:
Example: Basic usage
Example: With custom configuration