Angular Modernizer
    Preparing search index...

    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:

    • Standard Angular CLI projects (created with ng new)
    • Projects using standard Angular decorators (@Component, @Injectable, etc.)
    • Projects without custom path aliases
    • Projects without complex constructor patterns
    • Projects with external decorators (use EnhancedParserStrategy)
    • Projects with custom path aliases (use EnhancedParserStrategy)

    Reliability:

    • 0.95 for compatible projects (highest among all parsers)
    • 0.5 for incompatible projects (declines to handle)

    Performance Characteristics:

    • Parse time: <5ms per file (baseline reference)
    • Memory usage: ~50MB for typical project (single Project instance)
    • No preprocessing overhead
    • No false positive filtering overhead
    const parser = new StandardParserStrategy();

    // Check if parser can handle project
    const context: ProjectContext = {
    projectRoot: '/path/to/project',
    hasCustomDecorators: false,
    hasPathAliases: false,
    hasComplexConstructors: false,
    angularVersion: '17.0.0'
    };

    if (parser.canHandle(context)) {
    const reliability = parser.getReliability(context); // 0.95
    const ast = await parser.parse('src/app/app.component.ts', fileContent);
    const result = await parser.transform(ast, [standaloneRule]);
    }
    try {
    const ast = await parser.parse('invalid.ts', 'invalid syntax {{{');
    console.info(`Found ${ast.errors.length} syntax errors`);
    ast.errors.forEach(err => {
    console.error(`${err.file}:${err.line}:${err.column} - ${err.message}`);
    });
    } catch (error) {
    console.error('Parse failed:', error);
    }

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Initialize the Standard Parser Strategy.

      Uses SharedProjectManager's singleton Project instance for parsing. No Project instantiation needed - memory efficient (50MB shared vs 100MB dual).

      Returns StandardParserStrategy

      const parser = new StandardParserStrategy();
      // Parser is ready to use immediately (uses shared Project)

    Properties

    name: "standard" = 'standard'

    Parser name identifier.

    Used for logging, metrics, and parser selection.

    Methods

    • Check if this parser can handle the given project context.

      The standard parser only handles projects without custom patterns:

      • No custom decorators (external decorators like @PageComponent)
      • No complex constructor patterns
      • Standard Angular CLI project structure

      Decision Logic:

      • Returns true if project is standard Angular CLI
      • Returns false if project has custom decorators or complex constructors
      • Path aliases alone don't disqualify (but reduce reliability)

      Performance: <1ms (simple boolean checks)

      Parameters

      Returns boolean

      true if parser can handle this project, false otherwise

      const context: ProjectContext = {
      projectRoot: '/app',
      hasCustomDecorators: false,
      hasPathAliases: false,
      hasComplexConstructors: false,
      angularVersion: '17.0.0'
      };
      parser.canHandle(context); // true
      const context: ProjectContext = {
      projectRoot: '/app',
      hasCustomDecorators: true, // External decorators
      hasPathAliases: false,
      hasComplexConstructors: false,
      angularVersion: '16.0.0'
      };
      parser.canHandle(context); // false
    • 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:

      • 0.95: Standard Angular CLI project (no custom patterns)
      • 0.5: Incompatible project (has custom decorators or complex constructors)

      Performance: <1ms (simple conditional)

      Parameters

      Returns number

      Reliability score between 0.0 and 1.0

      const context: ProjectContext = {
      projectRoot: '/app',
      hasCustomDecorators: false,
      hasPathAliases: false,
      hasComplexConstructors: false,
      angularVersion: '17.0.0'
      };
      parser.getReliability(context); // 0.95
      const context: ProjectContext = {
      projectRoot: '/app',
      hasCustomDecorators: true, // External decorators
      hasPathAliases: false,
      hasComplexConstructors: false,
      angularVersion: '16.0.0'
      };
      parser.getReliability(context); // 0.5 (cannot handle)
    • 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:

      • ts-morph SourceFile for AST manipulation
      • Syntax errors detected by TypeScript compiler
      • Warnings (if any)

      No Preprocessing:

      • No false positive filtering
      • No path alias resolution
      • Direct ts-morph parsing

      Error Handling:

      • Returns errors in AST.errors array
      • Never throws unless catastrophic failure
      • Errors are mapped to ParserSyntaxError format

      Performance:

      • Parse time: <5ms per file (baseline)
      • No preprocessing overhead

      Parameters

      • file: string

        File path (used for error reporting and cache key)

      • content: string

        File content to parse

      Returns Promise<ParserAST>

      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:

      1. Create transform context with sourceFile and project
      2. Execute each rule's transform() method
      3. Aggregate results (modified, changeCount)
      4. Detect syntax errors after transformation
      5. Return result with metadata

      Error Handling:

      • Never throws errors
      • Returns result with modified=false on failure
      • Syntax errors after transformation reported in metadata

      Performance:

      • Transform time: <1s per file (typical)
      • No post-transformation preprocessing

      Parameters

      Returns Promise<ParserTransformResult>

      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()}`);
      }
      const result = await parser.transform(ast, rules);
      if (!result.modified && result.metadata?.syntaxErrors?.length) {
      console.error('Transformation introduced syntax errors:');
      result.metadata.syntaxErrors.forEach(err => console.error(` - ${err}`));
      }