UNPKG

5.68 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { AstSymbol } from './AstSymbol';
3import { AstModule, AstModuleExportInfo } from './AstModule';
4import { IFetchAstSymbolOptions } from './AstSymbolTable';
5import { AstEntity } from './AstEntity';
6/**
7 * Exposes the minimal APIs from AstSymbolTable that are needed by ExportAnalyzer.
8 *
9 * In particular, we want ExportAnalyzer to be able to call AstSymbolTable._fetchAstSymbol() even though it
10 * is a very private API that should not be exposed to any other components.
11 */
12export interface IAstSymbolTable {
13 fetchAstSymbol(options: IFetchAstSymbolOptions): AstSymbol | undefined;
14 analyze(astEntity: AstEntity): void;
15}
16/**
17 * Used with ExportAnalyzer.fetchAstModuleBySourceFile() to provide contextual information about how the source file
18 * was imported.
19 */
20interface IAstModuleReference {
21 /**
22 * For example, if we are following a statement like `import { X } from 'some-package'`, this will be the
23 * string `"some-package"`.
24 */
25 moduleSpecifier: string;
26 /**
27 * For example, if we are following a statement like `import { X } from 'some-package'`, this will be the
28 * symbol for `X`.
29 */
30 moduleSpecifierSymbol: ts.Symbol;
31}
32/**
33 * The ExportAnalyzer is an internal part of AstSymbolTable that has been moved out into its own source file
34 * because it is a complex and mostly self-contained algorithm.
35 *
36 * Its job is to build up AstModule objects by crawling import statements to discover where declarations come from.
37 * This is conceptually the same as the compiler's own TypeChecker.getExportsOfModule(), except that when
38 * ExportAnalyzer encounters a declaration that was imported from an external package, it remembers how it was imported
39 * (i.e. the AstImport object). Today the compiler API does not expose this information, which is crucial for
40 * generating .d.ts rollups.
41 */
42export declare class ExportAnalyzer {
43 private readonly _program;
44 private readonly _typeChecker;
45 private readonly _bundledPackageNames;
46 private readonly _astSymbolTable;
47 private readonly _astModulesByModuleSymbol;
48 private readonly _importableAmbientSourceFiles;
49 private readonly _astImportsByKey;
50 private readonly _astNamespaceImportByModule;
51 constructor(program: ts.Program, typeChecker: ts.TypeChecker, bundledPackageNames: ReadonlySet<string>, astSymbolTable: IAstSymbolTable);
52 /**
53 * For a given source file, this analyzes all of its exports and produces an AstModule object.
54 *
55 * @param moduleReference - contextual information about the import statement that took us to this source file.
56 * or `undefined` if this source file is the initial entry point
57 * @param isExternal - whether the given `moduleReference` is external.
58 */
59 fetchAstModuleFromSourceFile(sourceFile: ts.SourceFile, moduleReference: IAstModuleReference | undefined, isExternal: boolean): AstModule;
60 /**
61 * Retrieves the symbol for the module corresponding to the ts.SourceFile that is being imported/exported.
62 *
63 * @remarks
64 * The `module` keyword can be used to declare multiple TypeScript modules inside a single source file.
65 * (This is a deprecated construct and mainly used for typings such as `@types/node`.) In this situation,
66 * `moduleReference` helps us to fish out the correct module symbol.
67 */
68 private _getModuleSymbolFromSourceFile;
69 /**
70 * Implementation of {@link AstSymbolTable.fetchAstModuleExportInfo}.
71 */
72 fetchAstModuleExportInfo(entryPointAstModule: AstModule): AstModuleExportInfo;
73 /**
74 * Returns true if the module specifier refers to an external package. Ignores packages listed in the
75 * "bundledPackages" setting from the api-extractor.json config file.
76 */
77 private _isExternalModulePath;
78 /**
79 * Returns true if when we analyzed sourceFile, we found that it contains an "export=" statement that allows
80 * it to behave /either/ as an ambient module /or/ as a regular importable module. In this case,
81 * `AstSymbolTable._fetchAstSymbol()` will analyze its symbols even though `TypeScriptHelpers.isAmbient()`
82 * returns true.
83 */
84 isImportableAmbientSourceFile(sourceFile: ts.SourceFile): boolean;
85 private _collectAllExportsRecursive;
86 /**
87 * For a given symbol (which was encountered in the specified sourceFile), this fetches the AstEntity that it
88 * refers to. For example, if a particular interface describes the return value of a function, this API can help
89 * us determine a TSDoc declaration reference for that symbol (if the symbol is exported).
90 */
91 fetchReferencedAstEntity(symbol: ts.Symbol, referringModuleIsExternal: boolean): AstEntity | undefined;
92 fetchReferencedAstEntityFromImportTypeNode(node: ts.ImportTypeNode, referringModuleIsExternal: boolean): AstEntity | undefined;
93 private _tryMatchExportDeclaration;
94 private _tryMatchImportDeclaration;
95 private static _getIsTypeOnly;
96 private _getExportOfSpecifierAstModule;
97 private _getExportOfAstModule;
98 /**
99 * Implementation of {@link AstSymbolTable.tryGetExportOfAstModule}.
100 */
101 tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined;
102 private _tryGetExportOfAstModule;
103 private _tryGetExternalModulePath;
104 /**
105 * Given an ImportDeclaration of the form `export { X } from "___";`, this interprets the module specifier (`"___"`)
106 * and fetches the corresponding AstModule object.
107 */
108 private _fetchSpecifierAstModule;
109 private _fetchAstImport;
110 private _getModuleSpecifier;
111}
112export {};
113//# sourceMappingURL=ExportAnalyzer.d.ts.map
\No newline at end of file