import ts from "typescript"; import { JSDocNode } from "./JSDocNode"; import { NodeLocation } from "./NodeLocation"; /** * Represents a declaration in a code file. * @group Core */ export interface Declaration { /** * A link to the node location in the source code file in the repository, if * available. */ codeLink?: string; /** * The collection instance that created this instance. */ collection: DeclarationCollection; /** * The JSDoc summary associated with this declaration. */ documentation: readonly JSDocNode[]; /** * A link to the documentation for this declaration. */ documentationLink: string; /** * A list of examples given in the JSDoc for this node, if any. */ examples?: readonly ts.JSDocTag[]; /** * The value of the `@group` tag, if present. */ group?: string; /** * An unique identifier generated for this declaration. */ id: string; /** * A description of how this symbol can be imported. */ importInfo?: ImportInfo; /** * The location of this node in the source file, if source maps are present; * otherwise, the location of this node in the declaration file. */ location: NodeLocation; /** * The module that this declaration is defined in. */ moduleSpecifier: string; /** * A list of members that this declaration defines, where relevant. */ members?: Declaration[]; /** * The name of this declaration. */ name?: string; /** * The AST node associated with this declaration. */ node: Node; /** * A list of parameters that this declaration defines, where relevant. */ parameters?: Declaration[]; /** * The parent declaration for this declaration, where relevant. E.g. for * parameters, this will point to the function declaration. */ parent?: Declaration; /** * Extended JSDoc documentation defined using the `@remarks` tag, if * available. */ remarks?: readonly JSDocNode[]; /** * Details about what is returned from this declaration, if it is a * function-like node and the `@returns` tag has been provided. */ returns?: readonly JSDocNode[]; /** * A list of links provided using the `@see` tag, if any. */ see?: readonly ts.JSDocTag[]; /** * Documentation about values thrown by this declaration, if any, as * documented using the `@throws` tag. */ throws?: readonly ts.JSDocTag[]; /** * The URL slug for this declaration. */ slug: string; } /** * Represents the location of a node with an optional link to the source code in * a repository. * @group Utilities */ export interface NodeLocationWithLink extends NodeLocation { /** * A link to the node location in the source code file in the repository, if * available. */ codeLink?: string; } /** * Represents a function which can return a code link for a given source code * location. * @group Utilities */ export type CodeLinkFactory = (pos: NodeLocation) => string; /** * Represents information about a source code repository. * @group Utilities */ export interface RepositoryInfo { /** * The SHA hash of the current commit, from which this documentation has been * generated. */ sha: string; /** * The URL to the repository. */ url: string; } /** * Options for the {@link DeclarationCollection} class. * @group Core */ export interface DeclarationCollectionOptions { /** * A function to generate links to the code in the repository, or information * about the repository to use the default logic to create links. */ codeLinks?: RepositoryInfo | CodeLinkFactory; /** * The root path in the documentation to use as the base for documentation * links. Defaults to `"/code/declarations"`. */ documentationRoot?: string; /** * The path to find the package.json file. You can also pass the name of a * package to automatically resolve the package. */ packagePath: string; /** * The root path of the source code, used to generate relative paths to source * code files */ sourceRoot?: string; } /** * Information about an imported symbol. * @group Core */ export interface ImportInfo { /** * The kind of import: * - `default`: `import X from 'module';` * - `named`: `import { X } from 'module';` * - `star`: `import * as X from 'module';` */ kind: "default" | "named" | "star"; /** * The local name for named imports (e.g. `import { name as localName } from * 'module';`). */ localName?: string; /** * The module specifier for the import. */ module: string; /** * The imported name. */ name: string; } /** * A class which can parse package type declarations and generate metadata about * the declarations. * * @remarks * The class will automatically resolve all of the entry-points available in the * `exports` section of `package.json`, or choose either `module` or `main` as a * single entry-point. * * For each of the entry-points, all declarations will be read and added as * {@link Declaration} instances to the collection. If a re-export node (e.g. * `export * from './module'`) is encountered, the path will be followed and the * all of the Declarations from the referenced source file will be added, * recursively. The code isn't currently smart enough to limit this only to * named symbols specified in the export clause, or to track renames where the * symbols are given a different alias (e.g. `export { name as aliasName } from * './module'`). * * @example * ```typescript * const collection = new DeclarationCollection({ * codeLinks: { * sha: getGitSha(), * url: SiteMeta.repo, * }, * packagePath: "superdocs", * sourceRoot: getWorkspaceRoot(), * }); * ``` * * @group Core */ export declare class DeclarationCollection implements Iterable { private readonly checker; private readonly declarationsByNode; private readonly declarationsBySlug; private readonly documentationRoot; private readonly getCodeLink; private readonly nodeLocations; private readonly program; private readonly sourceRoot; /** * Get a copy of the list of {@link Declaration} elements in this collection. */ get declarations(): Declaration[]; /** * Create a new instance with the given options. */ constructor(opts: DeclarationCollectionOptions); /** * Implementation of the {@link Iterator} protocol, to return * {@link Declaration} instances when this instance is iterated. * @returns An iterator which returns {@link Declaration} instances. */ [Symbol.iterator](): Iterator; /** * Try to find a declaration for the given name. * @param name The name of the declaration. * @param alias True to try to follow the symbol to the original * declaration. * @returns The declaration if found, or `undefined`. */ getDeclaration(name: ts.EntityName | ts.JSDocMemberName, alias?: boolean): Declaration | undefined; /** * Get the {@link ImportInfo} for the given name, if available. */ getImportInfo(name: ts.EntityName | ts.JSDocMemberName): ImportInfo | undefined; /** * Find a declaration with the given URL slug, if it exists. */ getDeclarationBySlug(slug: string): Declaration | undefined; /** * Get the source location of the given AST node, along with the link to the * source code file in the source repository, if possible. */ getNodeLocation(node: ts.Node): NodeLocationWithLink; private addDeclaration; private getMembers; private getParameters; private loadExport; private loadSourceFile; private resolveSourceFile; } /** * For use as a sort function with {@link Array.prototype.sort}, in order to * sort {@link Declaration} instances by name. * @group Utilities */ export declare function sortDeclarationsByName(a: Declaration, b: Declaration): number; //# sourceMappingURL=DeclarationCollection.d.ts.map