Skip to content

Commit

Permalink
Fix @category tag for real
Browse files Browse the repository at this point in the history
Closes #1745
  • Loading branch information
Gerrit0 committed Oct 31, 2021
1 parent 78c779b commit 07a2d58
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Actually fixed `@category` tag incorrectly appearing on function types if used on a type alias, #1745.

## v0.22.7 (2021-10-25)

### Features
Expand Down
26 changes: 11 additions & 15 deletions src/lib/converter/plugins/CategoryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ContainerReflection,
DeclarationReflection,
CommentTag,
ReflectionKind,
} from "../../models";
import { ReflectionCategory } from "../../models/ReflectionCategory";
import { Component, ConverterComponent } from "../components";
Expand Down Expand Up @@ -179,8 +178,10 @@ export class CategoryPlugin extends ConverterComponent {
* @returns The category the reflection belongs to
*/
static getCategories(reflection: DeclarationReflection) {
function extractCategoryTag(comment: Comment) {
function extractCategoryTag(comment: Comment | undefined) {
const categories = new Set<string>();
if (!comment) return categories;

const tags = comment.tags;
const commentTags: CommentTag[] = [];
tags.forEach((tag) => {
Expand All @@ -198,28 +199,23 @@ export class CategoryPlugin extends ConverterComponent {
return categories;
}

const categories = new Set<string>();
let categories = new Set<string>();

if (reflection.comment) {
return extractCategoryTag(reflection.comment);
} else if (
reflection instanceof DeclarationReflection &&
reflection.signatures
) {
categories = extractCategoryTag(reflection.comment);
} else if (reflection.signatures) {
for (const sig of reflection.signatures) {
for (const cat of sig.comment
? extractCategoryTag(sig.comment)
: []) {
for (const cat of extractCategoryTag(sig.comment)) {
categories.add(cat);
}
}
}

if (
reflection.kind === ReflectionKind.TypeAlias &&
reflection.type?.type === "reflection"
) {
if (reflection.type?.type === "reflection") {
reflection.type.declaration.comment?.removeTags("category");
reflection.type.declaration.signatures?.forEach((s) =>
s.comment?.removeTags("category")
);
}

return categories;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/reflections/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DeclarationReflection extends ContainerReflection {
/**
* A list of call signatures attached to this declaration.
*
* TypeDoc creates one declaration per function that may contain ore or more
* TypeDoc creates one declaration per function that may contain one or more
* signature reflections.
*/
signatures?: SignatureReflection[];
Expand Down
6 changes: 6 additions & 0 deletions src/test/issueTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,11 @@ export const issueTests: {

ok(cat.children.includes(Foo));
ok(!Foo.comment?.hasTag("category"));
ok(!Foo.type.declaration.comment?.hasTag("category"));
ok(
!Foo.type.declaration.signatures?.some((s) =>
s.comment?.hasTag("category")
)
);
},
};

0 comments on commit 07a2d58

Please sign in to comment.