Skip to content

Commit

Permalink
Fix removeReflection skipping every other parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Mar 27, 2022
1 parent 98841f5 commit bc6130a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Fixed `--validation.notDocumented` warnings for functions/methods, #1895.
- Search results will no longer include random items when the search bar is empty, #1881.
- Comments on overloaded constructors will now be detected in the same way that overloaded functions/methods are.
- Fixed `removeReflection` not completely removing reflections from the project.

### Thanks!

Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/reflections/container.ts
Expand Up @@ -39,7 +39,7 @@ export class ContainerReflection extends Reflection {
* @param callback The callback function that should be applied for each child reflection.
*/
override traverse(callback: TraverseCallback) {
for (const child of this.children ?? []) {
for (const child of this.children?.slice() || []) {
if (callback(child, TraverseProperty.Children) === false) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models/reflections/declaration.ts
Expand Up @@ -170,7 +170,7 @@ export class DeclarationReflection extends ContainerReflection {
* @param callback The callback function that should be applied for each child reflection.
*/
override traverse(callback: TraverseCallback) {
for (const parameter of this.typeParameters ?? []) {
for (const parameter of this.typeParameters?.slice() || []) {
if (callback(parameter, TraverseProperty.TypeParameter) === false) {
return;
}
Expand All @@ -187,7 +187,7 @@ export class DeclarationReflection extends ContainerReflection {
}
}

for (const signature of this.signatures ?? []) {
for (const signature of this.signatures?.slice() || []) {
if (callback(signature, TraverseProperty.Signatures) === false) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models/reflections/signature.ts
Expand Up @@ -73,13 +73,13 @@ export class SignatureReflection extends Reflection {
}
}

for (const parameter of this.typeParameters ?? []) {
for (const parameter of this.typeParameters?.slice() || []) {
if (callback(parameter, TraverseProperty.TypeParameter) === false) {
return;
}
}

for (const parameter of this.parameters ?? []) {
for (const parameter of this.parameters?.slice() || []) {
if (callback(parameter, TraverseProperty.Parameters) === false) {
return;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/behaviorTests.ts
Expand Up @@ -70,4 +70,13 @@ export const behaviorTests: Record<

equal(foo.comment, undefined);
},

removeReflection(project) {
const foo = query(project, "foo");
project.removeReflection(foo);
equal(
Object.values(project.reflections).map((r) => r.name),
["typedoc"]
);
},
};
5 changes: 5 additions & 0 deletions src/test/converter2/behavior/removeReflection.ts
@@ -0,0 +1,5 @@
export function foo(first: string, second: string, third: string) {
first;
second;
third;
}

0 comments on commit bc6130a

Please sign in to comment.