X Tutup
Skip to content

Commit 96ee444

Browse files
committed
Handle cyclic references for @inheritDoc
1 parent 212394a commit 96ee444

File tree

7 files changed

+139
-4
lines changed

7 files changed

+139
-4
lines changed

apps/api-extractor/src/api/ExtractorMessageId.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ export const enum ExtractorMessageId {
7070
* will find a corresponding member from a base class (or implemented interface). Until then, the tag
7171
* always needs an explicit declaration reference such as `{@inhertDoc MyBaseClass.sameMethod}`.
7272
*/
73-
UnresolvedInheritDocBase = 'ae-unresolved-inheritdoc-base'
73+
UnresolvedInheritDocBase = 'ae-unresolved-inheritdoc-base',
74+
75+
/**
76+
* "The `@inheritDoc` tag for ____ refers to its own declaration".
77+
*/
78+
CyclicInheritDoc = 'ae-cyclic-inherit-doc'
7479
}
7580

7681
export const allExtractorMessageIds: Set<string> = new Set<string>([
@@ -84,5 +89,6 @@ export const allExtractorMessageIds: Set<string> = new Set<string>([
8489
'ae-preapproved-unsupported-type',
8590
'ae-preapproved-bad-release-tag',
8691
'ae-unresolved-inheritdoc-reference',
87-
'ae-unresolved-inheritdoc-base'
92+
'ae-unresolved-inheritdoc-base',
93+
'ae-cyclic-inherit-doc'
8894
]);

apps/api-extractor/src/enhancers/DocCommentEnhancer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { AstSymbol } from '../analyzer/AstSymbol';
99
import { AstDeclaration } from '../analyzer/AstDeclaration';
1010
import { DeclarationMetadata } from '../collector/DeclarationMetadata';
1111
import { AedocDefinitions } from '@microsoft/api-extractor-model';
12-
import { InternalError } from '@microsoft/node-core-library';
1312
import { ExtractorMessageId } from '../api/ExtractorMessageId';
1413
import { VisitorState } from '../collector/VisitorState';
1514

@@ -44,7 +43,12 @@ export class DocCommentEnhancer {
4443
}
4544

4645
if (metadata.docCommentEnhancerVisitorState === VisitorState.Visiting) {
47-
throw new InternalError('Infinite loop in DocCommentEnhancer._analyzeDeclaration()');
46+
this._collector.messageRouter.addAnalyzerIssue(
47+
ExtractorMessageId.CyclicInheritDoc,
48+
`The @inheritDoc tag for "${astDeclaration.astSymbol.localName}" refers to its own declaration`,
49+
astDeclaration
50+
);
51+
return;
4852
}
4953
metadata.docCommentEnhancerVisitorState = VisitorState.Visiting;
5054

build-tests/api-extractor-scenarios/etc/test-outputs/docReferences2/api-extractor-scenarios.api.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,94 @@
189189
}
190190
],
191191
"implementsTokenRanges": []
192+
},
193+
{
194+
"kind": "Class",
195+
"canonicalReference": "(FailWithSelfReference:class)",
196+
"docComment": "/**\n * @public\n */\n",
197+
"excerptTokens": [
198+
{
199+
"kind": "Content",
200+
"text": "export declare class "
201+
},
202+
{
203+
"kind": "Reference",
204+
"text": "FailWithSelfReference"
205+
},
206+
{
207+
"kind": "Content",
208+
"text": " "
209+
}
210+
],
211+
"releaseTag": "Public",
212+
"name": "FailWithSelfReference",
213+
"members": [
214+
{
215+
"kind": "Method",
216+
"canonicalReference": "(method1:instance,0)",
217+
"docComment": "",
218+
"excerptTokens": [
219+
{
220+
"kind": "Reference",
221+
"text": "method1"
222+
},
223+
{
224+
"kind": "Content",
225+
"text": "(): "
226+
},
227+
{
228+
"kind": "Content",
229+
"text": "void"
230+
},
231+
{
232+
"kind": "Content",
233+
"text": ";"
234+
}
235+
],
236+
"isStatic": false,
237+
"returnTypeTokenRange": {
238+
"startIndex": 2,
239+
"endIndex": 3
240+
},
241+
"releaseTag": "Public",
242+
"overloadIndex": 0,
243+
"parameters": [],
244+
"name": "method1"
245+
},
246+
{
247+
"kind": "Method",
248+
"canonicalReference": "(method2:instance,0)",
249+
"docComment": "",
250+
"excerptTokens": [
251+
{
252+
"kind": "Reference",
253+
"text": "method2"
254+
},
255+
{
256+
"kind": "Content",
257+
"text": "(): "
258+
},
259+
{
260+
"kind": "Content",
261+
"text": "void"
262+
},
263+
{
264+
"kind": "Content",
265+
"text": ";"
266+
}
267+
],
268+
"isStatic": false,
269+
"returnTypeTokenRange": {
270+
"startIndex": 2,
271+
"endIndex": 3
272+
},
273+
"releaseTag": "Public",
274+
"overloadIndex": 0,
275+
"parameters": [],
276+
"name": "method2"
277+
}
278+
],
279+
"implementsTokenRanges": []
192280
}
193281
]
194282
}

build-tests/api-extractor-scenarios/etc/test-outputs/docReferences2/api-extractor-scenarios.api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export class CyclicB {
1616
methodB4(): void;
1717
}
1818

19+
// @public (undocumented)
20+
export class FailWithSelfReference {
21+
// Warning: (ae-cyclic-inherit-doc) The @inheritDoc tag for "method1" refers to its own declaration
22+
//
23+
// (undocumented)
24+
method1(): void;
25+
// (undocumented)
26+
method2(): void;
27+
}
28+
1929

2030
// (No @packageDocumentation comment for this package)
2131

build-tests/api-extractor-scenarios/etc/test-outputs/docReferences2/rollup.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ export declare class CyclicB {
1515
methodB4(): void;
1616
}
1717

18+
/** @public */
19+
export declare class FailWithSelfReference {
20+
/** {@inheritDoc FailWithSelfReference.method2} */
21+
method1(): void;
22+
/** {@inheritDoc FailWithSelfReference.method1} */
23+
method2(): void;
24+
}
25+
1826
export { }

build-tests/api-extractor-scenarios/src/docReferences2/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ export class CyclicB {
2020
public methodB4(): void {
2121
}
2222
}
23+
24+
/** @public */
25+
export class FailWithSelfReference {
26+
/** {@inheritDoc FailWithSelfReference.method2} */
27+
public method1(): void {
28+
}
29+
/** {@inheritDoc FailWithSelfReference.method1} */
30+
public method2(): void {
31+
}
32+
}

build-tests/api-extractor-scenarios/src/runScenarios.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ export function runScenarios(buildConfigPath: string): void {
6666
"entryPointSourceFile": `./lib/${scenarioFolderName}/index.d.ts`
6767
},
6868

69+
"messages": {
70+
"extractorMessageReporting": {
71+
"ae-cyclic-inherit-doc": {
72+
"logLevel": "warning",
73+
"addToApiReviewFile": true
74+
}
75+
}
76+
},
77+
6978
"testMode": true
7079
};
7180

0 commit comments

Comments
 (0)
X Tutup