UNPKG

5.95 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { PackageJsonLookup } from '@rushstack/node-core-library';
3import { CollectorEntity } from './CollectorEntity';
4import { AstSymbolTable } from '../analyzer/AstSymbolTable';
5import { AstEntity } from '../analyzer/AstEntity';
6import { AstSymbol } from '../analyzer/AstSymbol';
7import { AstDeclaration } from '../analyzer/AstDeclaration';
8import { WorkingPackage } from './WorkingPackage';
9import { DeclarationMetadata } from './DeclarationMetadata';
10import { ApiItemMetadata } from './ApiItemMetadata';
11import { SymbolMetadata } from './SymbolMetadata';
12import { IGlobalVariableAnalyzer } from '../analyzer/TypeScriptInternals';
13import { MessageRouter } from './MessageRouter';
14import { AstReferenceResolver } from '../analyzer/AstReferenceResolver';
15import { ExtractorConfig } from '../api/ExtractorConfig';
16/**
17 * Options for Collector constructor.
18 */
19export interface ICollectorOptions {
20 /**
21 * Configuration for the TypeScript compiler. The most important options to set are:
22 *
23 * - target: ts.ScriptTarget.ES5
24 * - module: ts.ModuleKind.CommonJS
25 * - moduleResolution: ts.ModuleResolutionKind.NodeJs
26 * - rootDir: inputFolder
27 */
28 program: ts.Program;
29 messageRouter: MessageRouter;
30 extractorConfig: ExtractorConfig;
31}
32/**
33 * The `Collector` manages the overall data set that is used by `ApiModelGenerator`,
34 * `DtsRollupGenerator`, and `ApiReportGenerator`. Starting from the working package's entry point,
35 * the `Collector` collects all exported symbols, determines how to import any symbols they reference,
36 * assigns unique names, and sorts everything into a normalized alphabetical ordering.
37 */
38export declare class Collector {
39 readonly program: ts.Program;
40 readonly typeChecker: ts.TypeChecker;
41 readonly globalVariableAnalyzer: IGlobalVariableAnalyzer;
42 readonly astSymbolTable: AstSymbolTable;
43 readonly astReferenceResolver: AstReferenceResolver;
44 readonly packageJsonLookup: PackageJsonLookup;
45 readonly messageRouter: MessageRouter;
46 readonly workingPackage: WorkingPackage;
47 readonly extractorConfig: ExtractorConfig;
48 /**
49 * The `ExtractorConfig.bundledPackages` names in a set.
50 */
51 readonly bundledPackageNames: ReadonlySet<string>;
52 private readonly _program;
53 private readonly _tsdocParser;
54 private _astEntryPoint;
55 private readonly _entities;
56 private readonly _entitiesByAstEntity;
57 private readonly _starExportedExternalModulePaths;
58 private readonly _dtsTypeReferenceDirectives;
59 private readonly _dtsLibReferenceDirectives;
60 private readonly _cachedOverloadIndexesByDeclaration;
61 constructor(options: ICollectorOptions);
62 /**
63 * Returns a list of names (e.g. "example-library") that should appear in a reference like this:
64 *
65 * ```
66 * /// <reference types="example-library" />
67 * ```
68 */
69 get dtsTypeReferenceDirectives(): ReadonlySet<string>;
70 /**
71 * A list of names (e.g. "runtime-library") that should appear in a reference like this:
72 *
73 * ```
74 * /// <reference lib="runtime-library" />
75 * ```
76 */
77 get dtsLibReferenceDirectives(): ReadonlySet<string>;
78 get entities(): ReadonlyArray<CollectorEntity>;
79 /**
80 * A list of module specifiers (e.g. `"@rushstack/node-core-library/lib/FileSystem"`) that should be emitted
81 * as star exports (e.g. `export * from "@rushstack/node-core-library/lib/FileSystem"`).
82 */
83 get starExportedExternalModulePaths(): ReadonlyArray<string>;
84 /**
85 * Perform the analysis.
86 */
87 analyze(): void;
88 /**
89 * For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the CollectorEntity that
90 * it refers to. Returns undefined if it doesn't refer to anything interesting.
91 * @remarks
92 * Throws an Error if the ts.Identifier is not part of node tree that was analyzed.
93 */
94 tryGetEntityForNode(identifier: ts.Identifier | ts.ImportTypeNode): CollectorEntity | undefined;
95 /**
96 * Returns the associated `CollectorEntity` for the given `astEntity`, if one was created during analysis.
97 */
98 tryGetCollectorEntity(astEntity: AstEntity): CollectorEntity | undefined;
99 fetchSymbolMetadata(astSymbol: AstSymbol): SymbolMetadata;
100 fetchDeclarationMetadata(astDeclaration: AstDeclaration): DeclarationMetadata;
101 fetchApiItemMetadata(astDeclaration: AstDeclaration): ApiItemMetadata;
102 tryFetchMetadataForAstEntity(astEntity: AstEntity): SymbolMetadata | undefined;
103 isAncillaryDeclaration(astDeclaration: AstDeclaration): boolean;
104 getNonAncillaryDeclarations(astSymbol: AstSymbol): ReadonlyArray<AstDeclaration>;
105 /**
106 * Removes the leading underscore, for example: "_Example" --> "example*Example*_"
107 *
108 * @remarks
109 * This causes internal definitions to sort alphabetically case-insensitive, then case-sensitive, and
110 * initially ignoring the underscore prefix, while still deterministically comparing it.
111 * The star is used as a delimiter because it is not a legal identifier character.
112 */
113 static getSortKeyIgnoringUnderscore(identifier: string | undefined): string;
114 /**
115 * For function-like signatures, this returns the TSDoc "overload index" which can be used to identify
116 * a specific overload.
117 */
118 getOverloadIndex(astDeclaration: AstDeclaration): number;
119 private _createCollectorEntity;
120 private _createEntityForIndirectReferences;
121 /**
122 * Ensures a unique name for each item in the package typings file.
123 */
124 private _makeUniqueNames;
125 private _fetchSymbolMetadata;
126 private _calculateDeclarationMetadataForDeclarations;
127 private _addAncillaryDeclaration;
128 private _calculateApiItemMetadata;
129 private _parseTsdocForAstDeclaration;
130 private _collectReferenceDirectives;
131 private _collectReferenceDirectivesFromSourceFiles;
132}
133//# sourceMappingURL=Collector.d.ts.map
\No newline at end of file