Skip to content

Add support for the @inheritDoc tag #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tsdoc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log - @microsoft/tsdoc

## 0.6.0
- Add support for `@link` tags using the new declaration reference syntax
- Add support for `@inheritDoc` tags
- Add new APIs: `DocDeclarationReference`, `DocInheritDocTag`, `DocLinkTag`, `DocMemberIdentifier`, `DocMemberReference`, `DocMemberSelector`, `DocMemberSymbol`
- Remove `ParserContext.verbatimNodes`
- Add `DocParticle.particleId` property

## 0.5.0
- Add a new API `DocNode.updateParameters()` that allows a `DocNode` object to be updated after it was created; the tree nodes are no longer immutable
- Add `DocNodeTransforms.trimSpacesInParagraphNodes()` for collapsing whitespace inside `DocParagraph` subtrees
Expand Down
2 changes: 1 addition & 1 deletion tsdoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/tsdoc",
"version": "0.5.0",
"version": "0.6.0",
"description": "A parser for the TypeScript doc comment syntax",
"keywords": [
"TypeScript",
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface IDocBlockParameters extends IDocSectionParameters {
* For example, an `@example` block.
*/
export class DocBlock extends DocSection {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.Block;

private _blockTag: DocBlockTag | undefined; // never undefined after updateParameters()
Expand All @@ -41,7 +41,7 @@ export class DocBlock extends DocSection {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
2 changes: 1 addition & 1 deletion tsdoc/src/nodes/DocBlockTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface IDocBlockTagParameters extends IDocNodeLeafParameters {
* Represents a TSDoc block tag such as `@param` or `@public`.
*/
export class DocBlockTag extends DocNodeLeaf {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.BlockTag;

private _tagName: string | undefined; // never undefined after updateParameters()
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocCodeFence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IDocCodeFenceParameters extends IDocNodeParameters {
* can also specify a language for a syntax highlighter.
*/
export class DocCodeFence extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.CodeFence;

// The opening ``` delimiter and padding
Expand Down Expand Up @@ -102,7 +102,7 @@ export class DocCodeFence extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocCodeSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IDocCodeSpanParameters extends IDocNodeParameters {
* backtick characters.
*/
export class DocCodeSpan extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.CodeSpan;

// The opening ` delimiter
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DocCodeSpan extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
49 changes: 20 additions & 29 deletions tsdoc/src/nodes/DocComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DocSection } from './DocSection';
import { StandardModifierTagSet } from '../details/StandardModifierTagSet';
import { DocBlock } from './DocBlock';
import { DocParamBlock } from './DocParamBlock';
import { DocInheritDocTag } from './DocInheritDocTag';

/**
* Constructor parameters for {@link DocComment}.
Expand All @@ -15,7 +16,7 @@ export interface IDocCommentParameters extends IDocNodeParameters {
* This is the root of the DocNode tree.
*/
export class DocComment extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.Comment;

/**
Expand Down Expand Up @@ -72,6 +73,12 @@ export class DocComment extends DocNode {
*/
public returnsBlock: DocBlock | undefined;

/**
* If this doc comment contains an `@inheritDoc` tag, it will be extracted and associated
* with the DocComment.
*/
public inheritDocTag: DocInheritDocTag | undefined;

/**
* The modifier tags for this DocComment.
*/
Expand Down Expand Up @@ -113,36 +120,20 @@ export class DocComment extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
const result: DocNode[] = [ ];

result.push(this.summarySection);

if (this.remarksBlock) {
result.push(this.remarksBlock);
}

if (this.privateRemarks) {
result.push(this.privateRemarks);
}

if (this.deprecatedBlock) {
result.push(this.deprecatedBlock);
}

result.push(...this.paramBlocks);

if (this.returnsBlock) {
result.push(this.returnsBlock);
}

result.push(...this._customBlocks);

result.push(...this.modifierTagSet.nodes);

return result;
return DocNode.trimUndefinedNodes([
this.summarySection,
this.remarksBlock,
this.privateRemarks,
this.deprecatedBlock,
...this.paramBlocks,
this.returnsBlock,
...this._customBlocks,
this.inheritDocTag,
...this.modifierTagSet.nodes
]);
}
}
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocDeclarationReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IDocDeclarationReferenceParameters extends IDocNodeParameters {
* or `{@inheritDoc}` that need to refer to another declaration.
*/
export class DocDeclarationReference extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.DeclarationReference;

private _packageNameParticle: DocParticle | undefined;
Expand Down Expand Up @@ -117,7 +117,7 @@ export class DocDeclarationReference extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
2 changes: 1 addition & 1 deletion tsdoc/src/nodes/DocErrorText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface IDocErrorTextParameters extends IDocNodeLeafParameters {
* The characters should be rendered as plain text.
*/
export class DocErrorText extends DocNodeLeaf {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.ErrorText;

private _text: string | undefined; // never undefined after updateParameters()
Expand Down
2 changes: 1 addition & 1 deletion tsdoc/src/nodes/DocEscapedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum EscapeStyle {
* forces a specific escaping that may not be the default.
*/
export class DocEscapedText extends DocNodeLeaf {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.EscapedText;

private _escapeStyle: EscapeStyle | undefined; // never undefined after updateParameters()
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocHtmlAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IDocHtmlAttributeParameters extends IDocNodeParameters {
* Example: `href="#"` inside `<a href="#" />`
*/
export class DocHtmlAttribute extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.HtmlAttribute;

// The attribute name
Expand Down Expand Up @@ -109,7 +109,7 @@ export class DocHtmlAttribute extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocHtmlEndTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IDocHtmlEndTagParameters extends IDocNodeParameters {
* Represents an HTML end tag. Example: `</a>`
*/
export class DocHtmlEndTag extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.HtmlEndTag;

// The "</" delimiter
Expand Down Expand Up @@ -69,7 +69,7 @@ export class DocHtmlEndTag extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocHtmlStartTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IDocHtmlStartTagParameters extends IDocNodeParameters {
* Example: `<a href="#" />`
*/
export class DocHtmlStartTag extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.HtmlStartTag;

// The "<" delimiter
Expand Down Expand Up @@ -107,7 +107,7 @@ export class DocHtmlStartTag extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
65 changes: 65 additions & 0 deletions tsdoc/src/nodes/DocInheritDocTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { DocNodeKind, DocNode } from './DocNode';
import { DocInlineTag, IDocInlineTagParameters } from './DocInlineTag';
import { DocDeclarationReference } from './DocDeclarationReference';

/**
* Constructor parameters for {@link DocInheritDocTag}.
*/
export interface IDocInheritDocTagParameters extends IDocInlineTagParameters {
declarationReference?: DocDeclarationReference;
}

/**
* Represents an `{@inheritDoc}` tag.
*/
export class DocInheritDocTag extends DocInlineTag {

/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.InheritDocTag;

private _declarationReference: DocDeclarationReference | undefined;

/**
* Don't call this directly. Instead use {@link TSDocParser}
* @internal
*/
public constructor(parameters: IDocInheritDocTagParameters) {
super(parameters);
}

/**
* The declaration that the documentation will be inherited from.
* If omitted, the documentation will be inherited from the parent class.
*/
public get declarationReference(): DocDeclarationReference | undefined {
return this._declarationReference;
}

/** @override */
public updateParameters(parameters: IDocInheritDocTagParameters): void {
if (parameters.tagName.toUpperCase() !== '@INHERITDOC') {
throw new Error('DocInheritDocTag requires the tag name to be "{@inheritDoc}"');
}

super.updateParameters(parameters);

this._declarationReference = parameters.declarationReference;
}

/**
* {@inheritDoc}
* @override
*/
protected getChildNodesForContent(): ReadonlyArray<DocNode> {
if (this.tagContentParticle.excerpt) {
// If the parser associated the inline tag input with the tagContentExcerpt (e.g. because
// second stage parsing encountered an error), then fall back to the base class's representation
return super.getChildNodesForContent();
} else {
// Otherwise return the detailed structure
return DocNode.trimUndefinedNodes([
this._declarationReference
]);
}
}
}
6 changes: 3 additions & 3 deletions tsdoc/src/nodes/DocInlineTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export interface IDocInlineTagParameters extends IDocNodeParameters {
}

/**
* Represents a TSDoc inline tag such as `{@inheritdoc}` or `{@link}`.
* Represents a TSDoc inline tag such as `{@inheritDoc}` or `{@link}`.
*/
export class DocInlineTag extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.InlineTag;

private _openingDelimiterParticle: DocParticle | undefined; // never undefined after updateParameters()
Expand Down Expand Up @@ -88,7 +88,7 @@ export class DocInlineTag extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override @sealed
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocLinkTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IDocLinkTagParameters extends IDocInlineTagParameters {
*/
export class DocLinkTag extends DocInlineTag {

/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.LinkTag;

private _codeDestination: DocDeclarationReference | undefined;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class DocLinkTag extends DocInlineTag {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
protected getChildNodesForContent(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocMemberIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IDocMemberIdentifierParameters extends IDocNodeParameters {
* A member identifier is part of a {@link DocMemberReference}.
*/
export class DocMemberIdentifier extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.MemberIdentifier;

private _leftQuoteParticle: DocParticle | undefined;
Expand Down Expand Up @@ -97,7 +97,7 @@ export class DocMemberIdentifier extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
4 changes: 2 additions & 2 deletions tsdoc/src/nodes/DocMemberReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface IDocMemberReferenceParameters extends IDocNodeParameters {
* `ui`, `.controls`, and `.Button`, and `.(render:static)`.
*/
export class DocMemberReference extends DocNode {
/** {@inheritdoc} */
/** {@inheritDoc} */
public readonly kind: DocNodeKind = DocNodeKind.MemberReference;

// The "." token if unless this was the member reference in the chain
Expand Down Expand Up @@ -148,7 +148,7 @@ export class DocMemberReference extends DocNode {
}

/**
* {@inheritdoc}
* {@inheritDoc}
* @override
*/
public getChildNodes(): ReadonlyArray<DocNode> {
Expand Down
Loading