@@ -10,7 +10,6 @@ import { AstDeclaration } from '../analyzer/AstDeclaration';
1010import { DeclarationMetadata , VisitorState } from '../collector/DeclarationMetadata' ;
1111import { AedocDefinitions } from '@microsoft/api-extractor-model' ;
1212import { InternalError } from '@microsoft/node-core-library' ;
13- import { ResultOrError } from '../analyzer/AstReferenceResolver' ;
1413import { ExtractorMessageId } from '../api/ExtractorMessageId' ;
1514
1615export class DocCommentEnhancer {
@@ -41,8 +40,10 @@ export class DocCommentEnhancer {
4140 const metadata : DeclarationMetadata = this . _collector . fetchMetadata ( astDeclaration ) ;
4241 if ( metadata . docCommentEnhancerVisitorStage === VisitorState . Visited ) {
4342 return ;
44- } else if ( metadata . docCommentEnhancerVisitorStage === VisitorState . Visiting ) {
45- throw new InternalError ( 'Infinite loop' ) ;
43+ }
44+
45+ if ( metadata . docCommentEnhancerVisitorStage === VisitorState . Visiting ) {
46+ throw new InternalError ( 'Infinite loop in DocCommentEnhancer._analyzeDeclaration()' ) ;
4647 }
4748 metadata . docCommentEnhancerVisitorStage = VisitorState . Visiting ;
4849
@@ -51,6 +52,8 @@ export class DocCommentEnhancer {
5152 }
5253
5354 this . _analyzeNeedsDocumentation ( astDeclaration , metadata ) ;
55+
56+ metadata . docCommentEnhancerVisitorStage = VisitorState . Visited ;
5457 }
5558
5659 private _analyzeNeedsDocumentation ( astDeclaration : AstDeclaration , metadata : DeclarationMetadata ) : void {
@@ -87,6 +90,9 @@ export class DocCommentEnhancer {
8790 }
8891 }
8992
93+ /**
94+ * Follow an `{@inheritDoc ___}` reference and copy the content that we find in the referenced comment.
95+ */
9096 private _analyzeInheritDoc ( astDeclaration : AstDeclaration , docComment : tsdoc . DocComment ,
9197 inheritDocTag : tsdoc . DocInheritDocTag ) : void {
9298
@@ -97,22 +103,27 @@ export class DocCommentEnhancer {
97103 return ;
98104 }
99105
100- const sourceAstDeclaration : ResultOrError < AstDeclaration > = this . _collector . astReferenceResolver
106+ const referencedAstDeclaration : AstDeclaration | Error = this . _collector . astReferenceResolver
101107 . resolve ( inheritDocTag . declarationReference ) ;
102108
103- if ( sourceAstDeclaration instanceof Error ) {
109+ if ( referencedAstDeclaration instanceof Error ) {
104110 this . _collector . messageRouter . addAnalyzerIssue ( ExtractorMessageId . UnresolvedInheritDocReference ,
105- 'The `@inheritDoc` reference could not be resolved: ' + sourceAstDeclaration . message , astDeclaration ) ;
111+ 'The `@inheritDoc` reference could not be resolved: ' + referencedAstDeclaration . message , astDeclaration ) ;
106112 return ;
107113 }
108114
109- const sourceMetadata : DeclarationMetadata = this . _collector . fetchMetadata ( sourceAstDeclaration ) ;
115+ this . _analyzeDeclaration ( referencedAstDeclaration ) ;
116+
117+ const referencedMetadata : DeclarationMetadata = this . _collector . fetchMetadata ( referencedAstDeclaration ) ;
110118
111- if ( sourceMetadata . tsdocComment ) {
112- this . _copyInheritedDocs ( docComment , sourceMetadata . tsdocComment ) ;
119+ if ( referencedMetadata . tsdocComment ) {
120+ this . _copyInheritedDocs ( docComment , referencedMetadata . tsdocComment ) ;
113121 }
114122 }
115123
124+ /**
125+ * Copy the content from `sourceDocComment` to `targetDocComment`.
126+ */
116127 private _copyInheritedDocs ( targetDocComment : tsdoc . DocComment , sourceDocComment : tsdoc . DocComment ) : void {
117128 targetDocComment . summarySection = sourceDocComment . summarySection ;
118129 targetDocComment . remarksBlock = sourceDocComment . remarksBlock ;
0 commit comments