Skip to content

Commit

Permalink
fix(core): fix missing extended by definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 6, 2024
1 parent 91f99e7 commit 0e55835
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 24 deletions.
Expand Up @@ -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');
}
Expand Up @@ -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 {}
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
Expand Up @@ -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)
"
`;
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Expand Up @@ -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,
);
});
});

0 comments on commit 0e55835

Please sign in to comment.