Skip to content

Commit 70614b4

Browse files
committed
Adds the JSDoc 'see' tag
1 parent eac58d3 commit 70614b4

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

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

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) {

tsdoc/src/nodes/DocComment.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { DocBlock } from './DocBlock';
55
import { DocInheritDocTag } from './DocInheritDocTag';
66
import { StringBuilder } from '../emitters/StringBuilder';
77
import { DocParamCollection } from './DocParamCollection';
8+
import { IModifierTagSetParameters } from '../details/ModifierTagSet';
9+
import { StandardTags } from '../details/StandardTags';
810

911
/**
1012
* Constructor parameters for {@link DocComment}.
@@ -87,6 +89,7 @@ export class DocComment extends DocNode {
8789
*/
8890
public readonly modifierTagSet: StandardModifierTagSet;
8991

92+
private _seeBlocks: DocBlock[];
9093
private _customBlocks: DocBlock[];
9194

9295
/**
@@ -105,6 +108,7 @@ export class DocComment extends DocNode {
105108
this.returnsBlock = undefined;
106109
this.modifierTagSet = new StandardModifierTagSet({ configuration: this.configuration });
107110

111+
this._seeBlocks = [];
108112
this._customBlocks = [];
109113
}
110114

@@ -113,13 +117,30 @@ export class DocComment extends DocNode {
113117
return DocNodeKind.Comment;
114118
}
115119

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+
116127
/**
117128
* The collection of all DocBlock nodes belonging to this doc comment.
118129
*/
119130
public get customBlocks(): ReadonlyArray<DocBlock> {
120131
return this._customBlocks;
121132
}
122133

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+
123144
/**
124145
* Append an item to the customBlocks collection.
125146
*/
@@ -138,6 +159,7 @@ export class DocComment extends DocNode {
138159
this.typeParams.count > 0 ? this.typeParams : undefined,
139160
this.returnsBlock,
140161
...this.customBlocks,
162+
...this.seeBlocks,
141163
this.inheritDocTag,
142164
...this.modifierTagSet.nodes
143165
];
@@ -165,5 +187,4 @@ export class DocComment extends DocNode {
165187
}
166188

167189
// Circular reference
168-
import { TSDocEmitter } from '../emitters/TSDocEmitter';import { IModifierTagSetParameters } from '../details/ModifierTagSet';
169-
190+
import { TSDocEmitter } from '../emitters/TSDocEmitter';

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)