ReadonlynameUnique name for this parser strategy.
Standard names:
'standard' - Standard ts-morph parser (no preprocessing)'enhanced' - ts-morph with FalsePositiveDetector and PathAliasResolver'babel' - Babel parser with TypeScript plugin'custom' - Custom parser implementationsDetermine if this parser can handle the given project context.
This method is called by the parser orchestrator to filter out parsers that
are incompatible with the project. A parser should return false if it knows
it cannot parse the project reliably.
Decision Logic:
false for projects with custom decorators or complex constructorstrue for projects with custom patternstrue for all projectsPerformance: This method should be fast (<1ms) as it's called on every parser during selection.
Project characteristics detected by ProjectCompatibilityValidator
true if parser can handle this project, false otherwise
Calculate reliability score for this parser on the given project.
This method is called by the parser orchestrator to select the best parser for a project. Higher scores indicate higher reliability and confidence in the parser's ability to handle the project successfully.
Reliability Tiers:
Calculation Guidelines:
Performance: This method should be fast (<1ms) as it's called on every capable parser.
Project characteristics detected by ProjectCompatibilityValidator
Reliability score between 0.0 (cannot parse) and 1.0 (perfect reliability)
getReliability(context: ProjectContext): number {
if (!this.canHandle(context)) {
return 0.5; // Low score if cannot handle
}
return 0.95; // High reliability for standard projects
}
getReliability(context: ProjectContext): number {
let reliability = 0.8; // Base score
// Apply penalties for complexity
if (context.hasCustomDecorators) reliability -= 0.1;
if (context.hasPathAliases) reliability -= 0.05;
if (context.hasComplexConstructors) reliability -= 0.05;
return Math.max(reliability, 0.6); // Minimum 0.6
}
Parse a file and return an Abstract Syntax Tree.
This method is responsible for:
Error Handling:
Performance:
Absolute path to the file being parsed (for relative path calculation)
File content to parse
Promise resolving to AST with metadata
async parse(file: string, content: string): Promise<AST> {
const project = new Project();
const sourceFile = project.createSourceFile(file, content);
const diagnostics = sourceFile.getPreEmitDiagnostics();
return {
sourceFile,
errors: diagnostics.map(d => ({
message: d.getMessageText().toString(),
line: d.getLineNumber() || 0,
column: d.getStart() || 0
})),
warnings: [],
falsePositivesFiltered: 0,
customDecorators: [],
pathAliasesResolved: 0
};
}
async parse(file: string, content: string): Promise<AST> {
// Step 1: Resolve path aliases
const preprocessed = this.pathAliasResolver.preprocessFileContent(content, file);
const pathAliasesResolved = preprocessed !== content ? 1 : 0;
// Step 2: Parse with ts-morph
const project = new Project();
const sourceFile = project.createSourceFile(file, preprocessed);
const diagnostics = sourceFile.getPreEmitDiagnostics();
// Step 3: Filter false positives
const errors = diagnostics.map(d => ({
message: d.getMessageText().toString(),
line: d.getLineNumber() || 0,
column: d.getStart() || 0
}));
const filteredResult = this.falsePositiveDetector.filterErrors(errors, content);
return {
sourceFile,
errors: filteredResult.filtered,
warnings: [],
falsePositivesFiltered: filteredResult.removedCount,
customDecorators: [],
pathAliasesResolved
};
}
Apply transformation rules to an AST.
This method is responsible for:
Error Handling:
Performance:
Abstract Syntax Tree from parse()
Array of transformation rules to apply
Promise resolving to transformation result with metadata
async transform(ast: AST, rules: TransformRule[]): Promise<TransformResult> {
const startTime = Date.now();
let modified = false;
let changeCount = 0;
for (const rule of rules) {
const context = { sourceFile: ast.sourceFile, project: this.project, type: 'transform' };
const result = await rule.transform(context);
if (result.modified) {
modified = true;
changeCount += result.changeCount || 0;
}
}
// Detect syntax errors after transformation
const postDiagnostics = ast.sourceFile.getPreEmitDiagnostics();
const syntaxErrors = postDiagnostics.map(d => d.getMessageText().toString());
return {
ruleId: rules.map(r => r.id).join(','),
modified,
message: modified ? 'Transformation succeeded' : 'No changes needed',
changeCount,
metadata: {
duration: Date.now() - startTime,
syntaxErrors,
parserStrategy: this.name,
falsePositivesFiltered: ast.falsePositivesFiltered,
pathAliasesResolved: ast.pathAliasesResolved
}
};
}
Parser Strategy interface.
This interface defines the contract for all parser implementations in the platform. Each parser strategy must implement these methods to integrate with the parser orchestrator.
Strategy Pattern:
Lifecycle:
canHandle(projectContext)on all registered parsersgetReliability(projectContext)on capable parsersparse(file, content)to create ASTtransform(ast, rules)to apply transformationsReliability Scores:
Example: StandardParserStrategy (standard Angular CLI projects)
Example: EnhancedParserStrategy (projects with external decorators)