/** * @angular-modernizer/plugin-angular - Method Body Analyzer */ import { type ClassDeclaration, type SourceFile } from 'ts-morph'; export interface IdentifierUsage { name: string; moduleSpecifier: string; alias?: string; kind: 'named' | 'namespace' | 'default'; } /** * Analyzes method bodies using AST traversal to extract imported identifiers. * * This class replaces regex-based pattern matching with proper AST analysis * to accurately identify which imported symbols are used in method bodies. * * @example * ```typescript * const analyzer = new MethodBodyAnalyzer(); * const identifiers = analyzer.analyzeMethodBodies(classDecl, sourceFile); * // Returns: [ * // { name: 'LoginHelper', moduleSpecifier: '@shared/helpers/login-helper', kind: 'named' }, * // { name: 'map', moduleSpecifier: 'rxjs/operators', kind: 'named' } * // ] * ``` */ export declare class MethodBodyAnalyzer { /** * Analyzes method bodies using AST traversal to extract imported identifiers. * * Uses ts-morph's forEachDescendant() to traverse AST nodes and identify: * - Identifier nodes that reference imported symbols * - Property access expressions (e.g., LoginHelper.isUWISuperUser) * - Call expressions with imported functions * * Filters out: * - Local variables and parameters * - Built-in types (string, number, Array, etc.) * - Keywords (this, return, const, etc.) * - Class properties accessed via 'this' * * @param classDecl - The class declaration to analyze * @param originalServiceFile - The source file containing import declarations * @returns Array of imported identifiers used in method bodies */ analyzeMethodBodies(classDecl: ClassDeclaration, originalServiceFile: SourceFile): IdentifierUsage[]; /** * Builds a map of all imports in the source file. * * Handles: * - Named imports: import { LoginHelper } from '@shared/helpers' * - Namespace imports: import * as _ from 'lodash' * - Default imports: import moment from 'moment' * - Aliased imports: import { Model as DomainModel } from '@core/models' * * @param sourceFile - The source file to extract imports from * @returns Map of identifier names to import information */ private buildImportMap; /** * Checks if an identifier is a local variable, parameter, or property. * * Filters out: * - Variable declarations (const localVar = ...) * - Function parameters (function(param) {...}) * - Class properties (this.property) * - Property declarations (private myProp: string) * * @param node - The identifier node to check * @returns True if the identifier is local (should be filtered out) */ private isLocalIdentifier; /** * Removes duplicate identifiers from the list. * * Deduplication is based on the combination of: * - Module specifier * - Original name * - Alias (if present) * * @param identifiers - Array of identifiers to deduplicate * @returns Array with duplicates removed */ private deduplicateIdentifiers; } //# sourceMappingURL=method-body-analyzer.d.ts.map