Skip to content

Commit

Permalink
Merge pull request #1632 from vidartf/throws
Browse files Browse the repository at this point in the history
[api-extractor]: Add support for `@throws`
  • Loading branch information
octogonz authored Nov 24, 2019
2 parents 625c095 + c8011fe commit 248c0a8
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
22 changes: 22 additions & 0 deletions apps/api-documenter/src/documenters/MarkdownDocumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export class MarkdownDocumenter {
case ApiItemKind.MethodSignature:
case ApiItemKind.Function:
this._writeParameterTables(output, apiItem as ApiParameterListMixin);
this._writeThrowsSection(output, apiItem);
break;
case ApiItemKind.Namespace:
this._writePackageOrNamespaceTables(output, apiItem as ApiNamespace);
Expand Down Expand Up @@ -318,6 +319,27 @@ export class MarkdownDocumenter {
}
}

private _writeThrowsSection(output: DocSection, apiItem: ApiItem): void {
if (apiItem instanceof ApiDocumentedItem) {
const tsdocComment: DocComment | undefined = apiItem.tsdocComment;

if (tsdocComment) {
// Write the @throws blocks
const throwsBlocks: DocBlock[] = tsdocComment.customBlocks.filter(x => x.blockTag.tagNameWithUpperCase
=== StandardTags.throws.tagNameWithUpperCase);

if (throwsBlocks.length > 0) {
const heading: string = 'Exceptions';
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: heading }));

for (const throwsBlock of throwsBlocks) {
this._appendSection(output, throwsBlock.content);
}
}
}
}
}

/**
* GENERATE PAGE: MODEL
*/
Expand Down
1 change: 1 addition & 0 deletions apps/api-extractor-model/src/aedoc/AedocDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class AedocDefinitions {
StandardTags.remarks,
StandardTags.returns,
StandardTags.sealed,
StandardTags.throws,
StandardTags.virtual
],
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
{
"kind": "Method",
"canonicalReference": "api-documenter-test!DocClass1#exampleFunction:member(1)",
"docComment": "/**\n * This is an overloaded function.\n *\n * @param a - the first string\n *\n * @param b - the second string\n */\n",
"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",
"excerptTokens": [
{
"kind": "Content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ exampleFunction(a: string, b: string): string;

`string`

## Exceptions

`Error` The first throws line

The second throws line

5 changes: 5 additions & 0 deletions build-tests/api-documenter-test/src/DocClass1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInter
* This is an overloaded function.
* @param a - the first string
* @param b - the second string
*
* @throws `Error`
* The first throws line
*
* @throws The second throws line
*/
exampleFunction(a: string, b: string): string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/api-documenter",
"comment": "Added support for `@throws`",
"type": "minor"
}
],
"packageName": "@microsoft/api-documenter",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor-model",
"comment": "Added support for `@throws`",
"type": "minor"
}
],
"packageName": "@microsoft/api-extractor-model",
"email": "[email protected]"
}

0 comments on commit 248c0a8

Please sign in to comment.