Initialize the Standard Parser Strategy.
Uses SharedProjectManager's singleton Project instance for parsing. No Project instantiation needed - memory efficient (50MB shared vs 100MB dual).
ReadonlynameParser name identifier.
Used for logging, metrics, and parser selection.
Check if this parser can handle the given project context.
The standard parser only handles projects without custom patterns:
Decision Logic:
true if project is standard Angular CLIfalse if project has custom decorators or complex constructorsPerformance: <1ms (simple boolean checks)
Project characteristics detected by ProjectCompatibilityValidator
true if parser can handle this project, false otherwise
Calculate reliability score for this parser on the given project.
The standard parser provides the highest reliability (0.95) for compatible projects and lower reliability (0.5) for incompatible projects.
Reliability Tiers:
Performance: <1ms (simple conditional)
Project characteristics
Reliability score between 0.0 and 1.0
Parse a file and return an Abstract Syntax Tree.
This method uses ts-morph to parse the file content directly without any preprocessing. The resulting AST contains:
No Preprocessing:
Error Handling:
Performance:
File path (used for error reporting and cache key)
File content to parse
Promise resolving to AST with SourceFile and diagnostics
const content = `
import { Component } from '@angular/core';
@Component({ selector: 'app-user', template: '' })
export class UserComponent {}
`;
const ast = await parser.parse('user.component.ts', content);
console.info(`Errors: ${ast.errors.length}`); // 0
console.info(`Source: ${ast.sourceFile.getFullText()}`);
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+
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.
Transformation Process:
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(`Output: ${ast.sourceFile.getFullText()}`);
}
Standard Parser Strategy - ts-morph wrapper for standard Angular projects.
This parser is optimized for standard Angular CLI projects that don't require preprocessing. It provides the highest reliability (0.95) and fastest performance by using ts-morph directly without any preprocessing steps.
Compatibility:
ng new)Reliability:
Performance Characteristics:
Example: Basic usage
Example: Error handling