Skip to content

Commit 06624b2

Browse files
committed
Adds the JSDoc 'see' tag
1 parent 8c7ad21 commit 06624b2

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

Diff for: tsdoc/src/details/StandardTags.ts

+26
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,31 @@ export class StandardTags {
319319
standardization: Standardization.Extended
320320
});
321321

322+
/**
323+
* (Extended)
324+
*
325+
* Used to document another symbol or resource that may be related to the current item being documented.
326+
*
327+
* @remarks
328+
*
329+
* For example:
330+
*
331+
* ```ts
332+
* /**
333+
* * Make a rectangle from two points.
334+
* *
335+
* * @see {@link Point}
336+
* */
337+
* function makeRect(a: Point, b: Point): Rect;
338+
* ```
339+
*/
340+
public static readonly see: TSDocTagDefinition = StandardTags._defineTag({
341+
tagName: '@see',
342+
synonyms: ['@seeAlso'],
343+
syntaxKind: TSDocTagSyntaxKind.BlockTag,
344+
standardization: Standardization.Extended
345+
});
346+
322347
/**
323348
* (Extended)
324349
*
@@ -413,6 +438,7 @@ export class StandardTags {
413438
StandardTags.remarks,
414439
StandardTags.returns,
415440
StandardTags.sealed,
441+
StandardTags.see,
416442
StandardTags.throws,
417443
StandardTags.typeParam,
418444
StandardTags.virtual

Diff for: tsdoc/src/emitters/TSDocEmitter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class TSDocEmitter {
130130
docComment.typeParams,
131131
docComment.returnsBlock,
132132
...docComment.customBlocks,
133+
...docComment.seeBlocks,
133134
docComment.inheritDocTag
134135
]);
135136
if (docComment.modifierTagSet.nodes.length > 0) {

Diff for: tsdoc/src/nodes/DocComment.ts

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DocNode, DocNodeKind, IDocNodeParameters } from './DocNode';
22
import { DocSection } from './DocSection';
33
import { StandardModifierTagSet } from '../details/StandardModifierTagSet';
44
import { IModifierTagSetParameters } from '../details/ModifierTagSet';
5+
import { StandardTags } from '../details/StandardTags';
56
import { DocBlock } from './DocBlock';
67
import { DocInheritDocTag } from './DocInheritDocTag';
78
import { StringBuilder } from '../emitters/StringBuilder';
@@ -88,6 +89,7 @@ export class DocComment extends DocNode {
8889
*/
8990
public readonly modifierTagSet: StandardModifierTagSet;
9091

92+
private _seeBlocks: DocBlock[];
9193
private _customBlocks: DocBlock[];
9294

9395
/**
@@ -106,6 +108,7 @@ export class DocComment extends DocNode {
106108
this.returnsBlock = undefined;
107109
this.modifierTagSet = new StandardModifierTagSet({ configuration: this.configuration });
108110

111+
this._seeBlocks = [];
109112
this._customBlocks = [];
110113
}
111114

@@ -114,13 +117,30 @@ export class DocComment extends DocNode {
114117
return DocNodeKind.Comment;
115118
}
116119

120+
/**
121+
* The collection of all `@see` DocBlockTag nodes belonging to this doc comment.
122+
*/
123+
public get seeBlocks(): ReadonlyArray<DocBlock> {
124+
return this._seeBlocks;
125+
}
126+
117127
/**
118128
* The collection of all DocBlock nodes belonging to this doc comment.
119129
*/
120130
public get customBlocks(): ReadonlyArray<DocBlock> {
121131
return this._customBlocks;
122132
}
123133

134+
/**
135+
* Append an item to the seeBlocks collection.
136+
*/
137+
public appendSeeBlock(block: DocBlock): void {
138+
if (!StandardTags.see.isDefinitionOfTag(block.blockTag)) {
139+
throw new Error("Provided block is not a @see block.");
140+
}
141+
this._seeBlocks.push(block);
142+
}
143+
124144
/**
125145
* Append an item to the customBlocks collection.
126146
*/
@@ -139,6 +159,7 @@ export class DocComment extends DocNode {
139159
this.typeParams.count > 0 ? this.typeParams : undefined,
140160
this.returnsBlock,
141161
...this.customBlocks,
162+
...this.seeBlocks,
142163
this.inheritDocTag,
143164
...this.modifierTagSet.nodes
144165
];

Diff for: tsdoc/src/parser/NodeParser.ts

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ export class NodeParser {
323323
docComment.deprecatedBlock = block;
324324
} else if (StandardTags.returns.isDefinitionOfTag(block.blockTag)) {
325325
docComment.returnsBlock = block;
326+
} else if (StandardTags.see.isDefinitionOfTag(block.blockTag)) {
327+
docComment.appendSeeBlock(block);
326328
} else {
327329
docComment.appendCustomBlock(block);
328330
}

0 commit comments

Comments
 (0)