Skip to content

Commit

Permalink
build: fix docs not display inherited members properly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
devversion committed Sep 19, 2019
1 parent 66c8708 commit 3bd9850
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions tools/dgeni/processors/docs-private-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {getDocsPublicTag, isPublicDoc} from '../common/private-docs';
export class DocsPrivateFilter implements Processor {
name = 'docs-private-filter';
$runBefore = ['categorizer'];
$runAfter = ['merge-inherited-properties'];

$process(docs: DocCollection) {
return docs.filter(doc => {
Expand Down
31 changes: 22 additions & 9 deletions tools/dgeni/processors/merge-inherited-properties.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {DocCollection, Processor} from 'dgeni';
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';

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

$process(docs: DocCollection) {
return docs
.filter(doc => doc.docType === 'class')
.forEach(doc => this._addInheritedProperties(doc));
return docs.filter(doc => doc.docType === 'class')
.forEach(doc => this._addInheritedProperties(doc));
}

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

doc.extendsClauses.filter(clause => clause.doc).forEach(clause => {
clause.doc!.members.forEach(member => this._addMemberDocIfNotPresent(doc, member));
return [
...directBaseDocs,
// recursively collect base documents of direct base documents.
...directBaseDocs.reduce(
(res: ClassLikeExportDoc[], d) => res.concat(this._getBaseDocuments(d)), []),
];
}

private _addInheritedProperties(doc: ClassExportDoc) {
// Note that we need to get check all base documents. We cannot assume
// that directive base documents already have merged inherited members.
this._getBaseDocuments(doc).forEach(d => {
d.members.forEach(member => this._addMemberDocIfNotPresent(doc, member));
});
}

Expand Down

0 comments on commit 3bd9850

Please sign in to comment.