UNPKG

9.48 kBTypeScriptView Raw
1import ts from "typescript";
2import type { Application } from "../application.js";
3import { Comment, type CommentDisplayPart, type ContainerReflection, type DeclarationReflection, DocumentReflection, type ParameterReflection, ProjectReflection, type Reflection, type ReflectionSymbolId, type SignatureReflection, type SomeType, type TypeParameterReflection } from "../models/index.js";
4import { Context } from "./context.js";
5import { AbstractComponent } from "../utils/component.js";
6import { MinimalSourceFile } from "../utils/index.js";
7import type { DocumentationEntryPoint } from "../utils/entry-point.js";
8import type { CommentParserConfig } from "./comments/index.js";
9import type { CommentStyle, ValidationOptions } from "../utils/options/declaration.js";
10import { type ExternalSymbolResolver, type ExternalResolveResult } from "./comments/linkResolver.js";
11import { type DeclarationReference } from "./comments/declarationReference.js";
12import type { FileRegistry } from "../models/FileRegistry.js";
13import { IncludePlugin } from "./plugins/IncludePlugin.js";
14export interface ConverterEvents {
15 begin: [Context];
16 end: [Context];
17 createProject: [Context, ProjectReflection];
18 createDeclaration: [Context, DeclarationReflection];
19 createDocument: [undefined, DocumentReflection];
20 createSignature: [
21 Context,
22 SignatureReflection,
23 (ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature)?,
24 ts.Signature?
25 ];
26 createParameter: [Context, ParameterReflection, ts.Node?];
27 createTypeParameter: [
28 Context,
29 TypeParameterReflection,
30 ts.TypeParameterDeclaration?
31 ];
32 resolveBegin: [Context];
33 resolveReflection: [Context, Reflection];
34 resolveEnd: [Context];
35}
36/**
37 * Compiles source files using TypeScript and converts compiler symbols to reflections.
38 *
39 * @group Common
40 * @summary Responsible for converting TypeScript symbols into {@link Reflection}s and {@link Type}s.
41 */
42export declare class Converter extends AbstractComponent<Application, ConverterEvents> {
43 /** @internal */
44 accessor externalPattern: string[];
45 private externalPatternCache?;
46 private excludeCache?;
47 /** @internal */
48 accessor excludeExternals: boolean;
49 /** @internal */
50 accessor excludeNotDocumented: boolean;
51 /** @internal */
52 accessor excludePrivate: boolean;
53 /** @internal */
54 accessor excludeProtected: boolean;
55 /** @internal */
56 accessor excludeReferences: boolean;
57 /** @internal */
58 accessor commentStyle: CommentStyle;
59 /** @internal */
60 accessor validation: ValidationOptions;
61 /** @internal */
62 accessor externalSymbolLinkMappings: Record<string, Record<string, string>>;
63 /** @internal */
64 accessor preserveLinkText: boolean;
65 /** @internal */
66 accessor maxTypeConversionDepth: number;
67 private _config?;
68 private _externalSymbolResolvers;
69 get config(): CommentParserConfig;
70 /**
71 * General events
72 */
73 /**
74 * Triggered when the converter begins converting a project.
75 * The listener will be given a {@link Context} object.
76 * @event
77 */
78 static readonly EVENT_BEGIN: "begin";
79 /**
80 * Triggered when the converter has finished converting a project.
81 * The listener will be given a {@link Context} object.
82 * @event
83 */
84 static readonly EVENT_END: "end";
85 /**
86 * Factory events
87 */
88 /**
89 * Triggered when the converter has created a project reflection.
90 * The listener will be given {@link Context} and a {@link Models.ProjectReflection}.
91 * @event
92 */
93 static readonly EVENT_CREATE_PROJECT: "createProject";
94 /**
95 * Triggered when the converter has created a declaration reflection.
96 * The listener will be given {@link Context} and a {@link Models.DeclarationReflection}.
97 * @event
98 */
99 static readonly EVENT_CREATE_DECLARATION: "createDeclaration";
100 /**
101 * Triggered when the converter has created a document reflection.
102 * The listener will be given `undefined` (for consistency with the
103 * other create events) and a {@link Models.DocumentReflection}.
104 * @event
105 */
106 static readonly EVENT_CREATE_DOCUMENT: "createDocument";
107 /**
108 * Triggered when the converter has created a signature reflection.
109 * The listener will be given {@link Context}, {@link Models.SignatureReflection} | {@link Models.ProjectReflection} the declaration,
110 * `ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature | undefined`,
111 * and `ts.Signature | undefined`. The signature will be undefined if the created signature is an index signature.
112 * @event
113 */
114 static readonly EVENT_CREATE_SIGNATURE: "createSignature";
115 /**
116 * Triggered when the converter has created a parameter reflection.
117 * The listener will be given {@link Context}, {@link Models.ParameterReflection} and a `ts.Node?`
118 * @event
119 */
120 static readonly EVENT_CREATE_PARAMETER: "createParameter";
121 /**
122 * Triggered when the converter has created a type parameter reflection.
123 * The listener will be given {@link Context} and a {@link Models.TypeParameterReflection}
124 * @event
125 */
126 static readonly EVENT_CREATE_TYPE_PARAMETER: "createTypeParameter";
127 /**
128 * Resolve events
129 */
130 /**
131 * Triggered when the converter begins resolving a project.
132 * The listener will be given {@link Context}.
133 * @event
134 */
135 static readonly EVENT_RESOLVE_BEGIN: "resolveBegin";
136 /**
137 * Triggered when the converter resolves a reflection.
138 * The listener will be given {@link Context} and a {@link Reflection}.
139 * @event
140 */
141 static readonly EVENT_RESOLVE: "resolveReflection";
142 /**
143 * Triggered when the converter has finished resolving a project.
144 * The listener will be given {@link Context}.
145 * @event
146 */
147 static readonly EVENT_RESOLVE_END: "resolveEnd";
148 /** @internal @hidden */
149 includePlugin: IncludePlugin;
150 constructor(owner: Application);
151 /**
152 * Compile the given source files and create a project reflection for them.
153 */
154 convert(entryPoints: readonly DocumentationEntryPoint[]): ProjectReflection;
155 /** @internal */
156 addProjectDocuments(project: ProjectReflection): void;
157 /** @internal */
158 convertSymbol(context: Context, symbol: ts.Symbol, exportSymbol?: ts.Symbol): void;
159 /**
160 * Convert the given TypeScript type into its TypeDoc type reflection.
161 *
162 * @param context The context object describing the current state the converter is in.
163 * @returns The TypeDoc type reflection representing the given node and type.
164 * @internal
165 */
166 convertType(context: Context, node: ts.TypeNode | ts.Type | undefined): SomeType;
167 /**
168 * Parse the given file into a comment. Intended to be used with markdown files.
169 */
170 parseRawComment(file: MinimalSourceFile, files: FileRegistry): {
171 content: CommentDisplayPart[];
172 frontmatter: Record<string, unknown>;
173 };
174 /**
175 * Adds a new resolver that the theme can use to try to figure out how to link to a symbol declared
176 * by a third-party library which is not included in the documentation.
177 *
178 * The resolver function will be passed a declaration reference which it can attempt to resolve. If
179 * resolution fails, the function should return undefined.
180 *
181 * Note: This will be used for both references to types declared in node_modules (in which case the
182 * reference passed will have the `moduleSource` set and the `symbolReference` will navigate via `.`)
183 * and user defined \{\@link\} tags which cannot be resolved. If the link being resolved is inferred
184 * from a type, then no `part` will be passed to the resolver function.
185 */
186 addUnknownSymbolResolver(resolver: ExternalSymbolResolver): void;
187 /** @internal */
188 resolveExternalLink(ref: DeclarationReference, refl: Reflection, part: CommentDisplayPart | undefined, symbolId: ReflectionSymbolId | undefined): ExternalResolveResult | string | undefined;
189 resolveLinks(comment: Comment, owner: Reflection): void;
190 resolveLinks(parts: readonly CommentDisplayPart[], owner: Reflection): CommentDisplayPart[];
191 /**
192 * Compile the files within the given context and convert the compiler symbols to reflections.
193 *
194 * @param context The context object describing the current state the converter is in.
195 * @returns An array containing all errors generated by the TypeScript compiler.
196 */
197 private compile;
198 private convertExports;
199 private convertReExports;
200 /**
201 * Resolve the project within the given context.
202 *
203 * @param context The context object describing the current state the converter is in.
204 * @returns The final project reflection.
205 */
206 private resolve;
207 /**
208 * Used to determine if we should immediately bail when creating a reflection.
209 * Note: This should not be used for excludeNotDocumented because we don't have enough
210 * information at this point since comment discovery hasn't happened.
211 * @internal
212 */
213 shouldIgnore(symbol: ts.Symbol): boolean;
214 private isExcluded;
215 /** @internal */
216 isExternal(symbol: ts.Symbol): boolean;
217 processDocumentTags(reflection: Reflection, parent: ContainerReflection): void;
218 private addDocument;
219 private _buildCommentParserConfig;
220}