Skip to content

Commit 897e739

Browse files
authored
docs: incorrect descriptions for inherited class members (#22766)
In #22482 some changes were made that switched the doc rendering from `description` to `content` in an attempt to expose the descriptions for inherited class members. It turns out that `content` is actually the description of the member including `@param` and `@returns` tags which we don't want to show either. After some investigation, it turns out that the root cause of the descriptions not being shown is that dgeni won't assign a `description` if the base class isn't exported. These changes resolve the issue by falling back to `content` if there is no `description` and stripping out the JSDoc tags from it manually.
1 parent 31ffc5b commit 897e739

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

tools/dgeni/common/dgeni-definitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface CategorizedClassDoc extends ClassExportDoc, CategorizedClassLik
4040

4141
/** Extended Dgeni property-member document that includes extracted Angular metadata. */
4242
export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc, DeprecationInfo {
43+
description: string;
4344
isDirectiveInput: boolean;
4445
isDirectiveOutput: boolean;
4546
directiveInputAlias: string;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,20 @@ export class MergeInheritedProperties implements Processor {
5252
// by using an instance comparison.
5353
// tslint:disable-next-line:ban Need to use Object.assign to preserve the prototype.
5454
const newMemberDoc = Object.assign(Object.create(memberDoc), memberDoc);
55+
56+
// Dgeni won't add the `description` if the member doc belongs to a class
57+
// that isn't exported. If that's the case, we fall back to assigning it
58+
// ourselves by stripping JSDoc tags from the raw description.
59+
// TODO: figure out a more robust solution that will ensure that the description is
60+
// always added.
61+
newMemberDoc.description = newMemberDoc.description || stripJsDocTags(memberDoc.content);
5562
newMemberDoc.containerDoc = destination;
5663
destination.members.push(newMemberDoc);
5764
}
5865
}
5966
}
67+
68+
/** Strips all of the content after the first JSDoc tag from a string. */
69+
function stripJsDocTags(text: string): string {
70+
return text.split(/\s@[a-zA-Z-]*\s/)[0];
71+
}

tools/dgeni/templates/method.template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
</th>
1919
</tr>
2020
</thead>
21-
{%- if method.content -%}
21+
{%- if method.description -%}
2222
<tr class="docs-api-method-description-row">
2323
<td colspan="2" class="docs-api-method-description-cell">
24-
{$ method.content | marked | safe $}
24+
{$ method.description | marked | safe $}
2525
</td>
2626
</tr>
2727
{%- endif -%}

tools/dgeni/templates/property.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
<code>{$ property.name $}: {$ property.type $}</code>
3131
</p>
3232
</td>
33-
<td class="docs-api-property-description">{$ property.content | marked | safe $}</td>
33+
<td class="docs-api-property-description">{$ property.description | marked | safe $}</td>
3434
</tr>

0 commit comments

Comments
 (0)