UNPKG

5.17 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { AstSymbol } from './AstSymbol';
3import { AstEntity } from './AstEntity';
4/**
5 * Constructor options for AstDeclaration
6 */
7export interface IAstDeclarationOptions {
8 readonly declaration: ts.Declaration;
9 readonly astSymbol: AstSymbol;
10 readonly parent: AstDeclaration | undefined;
11}
12/**
13 * The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's
14 * ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.
15 *
16 * @remarks
17 * The AstDeclaration represents one or more syntax components of a symbol. Usually there is
18 * only one AstDeclaration per AstSymbol, but certain TypeScript constructs can have multiple
19 * declarations (e.g. overloaded functions, merged declarations, etc.).
20 *
21 * Because of this, the `AstDeclaration` manages the parent/child nesting hierarchy (e.g. with
22 * declaration merging, each declaration has its own children) and becomes the main focus
23 * of analyzing AEDoc and emitting *.d.ts files.
24 *
25 * The AstDeclarations correspond to items from the compiler's ts.Node hierarchy, but
26 * omitting/skipping any nodes that don't match the AstDeclaration.isSupportedSyntaxKind()
27 * criteria. This simplification makes the other API Extractor stages easier to implement.
28 */
29export declare class AstDeclaration {
30 readonly declaration: ts.Declaration;
31 readonly astSymbol: AstSymbol;
32 /**
33 * The parent, if this object is nested inside another AstDeclaration.
34 */
35 readonly parent: AstDeclaration | undefined;
36 /**
37 * A bit set of TypeScript modifiers such as "private", "protected", etc.
38 */
39 readonly modifierFlags: ts.ModifierFlags;
40 /**
41 * Additional information that is calculated later by the `Collector`. The actual type is `DeclarationMetadata`,
42 * but we declare it as `unknown` because consumers must obtain this object by calling
43 * `Collector.fetchDeclarationMetadata()`.
44 */
45 declarationMetadata: unknown;
46 /**
47 * Additional information that is calculated later by the `Collector`. The actual type is `ApiItemMetadata`,
48 * but we declare it as `unknown` because consumers must obtain this object by calling
49 * `Collector.fetchApiItemMetadata()`.
50 */
51 apiItemMetadata: unknown;
52 private readonly _analyzedChildren;
53 private readonly _analyzedReferencedAstEntitiesSet;
54 private _childrenByName;
55 constructor(options: IAstDeclarationOptions);
56 /**
57 * Returns the children for this AstDeclaration.
58 * @remarks
59 * The collection will be empty until AstSymbol.analyzed is true.
60 */
61 get children(): ReadonlyArray<AstDeclaration>;
62 /**
63 * Returns the AstEntity objects referenced by this node.
64 * @remarks
65 * NOTE: The collection will be empty until AstSymbol.analyzed is true.
66 *
67 * Since we assume references are always collected by a traversal starting at the
68 * root of the nesting declarations, this array omits the following items because they
69 * would be redundant:
70 * - symbols corresponding to parents of this declaration (e.g. a method that returns its own class)
71 * - symbols already listed in the referencedAstSymbols property for parents of this declaration
72 * (e.g. a method that returns its own class's base class)
73 * - symbols that are referenced only by nested children of this declaration
74 * (e.g. if a method returns an enum, this doesn't imply that the method's class references that enum)
75 */
76 get referencedAstEntities(): ReadonlyArray<AstEntity>;
77 /**
78 * This is an internal callback used when the AstSymbolTable attaches a new
79 * child AstDeclaration to this object.
80 * @internal
81 */
82 _notifyChildAttach(child: AstDeclaration): void;
83 /**
84 * Returns a diagnostic dump of the tree, which reports the hierarchy of
85 * AstDefinition objects.
86 */
87 getDump(indent?: string): string;
88 /**
89 * Returns a diagnostic dump using Span.getDump(), which reports the detailed
90 * compiler structure.
91 */
92 getSpanDump(indent?: string): string;
93 /**
94 * This is an internal callback used when AstSymbolTable.analyze() discovers a new
95 * type reference associated with this declaration.
96 * @internal
97 */
98 _notifyReferencedAstEntity(referencedAstEntity: AstEntity): void;
99 /**
100 * Visits all the current declaration and all children recursively in a depth-first traversal,
101 * and performs the specified action for each one.
102 */
103 forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void;
104 /**
105 * Returns the list of child declarations whose `AstSymbol.localName` matches the provided `name`.
106 *
107 * @remarks
108 * This is an efficient O(1) lookup.
109 */
110 findChildrenWithName(name: string): ReadonlyArray<AstDeclaration>;
111 /**
112 * This function determines which ts.Node kinds will generate an AstDeclaration.
113 * These correspond to the definitions that we can add AEDoc to.
114 */
115 static isSupportedSyntaxKind(kind: ts.SyntaxKind): boolean;
116}
117//# sourceMappingURL=AstDeclaration.d.ts.map
\No newline at end of file