Skip to content

Commit 3663469

Browse files
committed
Add tests, also fix accessors while we're here
1 parent 7cff286 commit 3663469

File tree

5 files changed

+91
-41
lines changed

5 files changed

+91
-41
lines changed

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,6 @@ export class CommentPlugin extends ConverterComponent {
203203
this.removeExcludedTags(comment);
204204
}
205205

206-
private getHiddenItems(reflection: Reflection) {
207-
const hiddenItems = new Set<Reflection>();
208-
if (reflection.kindOf(ReflectionKind.FunctionOrMethod)) {
209-
const decl = reflection as DeclarationReflection;
210-
if (decl.signatures) {
211-
for (const sig of decl.signatures) {
212-
if (!sig.comment) {
213-
hiddenItems.add(sig);
214-
}
215-
}
216-
}
217-
if (!decl.signatures?.some((sig) => sig.comment)) {
218-
hiddenItems.add(decl);
219-
}
220-
} else {
221-
hiddenItems.add(reflection);
222-
}
223-
return hiddenItems || [];
224-
}
225-
226206
/**
227207
* Triggered when the converter begins resolving a project.
228208
*
@@ -245,31 +225,29 @@ export class CommentPlugin extends ConverterComponent {
245225
}
246226

247227
if (this.isHidden(ref)) {
248-
this.getHiddenItems(ref).forEach((item) => hidden.add(item));
228+
hidden.add(ref);
249229
}
250230
}
251231
hidden.forEach((reflection) => project.removeReflection(reflection));
252232

253233
// remove functions with empty signatures after their signatures have been removed
254234
const [allRemoved, someRemoved] = partition(
255-
filterMap(hidden, (reflection) =>
256-
reflection.parent?.kindOf(
257-
ReflectionKind.FunctionOrMethod | ReflectionKind.Constructor
258-
)
259-
? reflection.parent
260-
: void 0
261-
) as DeclarationReflection[],
262-
(method) => method.signatures?.length === 0
235+
unique(
236+
filterMap(hidden, (reflection) =>
237+
reflection.parent?.kindOf(ReflectionKind.SignatureContainer)
238+
? reflection.parent
239+
: void 0
240+
) as DeclarationReflection[]
241+
),
242+
(method) => method.getNonIndexSignatures().length === 0
263243
);
264244
allRemoved.forEach((reflection) => {
265245
project.removeReflection(reflection);
266246
});
267247
someRemoved.forEach((reflection) => {
268-
reflection.sources = unique(
269-
reflection.signatures!.flatMap<SourceReference>(
270-
(s) => s.sources ?? []
271-
)
272-
);
248+
reflection.sources = reflection
249+
.getNonIndexSignatures()
250+
.flatMap<SourceReference>((s) => s.sources ?? []);
273251
});
274252
}
275253

@@ -425,26 +403,36 @@ export class CommentPlugin extends ConverterComponent {
425403

426404
if (!comment) {
427405
if (this.excludeNotDocumented) {
428-
// Only allow excludeNotDocumented to exclude root level reflections
429-
if (!(reflection instanceof DeclarationReflection)) {
406+
// Don't let excludeNotDocumented remove parameters.
407+
if (
408+
!(reflection instanceof DeclarationReflection) &&
409+
!(reflection instanceof SignatureReflection)
410+
) {
430411
return false;
431412
}
432413

433414
// excludeNotDocumented should hide a module only if it has no visible children
434415
if (reflection.kindOf(ReflectionKind.SomeModule)) {
435-
if (!reflection.children) {
416+
if (!(reflection as DeclarationReflection).children) {
436417
return true;
437418
}
438-
return reflection.children.every((child) =>
439-
this.isHidden(child)
440-
);
419+
return (
420+
reflection as DeclarationReflection
421+
).children!.every((child) => this.isHidden(child));
441422
}
442423

443424
// enum members should all be included if the parent enum is documented
444425
if (reflection.kind === ReflectionKind.EnumMember) {
445426
return false;
446427
}
447428

429+
// signature containers should only be hidden if all their signatures are hidden
430+
if (reflection.kindOf(ReflectionKind.SignatureContainer)) {
431+
return (reflection as DeclarationReflection)
432+
.getAllSignatures()
433+
.every((child) => this.isHidden(child));
434+
}
435+
448436
// excludeNotDocumented should never hide parts of "type" reflections
449437
return inTypeLiteral(reflection) === false;
450438
}

src/lib/models/reflections/kind.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,11 @@ export namespace ReflectionKind {
9393
ReflectionKind.Constructor |
9494
ReflectionKind.Function |
9595
ReflectionKind.Method;
96+
97+
/**
98+
* Note: This does not include Class/Interface, even though they technically could contain index signatures
99+
* @internal
100+
*/
101+
export const SignatureContainer =
102+
ContainsCallSignatures | ReflectionKind.Accessor;
96103
}

src/test/converter2.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe("Converter2", () => {
7878
} else {
7979
runTest(
8080
name,
81-
issueTests[`pre${entry}`],
81+
issueTests[`pre${entry[0].toUpperCase()}${entry.slice(1)}`],
8282
join("issues", entry),
8383
check as (
8484
project: ProjectReflection,

src/test/converter2/issues/gh1994.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Has docs
3+
*/
4+
export function documented() {}
5+
6+
/**
7+
* Some signatures with docs
8+
*/
9+
export function documented2(): void;
10+
export function documented2(x: number): number;
11+
export function documented2(x?: number) {
12+
return x;
13+
}
14+
15+
export function notDocumented() {}
16+
17+
/** Docs */
18+
export class Docs {
19+
/** Docs */
20+
get x() {
21+
return 1;
22+
}
23+
/** Docs */
24+
set x(value: number) {
25+
throw value;
26+
}
27+
28+
/** Docs */
29+
get y() {
30+
return 2;
31+
}
32+
set y(value: number) {
33+
throw value;
34+
}
35+
36+
get z() {
37+
return 3;
38+
}
39+
}

src/test/issueTests.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,20 @@ export const issueTests: {
608608
logger.discardDebugMessages();
609609
logger.expectNoOtherMessages();
610610
},
611+
612+
preGh1994(app) {
613+
app.options.setValue("excludeNotDocumented", true);
614+
},
615+
gh1994(project) {
616+
for (const exp of ["documented", "documented2", "Docs.x", "Docs.y"]) {
617+
query(project, exp);
618+
}
619+
for (const rem of ["notDocumented", "Docs.z"]) {
620+
ok(!project.getChildByName(rem));
621+
}
622+
623+
const y = query(project, "Docs.y");
624+
ok(y.getSignature);
625+
ok(!y.setSignature);
626+
},
611627
};

0 commit comments

Comments
 (0)