UNPKG

6.04 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { PackageJsonLookup } from '@rushstack/node-core-library';
3import { AstDeclaration } from './AstDeclaration';
4import { AstModule, AstModuleExportInfo } from './AstModule';
5import { AstEntity } from './AstEntity';
6import { MessageRouter } from '../collector/MessageRouter';
7/**
8 * Options for `AstSymbolTable._fetchAstSymbol()`
9 */
10export interface IFetchAstSymbolOptions {
11 /**
12 * The symbol after any symbol aliases have been followed using TypeScriptHelpers.followAliases()
13 */
14 followedSymbol: ts.Symbol;
15 /**
16 * True if followedSymbol is not part of the working package
17 */
18 isExternal: boolean;
19 /**
20 * If true, symbols with AstSymbol.nominalAnalysis=true will be returned.
21 * Otherwise `undefined` will be returned for such symbols.
22 */
23 includeNominalAnalysis: boolean;
24 /**
25 * True while populating the `AstSymbolTable`; false if we're doing a passive lookup
26 * without adding anything new to the table
27 */
28 addIfMissing: boolean;
29 /**
30 * A hint to help `_fetchAstSymbol()` determine the `AstSymbol.localName`.
31 */
32 localName?: string;
33}
34/**
35 * AstSymbolTable is the workhorse that builds AstSymbol and AstDeclaration objects.
36 * It maintains a cache of already constructed objects. AstSymbolTable constructs
37 * AstModule objects, but otherwise the state that it maintains is agnostic of
38 * any particular entry point. (For example, it does not track whether a given AstSymbol
39 * is "exported" or not.)
40 *
41 * Internally, AstSymbolTable relies on ExportAnalyzer to crawl import statements and determine where symbols
42 * are declared (i.e. the AstImport information needed to import them).
43 */
44export declare class AstSymbolTable {
45 private readonly _program;
46 private readonly _typeChecker;
47 private readonly _messageRouter;
48 private readonly _globalVariableAnalyzer;
49 private readonly _packageMetadataManager;
50 private readonly _exportAnalyzer;
51 private readonly _alreadyWarnedGlobalNames;
52 /**
53 * A mapping from ts.Symbol --> AstSymbol
54 * NOTE: The AstSymbol.followedSymbol will always be a lookup key, but additional keys
55 * are possible.
56 *
57 * After following type aliases, we use this map to look up the corresponding AstSymbol.
58 */
59 private readonly _astSymbolsBySymbol;
60 /**
61 * A mapping from ts.Declaration --> AstDeclaration
62 */
63 private readonly _astDeclarationsByDeclaration;
64 private readonly _entitiesByNode;
65 constructor(program: ts.Program, typeChecker: ts.TypeChecker, packageJsonLookup: PackageJsonLookup, bundledPackageNames: ReadonlySet<string>, messageRouter: MessageRouter);
66 /**
67 * Used to analyze an entry point that belongs to the working package.
68 */
69 fetchAstModuleFromWorkingPackage(sourceFile: ts.SourceFile): AstModule;
70 /**
71 * This crawls the specified entry point and collects the full set of exported AstSymbols.
72 */
73 fetchAstModuleExportInfo(astModule: AstModule): AstModuleExportInfo;
74 /**
75 * Attempts to retrieve an export by name from the specified `AstModule`.
76 * Returns undefined if no match was found.
77 */
78 tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined;
79 /**
80 * Ensures that AstSymbol.analyzed is true for the provided symbol. The operation
81 * starts from the root symbol and then fills out all children of all declarations, and
82 * also calculates AstDeclaration.referencedAstSymbols for all declarations.
83 * If the symbol is not imported, any non-imported references are also analyzed.
84 *
85 * @remarks
86 * This is an expensive operation, so we only perform it for top-level exports of an
87 * the AstModule. For example, if some code references a nested class inside
88 * a namespace from another library, we do not analyze any of that class's siblings
89 * or members. (We do always construct its parents however, since AstDefinition.parent
90 * is immutable, and needed e.g. to calculate release tag inheritance.)
91 */
92 analyze(astEntity: AstEntity): void;
93 /**
94 * For a given astDeclaration, this efficiently finds the child corresponding to the
95 * specified ts.Node. It is assumed that AstDeclaration.isSupportedSyntaxKind() would return true for
96 * that node type, and that the node is an immediate child of the provided AstDeclaration.
97 */
98 getChildAstDeclarationByNode(node: ts.Node, parentAstDeclaration: AstDeclaration): AstDeclaration;
99 /**
100 * For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the AstEntity that
101 * it refers to. Returns undefined if it doesn't refer to anything interesting.
102 * @remarks
103 * Throws an Error if the ts.Identifier is not part of node tree that was analyzed.
104 */
105 tryGetEntityForNode(identifier: ts.Identifier | ts.ImportTypeNode): AstEntity | undefined;
106 /**
107 * Builds an AstSymbol.localName for a given ts.Symbol. In the current implementation, the localName is
108 * a TypeScript-like expression that may be a string literal or ECMAScript symbol expression.
109 *
110 * ```ts
111 * class X {
112 * // localName="identifier"
113 * public identifier: number = 1;
114 * // localName="\"identifier\""
115 * public "quoted string!": number = 2;
116 * // localName="[MyNamespace.MySymbol]"
117 * public [MyNamespace.MySymbol]: number = 3;
118 * }
119 * ```
120 */
121 static getLocalNameForSymbol(symbol: ts.Symbol): string;
122 private _analyzeAstNamespaceImport;
123 private _analyzeAstSymbol;
124 /**
125 * Used by analyze to recursively analyze the entire child tree.
126 */
127 private _analyzeChildTree;
128 private _fetchEntityForNode;
129 private _fetchAstDeclaration;
130 private _fetchAstSymbol;
131 /**
132 * Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.
133 */
134 private _tryFindFirstAstDeclarationParent;
135}
136//# sourceMappingURL=AstSymbolTable.d.ts.map
\No newline at end of file