Skip to content

Commit 21c79dc

Browse files
committed
Adds the JSDoc 'see' tag
1 parent 6130309 commit 21c79dc

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
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

+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
/**
@@ -109,6 +112,7 @@ export class DocComment extends DocNode {
109112
};
110113
this.modifierTagSet = new StandardModifierTagSet(modifierTagSetParameters);
111114

115+
this._seeBlocks = [];
112116
this._customBlocks = [];
113117
}
114118

@@ -117,13 +121,30 @@ export class DocComment extends DocNode {
117121
return DocNodeKind.Comment;
118122
}
119123

124+
/**
125+
* The collection of all `@see` DocBlockTag nodes belonging to this doc comment.
126+
*/
127+
public get seeBlocks(): ReadonlyArray<DocBlock> {
128+
return this._seeBlocks;
129+
}
130+
120131
/**
121132
* The collection of all DocBlock nodes belonging to this doc comment.
122133
*/
123134
public get customBlocks(): ReadonlyArray<DocBlock> {
124135
return this._customBlocks;
125136
}
126137

138+
/**
139+
* Append an item to the seeBlocks collection.
140+
*/
141+
public appendSeeBlock(block: DocBlock): void {
142+
if (!StandardTags.see.isDefinitionOfTag(block.blockTag)) {
143+
throw new Error("Provided block is not a @see block.");
144+
}
145+
this._seeBlocks.push(block);
146+
}
147+
127148
/**
128149
* Append an item to the customBlocks collection.
129150
*/
@@ -142,6 +163,7 @@ export class DocComment extends DocNode {
142163
this.typeParams.count > 0 ? this.typeParams : undefined,
143164
this.returnsBlock,
144165
...this.customBlocks,
166+
...this.seeBlocks,
145167
this.inheritDocTag,
146168
...this.modifierTagSet.nodes
147169
];
@@ -169,5 +191,4 @@ export class DocComment extends DocNode {
169191
}
170192

171193
// Circular reference
172-
import { TSDocEmitter } from '../emitters/TSDocEmitter';import { IModifierTagSetParameters } from '../details/ModifierTagSet';
173-
194+
import { TSDocEmitter } from '../emitters/TSDocEmitter';

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)