Skip to content

Commit f00ae8d

Browse files
devversionjelbourn
authored andcommitted
build: fix docs not displaying inherited members properly (#17145)
Recently due to the MDC prototypes, we have multiple layers of inheritance. Apparently our current docs tooling sometimes does not display inherited members which are coming from implicitly inherited class-like documents. For example: see how the `MatTabLink` docs broke when the MDC prototype landed: 492fdcc40
1 parent 66c8708 commit f00ae8d

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

tools/dgeni/processors/docs-private-filter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {getDocsPublicTag, isPublicDoc} from '../common/private-docs';
99
export class DocsPrivateFilter implements Processor {
1010
name = 'docs-private-filter';
1111
$runBefore = ['categorizer'];
12+
$runAfter = ['merge-inherited-properties'];
1213

1314
$process(docs: DocCollection) {
1415
return docs.filter(doc => {

tools/dgeni/processors/merge-inherited-properties.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {DocCollection, Processor} from 'dgeni';
22
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
3+
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
34
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
45

56
/**
@@ -11,18 +12,30 @@ export class MergeInheritedProperties implements Processor {
1112
$runBefore = ['categorizer'];
1213

1314
$process(docs: DocCollection) {
14-
return docs
15-
.filter(doc => doc.docType === 'class')
16-
.forEach(doc => this._addInheritedProperties(doc));
15+
return docs.filter(doc => doc.docType === 'class')
16+
.forEach(doc => this._addInheritedProperties(doc));
1717
}
1818

19-
private _addInheritedProperties(doc: ClassExportDoc) {
20-
doc.implementsClauses.filter(clause => clause.doc).forEach(clause => {
21-
clause.doc!.members.forEach(member => this._addMemberDocIfNotPresent(doc, member));
22-
});
19+
/** Gets all class like export documents which the given doc inherits from. */
20+
private _getBaseDocuments(doc: ClassLikeExportDoc): ClassLikeExportDoc[] {
21+
const directBaseDocs = [
22+
...doc.implementsClauses.filter(clause => clause.doc).map(d => d.doc!),
23+
...doc.extendsClauses.filter(clause => clause.doc).map(d => d.doc!),
24+
];
2325

24-
doc.extendsClauses.filter(clause => clause.doc).forEach(clause => {
25-
clause.doc!.members.forEach(member => this._addMemberDocIfNotPresent(doc, member));
26+
return [
27+
...directBaseDocs,
28+
// recursively collect base documents of direct base documents.
29+
...directBaseDocs.reduce(
30+
(res: ClassLikeExportDoc[], d) => res.concat(this._getBaseDocuments(d)), []),
31+
];
32+
}
33+
34+
private _addInheritedProperties(doc: ClassExportDoc) {
35+
// Note that we need to get check all base documents. We cannot assume
36+
// that directive base documents already have merged inherited members.
37+
this._getBaseDocuments(doc).forEach(d => {
38+
d.members.forEach(member => this._addMemberDocIfNotPresent(doc, member));
2639
});
2740
}
2841

0 commit comments

Comments
 (0)