From 1b9ec50245d2c0860919c50cc13a279dc34a4a3d Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Tue, 7 May 2024 00:17:18 +0100 Subject: [PATCH] fix(core): fix missing extended by definitions --- .../resources/partials/member.hierarchy.ts | 59 ++++++++------- .../test/fixtures/src/reflections/classes.ts | 6 ++ .../__snapshots__/navigation.spec.ts.snap | 25 +++++++ .../reflection.class.spec.ts.snap | 71 +++++++++++++++++++ .../specs/__snapshots__/urls.spec.ts.snap | 10 +++ .../test/specs/reflection.class.spec.ts | 17 +++++ 6 files changed, 164 insertions(+), 24 deletions(-) diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/partials/member.hierarchy.ts b/packages/typedoc-plugin-markdown/src/theme/resources/partials/member.hierarchy.ts index 24ca07041..e1434b620 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/partials/member.hierarchy.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/partials/member.hierarchy.ts @@ -11,31 +11,42 @@ export function hierarchy( options: { headingLevel: number }, ): string { const md: string[] = []; - const parent = !model.isTarget - ? model.types - .map((hierarchyType) => { - return this.helpers.getHierarchyType(hierarchyType as SomeType, { - isTarget: model.isTarget || false, - }); - }) - .join('.') - : null; - if (model.next) { - if (parent) { - md.push(heading(options.headingLevel, this.getText('label.extends'))); - md.push(`- ${parent}`); - } else { - md.push(heading(options.headingLevel, this.getText('label.extendedBy'))); - const lines: string[] = []; - model.next.types.forEach((hierarchyType) => { - lines.push( - this.helpers.getHierarchyType(hierarchyType as SomeType, { - isTarget: model.next?.isTarget || false, - }), + + const getHierarchy = (hModel: DeclarationHierarchy) => { + const parent = !hModel.isTarget + ? hModel.types + .map((hierarchyType) => { + return this.helpers.getHierarchyType(hierarchyType as SomeType, { + isTarget: hModel.isTarget || false, + }); + }) + .join('.') + : null; + if (hModel.next) { + if (parent) { + md.push(heading(options.headingLevel, this.getText('label.extends'))); + md.push(`- ${parent}`); + } else { + md.push( + heading(options.headingLevel, this.getText('label.extendedBy')), ); - }); - md.push(unorderedList(lines)); + const lines: string[] = []; + hModel.next.types.forEach((hierarchyType) => { + lines.push( + this.helpers.getHierarchyType(hierarchyType as SomeType, { + isTarget: hModel.next?.isTarget || false, + }), + ); + }); + md.push(unorderedList(lines)); + } + if (hModel.next?.next) { + getHierarchy(hModel.next); + } } - } + }; + + getHierarchy(model); + return md.join('\n\n'); } diff --git a/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts b/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts index 3053d1fb3..fe4468fe1 100644 --- a/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts +++ b/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts @@ -232,3 +232,9 @@ export class ClassWithFlags { */ protected internalMethod() {} } + +export class BaseClass {} +export class ChildClassA extends BaseClass {} +export class ChildClassB extends BaseClass {} +export class GrandChildClassA extends ChildClassA {} +export class GrandChildClassB extends ChildClassA {} diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap index 343bb1586..8e49b4da8 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap @@ -2690,6 +2690,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output "kind": 128, "path": "classes/AbstractClass.md" }, + { + "title": "BaseClass", + "kind": 128, + "path": "classes/BaseClass.md" + }, { "title": "BasicClass", "kind": 128, @@ -2700,6 +2705,16 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output "kind": 128, "path": "classes/CallbacksOptions.md" }, + { + "title": "ChildClassA", + "kind": 128, + "path": "classes/ChildClassA.md" + }, + { + "title": "ChildClassB", + "kind": 128, + "path": "classes/ChildClassB.md" + }, { "title": "ClassWithAccessors", "kind": 128, @@ -2754,6 +2769,16 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output "title": "DisposableClass", "kind": 128, "path": "classes/DisposableClass.md" + }, + { + "title": "GrandChildClassA", + "kind": 128, + "path": "classes/GrandChildClassA.md" + }, + { + "title": "GrandChildClassB", + "kind": 128, + "path": "classes/GrandChildClassB.md" } ] }, diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap index 09ae63e5a..f1dde7555 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap @@ -1308,3 +1308,74 @@ exports[`Class Reflection should compile disposable class: (Output File Strategy [classes.ts:112](http://source-url) " `; + +exports[`Class Reflection should compile hierarchy for BaseClass: (Output File Strategy "members") (Option Group "1") 1`] = ` +"# Class: BaseClass + +## Extended by + +- [\`ChildClassA\`](ChildClassA.md) +- [\`ChildClassB\`](ChildClassB.md) + +## Constructors + +### new BaseClass() + +> **new BaseClass**(): [\`BaseClass\`](BaseClass.md) + +#### Returns + +[\`BaseClass\`](BaseClass.md) +" +`; + +exports[`Class Reflection should compile hierarchy for ChildClassA: (Output File Strategy "members") (Option Group "1") 1`] = ` +"# Class: ChildClassA + +## Extends + +- [\`BaseClass\`](BaseClass.md) + +## Extended by + +- [\`GrandChildClassA\`](GrandChildClassA.md) +- [\`GrandChildClassB\`](GrandChildClassB.md) + +## Constructors + +### new ChildClassA() + +> **new ChildClassA**(): [\`ChildClassA\`](ChildClassA.md) + +#### Returns + +[\`ChildClassA\`](ChildClassA.md) + +#### Inherited from + +[\`BaseClass\`](BaseClass.md).[\`constructor\`](BaseClass.md#constructors) +" +`; + +exports[`Class Reflection should compile hierarchy for GrandChildClassA: (Output File Strategy "members") (Option Group "1") 1`] = ` +"# Class: GrandChildClassA + +## Extends + +- [\`ChildClassA\`](ChildClassA.md) + +## Constructors + +### new GrandChildClassA() + +> **new GrandChildClassA**(): [\`GrandChildClassA\`](GrandChildClassA.md) + +#### Returns + +[\`GrandChildClassA\`](GrandChildClassA.md) + +#### Inherited from + +[\`ChildClassA\`](ChildClassA.md).[\`constructor\`](ChildClassA.md#constructors) +" +`; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap index eac0afe40..112757a21 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap @@ -496,8 +496,11 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb [ "README.md", "classes/AbstractClass.md", + "classes/BaseClass.md", "classes/BasicClass.md", "classes/CallbacksOptions.md", + "classes/ChildClassA.md", + "classes/ChildClassB.md", "classes/ClassWithAccessors.md", "classes/ClassWithComplexProps.md", "classes/ClassWithConstructorOverloads.md", @@ -509,6 +512,8 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb "classes/DerivedClassA.md", "classes/DerivedClassB.md", "classes/DisposableClass.md", + "classes/GrandChildClassA.md", + "classes/GrandChildClassB.md", "enumerations/BasicEnum.md", "enumerations/EnumWithValues.md", "functions/basicFunction.md", @@ -566,8 +571,11 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb [ "README.md", "classes/AbstractClass.md", + "classes/BaseClass.md", "classes/BasicClass.md", "classes/CallbacksOptions.md", + "classes/ChildClassA.md", + "classes/ChildClassB.md", "classes/ClassWithAccessors.md", "classes/ClassWithComplexProps.md", "classes/ClassWithConstructorOverloads.md", @@ -579,6 +587,8 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb "classes/DerivedClassA.md", "classes/DerivedClassB.md", "classes/DisposableClass.md", + "classes/GrandChildClassA.md", + "classes/GrandChildClassB.md", "enumerations/BasicEnum.md", "enumerations/EnumWithValues.md", "functions/basicFunction.md", diff --git a/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts b/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts index a2455ef08..6316c9e1f 100644 --- a/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts @@ -82,4 +82,21 @@ describe(`Class Reflection`, () => { 1, ); }); + + test(`should compile hierarchy for BaseClass`, () => { + expectFileToEqual('reflections', 'members', 'classes/BaseClass.md', 1); + }); + + test(`should compile hierarchy for ChildClassA`, () => { + expectFileToEqual('reflections', 'members', 'classes/ChildClassA.md', 1); + }); + + test(`should compile hierarchy for GrandChildClassA`, () => { + expectFileToEqual( + 'reflections', + 'members', + 'classes/GrandChildClassA.md', + 1, + ); + }); });