Skip to content

Commit

Permalink
Update categories/groups to contain DeclarationReflection
Browse files Browse the repository at this point in the history
This type is more accurate, and lets us get rid of an inappropriate assert.
  • Loading branch information
Gerrit0 committed Oct 17, 2021
1 parent f64b4b7 commit e37db58
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/lib/converter/plugins/CategoryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class CategoryPlugin extends ConverterComponent {
* @returns An array containing all children of the given reflection categorized
*/
static getReflectionCategories(
reflections: Reflection[]
reflections: DeclarationReflection[]
): ReflectionCategory[] {
const categories: ReflectionCategory[] = [];
let defaultCat: ReflectionCategory | undefined;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/plugins/GroupPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export class GroupPlugin extends ConverterComponent {
* @param reflections The reflections that should be grouped.
* @returns An array containing all children of the given reflection grouped by their kind.
*/
static getReflectionGroups(reflections: Reflection[]): ReflectionGroup[] {
static getReflectionGroups(
reflections: DeclarationReflection[]
): ReflectionGroup[] {
const groups: ReflectionGroup[] = [];
reflections.forEach((child) => {
for (let i = 0; i < groups.length; i++) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/converter/plugins/SourcePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class SourcePlugin extends ConverterComponent {
const project = context.project;
const home = project.directory;
project.files.forEach((file) => {
const reflections: Reflection[] = [];
const reflections: DeclarationReflection[] = [];
file.reflections.forEach((reflection) => {
reflections.push(reflection);
});
Expand All @@ -183,7 +183,6 @@ export class SourcePlugin extends ConverterComponent {
}

directory.files.push(file);
// reflections.sort(GroupHandler.sortCallback);
file.parent = directory;
file.reflections = reflections;
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models/ReflectionCategory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Reflection } from "./reflections/abstract";
import type { DeclarationReflection } from ".";

/**
* A category of reflections.
Expand All @@ -16,7 +16,7 @@ export class ReflectionCategory {
/**
* All reflections of this category.
*/
children: Reflection[] = [];
children: DeclarationReflection[] = [];

/**
* Create a new ReflectionCategory instance.
Expand Down
5 changes: 3 additions & 2 deletions src/lib/models/ReflectionGroup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Reflection, ReflectionKind } from "./reflections/abstract";
import type { ReflectionKind } from "./reflections/abstract";
import type { ReflectionCategory } from "./ReflectionCategory";
import type { DeclarationReflection } from ".";

/**
* A group of reflections. All reflections in a group are of the same kind.
Expand All @@ -22,7 +23,7 @@ export class ReflectionGroup {
/**
* All reflections of this group.
*/
children: Reflection[] = [];
children: DeclarationReflection[] = [];

/**
* A list of generated css classes that should be applied to representations of this
Expand Down
13 changes: 4 additions & 9 deletions src/lib/models/sources/directory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Reflection } from "../reflections/abstract";
import type { ReflectionGroup } from "../ReflectionGroup";
import type { SourceFile } from "./file";
import type { DeclarationReflection } from "..";
import { flatMap } from "../../utils/array";

/**
* Exposes information about a directory containing source files.
Expand Down Expand Up @@ -82,13 +83,7 @@ export class SourceDirectory {
* @returns An aggregated list of all {@link DeclarationReflection} defined in the
* files of this directory.
*/
getAllReflections(): Reflection[] {
const reflections: Reflection[] = [];
this.files.forEach((file) => {
reflections.push(...file.reflections);
});

// reflections.sort(Factories.GroupHandler.sortCallback);
return reflections;
getAllReflections(): DeclarationReflection[] {
return flatMap(this.files, (file) => file.reflections);
}
}
4 changes: 2 additions & 2 deletions src/lib/models/sources/file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as Path from "path";

import type { Reflection } from "../reflections/abstract";
import type { ReflectionGroup } from "../ReflectionGroup";
import type { SourceDirectory } from "./directory";
import type { RepositoryType } from "./repository";
import type { DeclarationReflection } from "..";

/**
* Represents references of reflections to their defining source files.
Expand Down Expand Up @@ -79,7 +79,7 @@ export class SourceFile {
/**
* A list of all reflections that are declared in this file.
*/
reflections: Reflection[] = [];
reflections: DeclarationReflection[] = [];

/**
* A grouped list of the reflections declared in this file.
Expand Down
6 changes: 2 additions & 4 deletions src/lib/output/themes/default/partials/member.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertIsDeclarationReflection, renderFlags, wbr } from "../../lib";
import { renderFlags, wbr } from "../../lib";
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
import { JSX } from "../../../../utils";
import { DeclarationReflection, ReferenceReflection } from "../../../../models";
Expand All @@ -20,8 +20,6 @@ export const member = (context: DefaultThemeRenderContext, props: DeclarationRef
? context.memberReference(props)
: context.memberDeclaration(props)}

{props.groups?.map((item) =>
item.children.map((item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item)))
)}
{props.groups?.map((item) => item.children.map((item) => !item.hasOwnDocument && context.member(item)))}
</section>
);
7 changes: 2 additions & 5 deletions src/lib/output/themes/default/partials/members.group.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assertIsDeclarationReflection } from "../../lib";
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
import { JSX } from "../../../../utils";
import type { ReflectionGroup } from "../../../../models";
Expand All @@ -13,9 +12,7 @@ export function membersGroup(context: DefaultThemeRenderContext, group: Reflecti
{!!item.title && <>{item.title} </>}
{group.title}
</h2>
{item.children.map(
(item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item))
)}
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
))}
</>
Expand All @@ -25,7 +22,7 @@ export function membersGroup(context: DefaultThemeRenderContext, group: Reflecti
return (
<section class={"tsd-panel-group tsd-member-group " + group.cssClasses}>
<h2>{group.title}</h2>
{group.children.map((item) => !item.hasOwnDocument && context.member(assertIsDeclarationReflection(item)))}
{group.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
);
}
6 changes: 1 addition & 5 deletions src/lib/output/themes/default/partials/members.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assertIsDeclarationReflection } from "../../lib";
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
import { JSX } from "../../../../utils";
import type { ContainerReflection } from "../../../../models";
Expand All @@ -12,10 +11,7 @@ export function members(context: DefaultThemeRenderContext, props: ContainerRefl
!item.allChildrenHaveOwnDocument() && (
<section class={"tsd-panel-group tsd-member-group " + props.cssClasses}>
<h2>{item.title}</h2>
{item.children.map(
(item) =>
!item.hasOwnDocument && context.member(assertIsDeclarationReflection(item))
)}
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
)
)}
Expand Down
6 changes: 0 additions & 6 deletions src/lib/output/themes/lib.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ok as assert } from "assert";
import {
DeclarationReflection,
Reflection,
Expand Down Expand Up @@ -71,11 +70,6 @@ export function classNames(names: Record<string, boolean | null | undefined>) {
.join(" ");
}

export function assertIsDeclarationReflection(reflection: Reflection): DeclarationReflection {
assert(reflection instanceof DeclarationReflection);
return reflection;
}

export function hasTypeParameters(
reflection: Reflection
): reflection is Reflection & { typeParameters: TypeParameterReflection[] } {
Expand Down

0 comments on commit e37db58

Please sign in to comment.