Skip to content

Commit e37db58

Browse files
committed
Update categories/groups to contain DeclarationReflection
This type is more accurate, and lets us get rid of an inappropriate assert.
1 parent f64b4b7 commit e37db58

File tree

11 files changed

+21
-39
lines changed

11 files changed

+21
-39
lines changed

src/lib/converter/plugins/CategoryPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class CategoryPlugin extends ConverterComponent {
135135
* @returns An array containing all children of the given reflection categorized
136136
*/
137137
static getReflectionCategories(
138-
reflections: Reflection[]
138+
reflections: DeclarationReflection[]
139139
): ReflectionCategory[] {
140140
const categories: ReflectionCategory[] = [];
141141
let defaultCat: ReflectionCategory | undefined;

src/lib/converter/plugins/GroupPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export class GroupPlugin extends ConverterComponent {
112112
* @param reflections The reflections that should be grouped.
113113
* @returns An array containing all children of the given reflection grouped by their kind.
114114
*/
115-
static getReflectionGroups(reflections: Reflection[]): ReflectionGroup[] {
115+
static getReflectionGroups(
116+
reflections: DeclarationReflection[]
117+
): ReflectionGroup[] {
116118
const groups: ReflectionGroup[] = [];
117119
reflections.forEach((child) => {
118120
for (let i = 0; i < groups.length; i++) {

src/lib/converter/plugins/SourcePlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class SourcePlugin extends ConverterComponent {
158158
const project = context.project;
159159
const home = project.directory;
160160
project.files.forEach((file) => {
161-
const reflections: Reflection[] = [];
161+
const reflections: DeclarationReflection[] = [];
162162
file.reflections.forEach((reflection) => {
163163
reflections.push(reflection);
164164
});
@@ -183,7 +183,6 @@ export class SourcePlugin extends ConverterComponent {
183183
}
184184

185185
directory.files.push(file);
186-
// reflections.sort(GroupHandler.sortCallback);
187186
file.parent = directory;
188187
file.reflections = reflections;
189188
});

src/lib/models/ReflectionCategory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Reflection } from "./reflections/abstract";
1+
import type { DeclarationReflection } from ".";
22

33
/**
44
* A category of reflections.
@@ -16,7 +16,7 @@ export class ReflectionCategory {
1616
/**
1717
* All reflections of this category.
1818
*/
19-
children: Reflection[] = [];
19+
children: DeclarationReflection[] = [];
2020

2121
/**
2222
* Create a new ReflectionCategory instance.

src/lib/models/ReflectionGroup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { Reflection, ReflectionKind } from "./reflections/abstract";
1+
import type { ReflectionKind } from "./reflections/abstract";
22
import type { ReflectionCategory } from "./ReflectionCategory";
3+
import type { DeclarationReflection } from ".";
34

45
/**
56
* A group of reflections. All reflections in a group are of the same kind.
@@ -22,7 +23,7 @@ export class ReflectionGroup {
2223
/**
2324
* All reflections of this group.
2425
*/
25-
children: Reflection[] = [];
26+
children: DeclarationReflection[] = [];
2627

2728
/**
2829
* A list of generated css classes that should be applied to representations of this

src/lib/models/sources/directory.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { Reflection } from "../reflections/abstract";
21
import type { ReflectionGroup } from "../ReflectionGroup";
32
import type { SourceFile } from "./file";
3+
import type { DeclarationReflection } from "..";
4+
import { flatMap } from "../../utils/array";
45

56
/**
67
* Exposes information about a directory containing source files.
@@ -82,13 +83,7 @@ export class SourceDirectory {
8283
* @returns An aggregated list of all {@link DeclarationReflection} defined in the
8384
* files of this directory.
8485
*/
85-
getAllReflections(): Reflection[] {
86-
const reflections: Reflection[] = [];
87-
this.files.forEach((file) => {
88-
reflections.push(...file.reflections);
89-
});
90-
91-
// reflections.sort(Factories.GroupHandler.sortCallback);
92-
return reflections;
86+
getAllReflections(): DeclarationReflection[] {
87+
return flatMap(this.files, (file) => file.reflections);
9388
}
9489
}

src/lib/models/sources/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Path from "path";
22

3-
import type { Reflection } from "../reflections/abstract";
43
import type { ReflectionGroup } from "../ReflectionGroup";
54
import type { SourceDirectory } from "./directory";
65
import type { RepositoryType } from "./repository";
6+
import type { DeclarationReflection } from "..";
77

88
/**
99
* Represents references of reflections to their defining source files.
@@ -79,7 +79,7 @@ export class SourceFile {
7979
/**
8080
* A list of all reflections that are declared in this file.
8181
*/
82-
reflections: Reflection[] = [];
82+
reflections: DeclarationReflection[] = [];
8383

8484
/**
8585
* A grouped list of the reflections declared in this file.

src/lib/output/themes/default/partials/member.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertIsDeclarationReflection, renderFlags, wbr } from "../../lib";
1+
import { renderFlags, wbr } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { JSX } from "../../../../utils";
44
import { DeclarationReflection, ReferenceReflection } from "../../../../models";
@@ -20,8 +20,6 @@ export const member = (context: DefaultThemeRenderContext, props: DeclarationRef
2020
? context.memberReference(props)
2121
: context.memberDeclaration(props)}
2222

23-
{props.groups?.map((item) =>
24-
item.children.map((item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item)))
25-
)}
23+
{props.groups?.map((item) => item.children.map((item) => !item.hasOwnDocument && context.member(item)))}
2624
</section>
2725
);

src/lib/output/themes/default/partials/members.group.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assertIsDeclarationReflection } from "../../lib";
21
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
32
import { JSX } from "../../../../utils";
43
import type { ReflectionGroup } from "../../../../models";
@@ -13,9 +12,7 @@ export function membersGroup(context: DefaultThemeRenderContext, group: Reflecti
1312
{!!item.title && <>{item.title} </>}
1413
{group.title}
1514
</h2>
16-
{item.children.map(
17-
(item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item))
18-
)}
15+
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
1916
</section>
2017
))}
2118
</>
@@ -25,7 +22,7 @@ export function membersGroup(context: DefaultThemeRenderContext, group: Reflecti
2522
return (
2623
<section class={"tsd-panel-group tsd-member-group " + group.cssClasses}>
2724
<h2>{group.title}</h2>
28-
{group.children.map((item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item)))}
25+
{group.children.map((item) => !item.hasOwnDocument && context.member(item))}
2926
</section>
3027
);
3128
}

src/lib/output/themes/default/partials/members.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { assertIsDeclarationReflection } from "../../lib";
21
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
32
import { JSX } from "../../../../utils";
43
import type { ContainerReflection } from "../../../../models";
@@ -12,10 +11,7 @@ export function members(context: DefaultThemeRenderContext, props: ContainerRefl
1211
!item.allChildrenHaveOwnDocument() && (
1312
<section class={"tsd-panel-group tsd-member-group " + props.cssClasses}>
1413
<h2>{item.title}</h2>
15-
{item.children.map(
16-
(item) =>
17-
!item.hasOwnDocument && context.member(assertIsDeclarationReflection(item))
18-
)}
14+
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
1915
</section>
2016
)
2117
)}

0 commit comments

Comments
 (0)