@microsoft/api-extractor
Version:
Validate, document, and review the exported API for a TypeScript library
87 lines (86 loc) • 3.9 kB
TypeScript
import * as ts from 'typescript';
import { AstSymbol } from './AstSymbol';
/**
* Constructor parameters for AstDeclaration
*/
export interface IAstDeclarationParameters {
readonly declaration: ts.Declaration;
readonly astSymbol: AstSymbol;
readonly parent: AstDeclaration | undefined;
}
/**
* The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's
* ts.Declaration and ts.Symbol objects. They are created by the SymbolTable class.
*
* @remarks
* The AstDeclaration represents one or more syntax components of a symbol. Usually there is
* only one AstDeclaration per AstSymbol, but certain TypeScript constructs can have multiple
* declarations (e.g. overloaded functions, declaration merging, etc).
*
* Because of this the AstDeclaration manages the parent/child nesting hierarchy (e.g. with
* declaration merging, each declaration has its own children) and becomes the main focus
* of analyzing AEDoc and emitting *.d.ts files.
*
* The AstDeclarations correspond to items from the compiler's ts.Node hierarchy, but
* omitting/skipping any nodes that don't match the SymbolAnalyzer.isAstDeclaration()
* criteria. This simplification makes the other API Extractor stages easier to implement.
*/
export declare class AstDeclaration {
readonly declaration: ts.Declaration;
readonly astSymbol: AstSymbol;
/**
* The parent, if this object is nested inside another AstDeclaration.
*/
readonly parent: AstDeclaration | undefined;
private readonly _analyzedChildren;
private readonly _analyzedReferencedAstSymbolsSet;
constructor(parameters: IAstDeclarationParameters);
/**
* Returns the children for this AstDeclaration.
* @remarks
* The collection will be empty until AstSymbol.analyzed is true.
*/
readonly children: ReadonlyArray<AstDeclaration>;
/**
* Returns the AstSymbols referenced by this node.
* @remarks
* NOTE: The collection will be empty until AstSymbol.analyzed is true.
*
* Since we assume references are always collected by a traversal starting at the
* root of the nesting declarations, this array omits the following items because they
* would be redundant:
* - symbols corresponding to parents of this declaration (e.g. a method that returns its own class)
* - symbols already listed in the referencedAstSymbols property for parents of this declaration
* (e.g. a method that returns its own class's base class)
* - symbols that are referenced only by nested children of this declaration
* (e.g. if a method returns an enum, this doesn't imply that the method's class references that enum)
*/
readonly referencedAstSymbols: ReadonlyArray<AstSymbol>;
/**
* This is an internal callback used when the SymbolTable attaches a new
* child AstDeclaration to this object.
* @internal
*/
_notifyChildAttach(child: AstDeclaration): void;
/**
* Returns a diagnostic dump of the tree, which reports the hierarchy of
* AstDefinition objects.
*/
getDump(indent?: string): string;
/**
* Returns a diagnostic dump using Span.getDump(), which reports the detailed
* compiler structure.
*/
getSpanDump(indent?: string): string;
/**
* This is an internal callback used when SymbolTable.analyze() discovers a new
* type reference associated with this declaration.
* @internal
*/
_notifyReferencedAstSymbol(referencedAstSymbol: AstSymbol): void;
/**
* Visits all the current declaration and all children recursively in a depth-first traversal,
* and performs the specified action for each one.
*/
forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void;
}