import { JavaScriptVisitor } from "./visitor"; import { J } from "../java"; import { JS } from "./tree"; export declare enum ImportStyle { ES6Named = 0,// import { x } from 'module' ES6Namespace = 1,// import * as x from 'module' ES6Default = 2,// import x from 'module' CommonJS = 3 } export interface AddImportOptions { /** The module name (e.g., 'fs', 'react') to import from */ module: string; /** Optionally, the specific member to import from the module. * If not specified, adds a default import or namespace import. * Special values: * - 'default': Adds a default import from the module. * When using 'default', the `alias` parameter is required. * - '*': Adds a namespace import (import * as alias from 'module'). * When using '*', the `alias` parameter is required. * Cannot be combined with `sideEffectOnly`. */ member?: string; /** Optional alias for the imported member. * Required when member is 'default' or '*'. * Cannot be combined with `sideEffectOnly`. */ alias?: string; /** If true, only add the import if the member is actually used in the file. Default: true * Cannot be combined with `sideEffectOnly`. */ onlyIfReferenced?: boolean; /** If true, adds a side-effect import without bindings (e.g., `import 'module'` or `require('module')`). * Cannot be combined with `member`, `alias`, or `onlyIfReferenced`. */ sideEffectOnly?: boolean; /** If true, adds a type-only import (e.g., `import type { Foo } from 'module'`). * Type-only imports are erased at compile time and do not generate runtime code. * Cannot be combined with `sideEffectOnly`. */ typeOnly?: boolean; /** Optional import style to use. If not specified, auto-detects from file and existing imports */ style?: ImportStyle; } /** * Register an AddImport visitor to add an import statement to a JavaScript/TypeScript file * @param visitor The visitor to add the import addition to * @param options Configuration options for the import to add * * @example * // Add a named import * maybeAddImport(visitor, { module: 'fs', member: 'readFile' }); * * @example * // Add a default import using the 'default' member specifier * maybeAddImport(visitor, { module: 'react', member: 'default', alias: 'React' }); * * @example * // Add a default import (legacy way, without specifying member) * maybeAddImport(visitor, { module: 'react', alias: 'React' }); * * @example * // Add a namespace import * maybeAddImport(visitor, { module: 'crypto', member: '*', alias: 'crypto' }); * * @example * // Add a side-effect import * maybeAddImport(visitor, { module: 'core-js/stable', sideEffectOnly: true }); */ export declare function maybeAddImport(visitor: JavaScriptVisitor, options: AddImportOptions): void; export declare class AddImport

extends JavaScriptVisitor

{ readonly module: string; readonly member?: string; readonly alias?: string; readonly onlyIfReferenced: boolean; readonly sideEffectOnly: boolean; readonly typeOnly: boolean; readonly style?: ImportStyle; constructor(options: AddImportOptions); /** * Extract module name from a module specifier literal */ private getModuleName; /** * Check if a method invocation is a require() call */ private isRequireCall; /** * Determine the appropriate import style based on file type and existing imports */ private determineImportStyle; /** * Find the import style used for an existing import from the same module */ private findExistingImportStyleForModule; visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, p: P): Promise; /** * Try to merge the new member into an existing import from the same module */ private tryMergeIntoExistingImport; /** * Check if the import already exists in the compilation unit */ private checkImportExists; /** * Check if the import matches what we're trying to add */ private isMatchingImport; /** * Check if this is a matching CommonJS require statement */ private isMatchingRequire; /** * Extract the module name from a class type by traversing the owningClass chain * or extracting it from the FQN. */ private getModuleFromClassType; /** * Extract the module name from a type (method, class, or variable). */ private getModuleFromType; /** * Check if a class type matches the expected module. * Handles direct FQN match, owningClass chain match, and FQN prefix match. */ private classTypeMatchesModule; /** * Check if the identifier is actually referenced in the file */ private checkIdentifierReferenced; /** * Create a new import statement */ private createImportStatement; /** * Create an import specifier for a named import */ private createImportSpecifier; /** * Determine the appropriate spacing before the import statement */ private determineImportPrefix; /** * Find the index where the new import should be inserted */ private findImportInsertionIndex; /** * Get the module name from a require() call */ private getModuleNameFromRequire; /** * Get the import name from an import specifier */ private getImportName; /** * Get the import alias from an import specifier */ private getImportAlias; } //# sourceMappingURL=add-import.d.ts.map