Skip to content

Commit f2cafaf

Browse files
committed
[AD]: Handle @throws
1 parent 4c9b7d3 commit f2cafaf

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

apps/api-documenter/src/documenters/MarkdownDocumenter.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export class MarkdownDocumenter {
234234
case ApiItemKind.MethodSignature:
235235
case ApiItemKind.Function:
236236
this._writeParameterTables(output, apiItem as ApiParameterListMixin);
237+
this._writeThrowsSection(output, apiItem);
237238
break;
238239
case ApiItemKind.Namespace:
239240
this._writePackageOrNamespaceTables(output, apiItem as ApiNamespace);
@@ -318,6 +319,27 @@ export class MarkdownDocumenter {
318319
}
319320
}
320321

322+
private _writeThrowsSection(output: DocSection, apiItem: ApiItem): void {
323+
if (apiItem instanceof ApiDocumentedItem) {
324+
const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
325+
326+
if (tsdocComment) {
327+
// Write the @throws blocks
328+
const throwsBlocks: DocBlock[] = tsdocComment.customBlocks.filter(x => x.blockTag.tagNameWithUpperCase
329+
=== StandardTags.throws.tagNameWithUpperCase);
330+
331+
if (throwsBlocks.length > 0) {
332+
const heading: string = 'Exceptions';
333+
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: heading }));
334+
335+
for (const throwsBlock of throwsBlocks) {
336+
this._appendSection(output, throwsBlock.content);
337+
}
338+
}
339+
}
340+
}
341+
}
342+
321343
/**
322344
* GENERATE PAGE: MODEL
323345
*/

build-tests/api-documenter-test/etc/api-documenter-test.api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
{
172172
"kind": "Method",
173173
"canonicalReference": "api-documenter-test!DocClass1#exampleFunction:member(1)",
174-
"docComment": "/**\n * This is an overloaded function.\n *\n * @param a - the first string\n *\n * @param b - the second string\n */\n",
174+
"docComment": "/**\n * This is an overloaded function.\n *\n * @param a - the first string\n *\n * @param b - the second string\n *\n * @throws\n *\n * `Error` The first throws line\n *\n * @throws\n *\n * The second throws line\n */\n",
175175
"excerptTokens": [
176176
{
177177
"kind": "Content",

build-tests/api-documenter-test/etc/markdown/api-documenter-test.docclass1.examplefunction.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ exampleFunction(a: string, b: string): string;
2323

2424
`string`
2525

26+
## Exceptions
27+
28+
`Error` The first throws line
29+
30+
The second throws line
31+

build-tests/api-documenter-test/src/DocClass1.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ export class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInter
158158
* This is an overloaded function.
159159
* @param a - the first string
160160
* @param b - the second string
161+
*
162+
* @throws `Error`
163+
* The first throws line
164+
*
165+
* @throws The second throws line
161166
*/
162167
exampleFunction(a: string, b: string): string;
163168

0 commit comments

Comments
 (0)