UNPKG

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