Skip to content

Commit e06b849

Browse files
committed
fix(core): fix reflection flags
1 parent 9b00dca commit e06b849

19 files changed

+154
-49
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"ts-morph": "^22.0.0",
5252
"ts-node": "^10.9.2",
5353
"tsc-alias": "^1.8.10",
54-
"typedoc": "^0.26.0-beta.3",
54+
"typedoc": "^0.26.0-beta.4",
5555
"typescript": "^5.4.5",
5656
"unified-prettier": "^2.0.1"
5757
}

packages/typedoc-plugin-markdown/.scripts/prebuild-resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ async function writeResourcesFile() {
138138
'ReferenceType',
139139
'Reflection',
140140
'ReflectionCategory',
141+
'ReflectionFlags',
141142
'ReflectionGroup',
142143
'ReflectionKind',
143144
'ReflectionType',

packages/typedoc-plugin-markdown/src/theme/context/helpers/_index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './get-comment-flags';
12
export * from './get-comment-parts';
23
export * from './get-declaration-type';
34
export * from './get-description-for-reflection';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { camelToTitleCase } from 'libs/utils';
2+
import { MarkdownThemeContext } from 'theme';
3+
import { DeclarationReflection, SignatureReflection } from 'typedoc';
4+
5+
export function getCommentFlags(
6+
this: MarkdownThemeContext,
7+
reflection: DeclarationReflection | SignatureReflection,
8+
): string[] {
9+
const flagsNotRendered: `@${string}`[] = [
10+
'@showCategories',
11+
'@showGroups',
12+
'@hideCategories',
13+
'@hideGroups',
14+
];
15+
const flags: string[] = [];
16+
if (reflection.comment) {
17+
for (const tag of reflection.comment.modifierTags) {
18+
if (!flagsNotRendered.includes(tag)) {
19+
flags.push(camelToTitleCase(tag.substring(1)));
20+
}
21+
}
22+
}
23+
return flags;
24+
}
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
import { camelToTitleCase } from 'libs/utils';
1+
import { backTicks } from 'libs/markdown';
22
import { MarkdownThemeContext } from 'theme';
3-
import { DeclarationReflection, SignatureReflection } from 'typedoc';
3+
import { ReflectionFlags } from 'typedoc';
44

55
export function getReflectionFlags(
66
this: MarkdownThemeContext,
7-
reflection: DeclarationReflection | SignatureReflection,
8-
): string[] {
9-
const flagsNotRendered: `@${string}`[] = [
10-
'@showCategories',
11-
'@showGroups',
12-
'@hideCategories',
13-
'@hideGroups',
14-
];
15-
const flags: string[] = [];
16-
if (reflection.comment) {
17-
for (const tag of reflection.comment.modifierTags) {
18-
if (!flagsNotRendered.includes(tag)) {
19-
flags.push(camelToTitleCase(tag.substring(1)));
20-
}
21-
}
7+
reflectionFlags: ReflectionFlags,
8+
): string {
9+
const result: string[] = [];
10+
if (reflectionFlags.isAbstract) {
11+
result.push(backTicks('abstract'));
2212
}
23-
return flags;
13+
if (reflectionFlags.isConst) {
14+
result.push(backTicks('const'));
15+
}
16+
if (reflectionFlags.isPrivate) {
17+
result.push(backTicks('private'));
18+
}
19+
if (reflectionFlags.isProtected) {
20+
result.push(backTicks('protected'));
21+
}
22+
if (reflectionFlags.isReadonly) {
23+
result.push(backTicks('readonly'));
24+
}
25+
if (reflectionFlags.isStatic) {
26+
result.push(backTicks('static'));
27+
}
28+
if (reflectionFlags.isOptional) {
29+
result.push(backTicks('optional'));
30+
}
31+
return result.join(' ');
2432
}

packages/typedoc-plugin-markdown/src/theme/context/partials/member.declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function declaration(
3333

3434
md.push(
3535
this.helpers
36-
.getReflectionFlags(model)
36+
.getCommentFlags(model)
3737
.map((item) => backTicks(item))
3838
.join(' '),
3939
);

packages/typedoc-plugin-markdown/src/theme/context/partials/member.declarationTitle.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export function declarationTitle(
2020

2121
const prefix: string[] = [];
2222

23-
if (model.flags.length) {
24-
prefix.push(
25-
model.flags?.map((flag) => backTicks(flag.toLowerCase())).join(' '),
26-
);
23+
const flagsString = this.helpers.getReflectionFlags(model.flags);
24+
25+
if (flagsString.length) {
26+
prefix.push(flagsString);
2727
}
2828

2929
if (model.flags.isRest) {
@@ -36,8 +36,10 @@ export function declarationTitle(
3636
prefix.push(keyword);
3737
}
3838

39-
if (prefix.length) {
40-
md.push(prefix.join(' ') + ' ');
39+
const prefixes = prefix.filter((prefix) => prefix.length > 0);
40+
41+
if (prefixes.length) {
42+
md.push(prefixes.join(' ') + ' ');
4143
}
4244

4345
const name: string[] = [];

packages/typedoc-plugin-markdown/src/theme/context/partials/member.indexSignature.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export function indexSignature(
1212
model: SignatureReflection,
1313
): string {
1414
const md = [''];
15-
1615
const params = model.parameters
1716
? model.parameters.map((parameter) => {
1817
return parameter.type

packages/typedoc-plugin-markdown/src/theme/context/partials/member.memberTitle.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ export function memberTitle(
1515
const md: string[] = [];
1616
const name: string[] = [];
1717

18-
if (
19-
model?.kind === ReflectionKind.Class &&
20-
model.flags?.includes('Abstract')
21-
) {
22-
name.push(backTicks('abstract') + ' ');
18+
if (model?.kind === ReflectionKind.Class && model.flags?.isAbstract) {
19+
name.push(this.helpers.getReflectionFlags(model.flags) + ' ');
2320
}
2421

2522
name.push(

0 commit comments

Comments
 (0)