1 | import * as ts from 'typescript';
|
2 | import { AstDeclaration } from './AstDeclaration';
|
3 | import { AstEntity } from './AstEntity';
|
4 | /**
|
5 | * Constructor options for AstSymbol
|
6 | */
|
7 | export interface IAstSymbolOptions {
|
8 | readonly followedSymbol: ts.Symbol;
|
9 | readonly localName: string;
|
10 | readonly isExternal: boolean;
|
11 | readonly nominalAnalysis: boolean;
|
12 | readonly parentAstSymbol: AstSymbol | undefined;
|
13 | readonly rootAstSymbol: AstSymbol | undefined;
|
14 | }
|
15 | /**
|
16 | * The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's
|
17 | * ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.
|
18 | *
|
19 | * @remarks
|
20 | * The AstSymbol represents the ts.Symbol information for an AstDeclaration. For example,
|
21 | * if a method has 3 overloads, each overloaded signature will have its own AstDeclaration,
|
22 | * but they will all share a common AstSymbol.
|
23 | *
|
24 | * For nested definitions, the AstSymbol has a unique parent (i.e. AstSymbol.rootAstSymbol),
|
25 | * but the parent/children for each AstDeclaration may be different. Consider this example:
|
26 | *
|
27 | * ```ts
|
28 | * export namespace N {
|
29 | * export function f(): void { }
|
30 | * }
|
31 | *
|
32 | * export interface N {
|
33 | * g(): void;
|
34 | * }
|
35 | * ```
|
36 | *
|
37 | * Note how the parent/child relationships are different for the symbol tree versus
|
38 | * the declaration tree, and the declaration tree has two roots:
|
39 | *
|
40 | * ```
|
41 | * AstSymbol tree: AstDeclaration tree:
|
42 | * - N - N (namespace)
|
43 | * - f - f
|
44 | * - g - N (interface)
|
45 | * - g
|
46 | * ```
|
47 | */
|
48 | export declare class AstSymbol extends AstEntity {
|
49 | /** {@inheritdoc} */
|
50 | readonly localName: string;
|
51 | /**
|
52 | * If true, then the `followedSymbol` (i.e. original declaration) of this symbol
|
53 | * is not part of the working package. The working package may still export this symbol,
|
54 | * but if so it should be emitted as an alias such as `export { X } from "package1";`.
|
55 | */
|
56 | readonly isExternal: boolean;
|
57 | /**
|
58 | * The compiler symbol where this type was defined, after following any aliases.
|
59 | *
|
60 | * @remarks
|
61 | * This is a normal form that can be reached from any symbol alias by calling
|
62 | * `TypeScriptHelpers.followAliases()`. It can be compared to determine whether two
|
63 | * symbols refer to the same underlying type.
|
64 | */
|
65 | readonly followedSymbol: ts.Symbol;
|
66 | /**
|
67 | * If true, then this AstSymbol represents a foreign object whose structure will be
|
68 | * ignored. The AstDeclaration objects will not have any parent or children, and its references
|
69 | * will not be analyzed.
|
70 | *
|
71 | * Nominal symbols are tracked e.g. when they are reexported by the working package.
|
72 | */
|
73 | readonly nominalAnalysis: boolean;
|
74 | /**
|
75 | * Returns the symbol of the parent of this AstSymbol, or undefined if there is no parent.
|
76 | * @remarks
|
77 | * If a symbol has multiple declarations, we assume (as an axiom) that their parent
|
78 | * declarations will belong to the same symbol. This means that the "parent" of a
|
79 | * symbol is a well-defined concept. However, the "children" of a symbol are not very
|
80 | * meaningful, because different declarations may have different nested members,
|
81 | * so we usually need to traverse declarations to find children.
|
82 | */
|
83 | readonly parentAstSymbol: AstSymbol | undefined;
|
84 | /**
|
85 | * Returns the symbol of the root of the AstDeclaration hierarchy.
|
86 | * @remarks
|
87 | * NOTE: If this AstSymbol is the root, then rootAstSymbol will point to itself.
|
88 | */
|
89 | readonly rootAstSymbol: AstSymbol;
|
90 | /**
|
91 | * Additional information that is calculated later by the `Collector`. The actual type is `SymbolMetadata`,
|
92 | * but we declare it as `unknown` because consumers must obtain this object by calling
|
93 | * `Collector.fetchSymbolMetadata()`.
|
94 | */
|
95 | symbolMetadata: unknown;
|
96 | private readonly _astDeclarations;
|
97 | private _analyzed;
|
98 | constructor(options: IAstSymbolOptions);
|
99 | /**
|
100 | * The one or more declarations for this symbol.
|
101 | * @remarks
|
102 | * For example, if this symbol is a method, then the declarations might be
|
103 | * various method overloads. If this symbol is a namespace, then the declarations
|
104 | * might be separate namespace blocks with the same name that get combined via
|
105 | * declaration merging.
|
106 | */
|
107 | get astDeclarations(): ReadonlyArray<AstDeclaration>;
|
108 | /**
|
109 | * Returns true if the AstSymbolTable.analyze() was called for this object.
|
110 | * See that function for details.
|
111 | * @remarks
|
112 | * AstSymbolTable.analyze() is always performed on the root AstSymbol. This function
|
113 | * returns true if-and-only-if the root symbol was analyzed.
|
114 | */
|
115 | get analyzed(): boolean;
|
116 | /**
|
117 | * This is an internal callback used when the AstSymbolTable attaches a new
|
118 | * AstDeclaration to this object.
|
119 | * @internal
|
120 | */
|
121 | _notifyDeclarationAttach(astDeclaration: AstDeclaration): void;
|
122 | /**
|
123 | * This is an internal callback used when the AstSymbolTable.analyze()
|
124 | * has processed this object.
|
125 | * @internal
|
126 | */
|
127 | _notifyAnalyzed(): void;
|
128 | /**
|
129 | * Helper that calls AstDeclaration.forEachDeclarationRecursive() for each AstDeclaration.
|
130 | */
|
131 | forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void;
|
132 | }
|
133 | //# sourceMappingURL=AstSymbol.d.ts.map |
\ | No newline at end of file |