import { IScope, IScoped, ScopeImpl } from './scope'; import { Statement } from './statements'; import { StructType } from './struct'; import { Type } from './type'; /** * A module */ export declare class Module extends ScopeImpl { /** * Find the containing module of the scoped item */ static of(scoped: IScoped): Module; private readonly _imports; readonly imports: ReadonlyArray; private readonly _initialization; readonly documentation: string[]; readonly initialization: ReadonlyArray; /** * Create a module with a given FQN * * The FQN should just be unique, it does not need to correspond to a file * name (it helps for you own bookkeeping if it is useful though). * * All types defined in this module will have this FQN as a prefix of their * own FQN. */ constructor(fqn: string); /** * Whether this module has no types and no statements */ isEmpty(): boolean; get name(): string; get importName(): string; /** * All interfaces in this module/namespace (not submodules) */ get interfaces(): readonly StructType[]; /** * Add an import of another module into the current module * * `ModuleImport` should be either a `SelectiveModuleImport` or an * `AliasedModuleImport`; symbols from the linked Module will automatically * become availabe in the current module. */ addImport(imp: ModuleImport): void; /** * Import the current module into the target module */ import(intoModule: Module, as: string, props?: ModuleImportProps): void; /** * Import the current module into the target module with selective imports * * @param intoModule - The module to import into * @param names - Array of import names. Each element can be: * - A string for regular imports: `'foo'` → `import { foo } from '...'` * - A tuple for aliased imports: `['foo', 'bar']` → `import { foo as bar } from '...'` * @param props - Additional import properties * @returns The SelectiveModuleImport instance for further customization * * @example Regular and aliased imports * ```ts * source.importSelective(target, ['RegularImport', ['LongName', 'Short']]); * // Generates: import { RegularImport, LongName as Short } from "source"; * ``` * * @example Avoiding name conflicts * ```ts * reactModule.importSelective(myModule, [['Component', 'ReactComponent'], 'useState']); * // Generates: import { Component as ReactComponent, useState } from "react"; * ``` * * @example Dynamic imports using returned instance * ```ts * const imp = source.importSelective(target, ['existing']); * imp.addAliasedImport('foo', 'bar'); * // Generates: import { existing, foo as bar } from "source"; * ``` */ importSelective(intoModule: Module, names: Array, props?: ModuleImportProps): SelectiveModuleImport; /** * Add initialization statements * * These will be executed when the module loads */ addInitialization(...statements: Statement[]): void; /** * Return a reference to a type in this module * * The presence of the type is not checked. */ type(name: string): Type; toString(): string; } export declare abstract class ModuleImport { readonly module: Module; readonly moduleSource: string; constructor(module: Module, moduleSource: string); /** * Make the current module import create the appropriate link in the given scope */ abstract linkInto(scope: IScope): void; } /** * An import statement * * Import statements get rendered into the source module, and also count as scope linkage. */ export declare class AliasedModuleImport extends ModuleImport { readonly importAlias: string; constructor(module: Module, moduleSource: string, importAlias: string); linkInto(scope: IScope): void; } /** * A selective import statement * * Import statements get rendered into the source module, and also count as scope linkage. * Supports both regular imports and aliased imports. * * @example Constructor with mixed imports * ```ts * new SelectiveModuleImport(module, 'source', ['foo', ['bar', 'baz']]); * // Generates: import { foo, bar as baz } from "source"; * ``` * * @example Adding imports dynamically * ```ts * const imp = new SelectiveModuleImport(module, 'source'); * imp.addImportedName('foo'); * imp.addAliasedImport('bar', 'baz'); * // Generates: import { foo, bar as baz } from "source"; * ``` */ export declare class SelectiveModuleImport extends ModuleImport { readonly importedNames: string[]; private readonly aliasMap; private targetScope?; constructor(module: Module, moduleSource: string, importedNames?: Array); /** * Add a regular import name * * @param name - The name to import * @example * ```ts * imp.addImportedName('MyClass'); * // Adds to: import { MyClass } from "..."; * ``` */ addImportedName(name: string): void; /** * Add an aliased import * * @param name - The original name in the source module * @param alias - The alias to use in the target module * @example * ```ts * imp.addAliasedImport('VeryLongClassName', 'Short'); * // Adds to: import { VeryLongClassName as Short } from "..."; * ``` */ addAliasedImport(name: string, alias: string): void; /** * Get the alias for an imported name, if any * @param name - The original name * @returns The alias, or undefined if no alias exists */ getAlias(name: string): string | undefined; linkInto(scope: IScope): void; private linkSymbol; } /** * Props to change module import behavior */ export interface ModuleImportProps { /** * Override the location the module is imported from * @default - FQN of the imported module */ readonly fromLocation?: string; }