Skip to content

Commit d8f2540

Browse files
committed
Adds the JSDoc 'see' tag
1 parent 7b10820 commit d8f2540

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
@@ -331,6 +331,31 @@ export class StandardTags {
331331
standardization: Standardization.Extended
332332
});
333333

334+
/**
335+
* (Extended)
336+
*
337+
* Used to document another symbol or resource that may be related to the current item being documented.
338+
*
339+
* @remarks
340+
*
341+
* For example:
342+
*
343+
* ```ts
344+
* /**
345+
* * Make a rectangle from two points.
346+
* *
347+
* * @see {@link Point}
348+
* */
349+
* function makeRect(a: Point, b: Point): Rect;
350+
* ```
351+
*/
352+
public static readonly see: TSDocTagDefinition = StandardTags._defineTag({
353+
tagName: '@see',
354+
synonyms: ['@seeAlso'],
355+
syntaxKind: TSDocTagSyntaxKind.BlockTag,
356+
standardization: Standardization.Extended
357+
});
358+
334359
/**
335360
* (Extended)
336361
*
@@ -425,6 +450,7 @@ export class StandardTags {
425450
StandardTags.remarks,
426451
StandardTags.returns,
427452
StandardTags.sealed,
453+
StandardTags.see,
428454
StandardTags.throws,
429455
StandardTags.typeParam,
430456
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)