|
1 | 1 | import { Reflection, type TraverseCallback, TraverseProperty } from "./Reflection.js"; |
2 | 2 | import { ReflectionCategory } from "./ReflectionCategory.js"; |
3 | 3 | import { ReflectionGroup } from "./ReflectionGroup.js"; |
4 | | -import type { ReflectionKind } from "./kind.js"; |
| 4 | +import { ReflectionKind } from "./kind.js"; |
5 | 5 | import type { Deserializer, JSONOutput, Serializer } from "#serialization"; |
6 | 6 | import type { DocumentReflection } from "./DocumentReflection.js"; |
7 | 7 | import type { DeclarationReflection } from "./DeclarationReflection.js"; |
8 | | -import { removeIfPresent } from "#utils"; |
| 8 | +import { assertNever, removeIfPresent } from "#utils"; |
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * @category Reflections |
@@ -59,17 +59,39 @@ export abstract class ContainerReflection extends Reflection { |
59 | 59 | return (this.children || []).filter((child) => child.kindOf(kind)); |
60 | 60 | } |
61 | 61 |
|
62 | | - addChild(child: DeclarationReflection | DocumentReflection) { |
| 62 | + addChild(child: Reflection) { |
63 | 63 | if (child.isDeclaration()) { |
64 | 64 | this.children ||= []; |
65 | 65 | this.children.push(child); |
66 | | - } else { |
| 66 | + |
| 67 | + this.childrenIncludingDocuments ||= []; |
| 68 | + this.childrenIncludingDocuments.push(child); |
| 69 | + } else if (child.isDocument()) { |
67 | 70 | this.documents ||= []; |
68 | 71 | this.documents.push(child); |
69 | | - } |
70 | 72 |
|
71 | | - this.childrenIncludingDocuments ||= []; |
72 | | - this.childrenIncludingDocuments.push(child); |
| 73 | + this.childrenIncludingDocuments ||= []; |
| 74 | + this.childrenIncludingDocuments.push(child); |
| 75 | + } else if (this.isDeclaration() && child.isSignature()) { |
| 76 | + switch (child.kind) { |
| 77 | + case ReflectionKind.CallSignature: |
| 78 | + case ReflectionKind.ConstructorSignature: |
| 79 | + this.signatures ||= []; |
| 80 | + this.signatures.push(child); |
| 81 | + break; |
| 82 | + case ReflectionKind.IndexSignature: |
| 83 | + this.indexSignatures ||= []; |
| 84 | + this.indexSignatures.push(child); |
| 85 | + break; |
| 86 | + case ReflectionKind.GetSignature: |
| 87 | + case ReflectionKind.SetSignature: |
| 88 | + throw new Error("Unsupported child type: " + ReflectionKind[child.kind]); |
| 89 | + default: |
| 90 | + assertNever(child.kind); |
| 91 | + } |
| 92 | + } else { |
| 93 | + throw new Error("Unsupported child type: " + ReflectionKind[child.kind]); |
| 94 | + } |
73 | 95 | } |
74 | 96 |
|
75 | 97 | removeChild(child: DeclarationReflection | DocumentReflection) { |
|
0 commit comments