Skip to content

Commit

Permalink
Fix comment discovery on constructor params
Browse files Browse the repository at this point in the history
Resolves #2636
  • Loading branch information
Gerrit0 committed Jul 13, 2024
1 parent 9426642 commit 794d4ae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 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

- Constructor parameters which share a name with a property on a parent class will no longer inherit the comment on the parent class, #2636.

## v0.26.4 (2024-07-10)

### Bug Fixes
Expand Down
6 changes: 6 additions & 0 deletions src/lib/converter/comments/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ function declarationToCommentNodeIgnoringParents(
// ts.SourceFile is a counterexample
if (!node.parent) return node;

// function foo(x: number)
// ^^^^^^^^^
if (node.kind === ts.SyntaxKind.Parameter) {
return node;
}

// const abc = 123
// ^^^
if (node.parent.kind === ts.SyntaxKind.VariableDeclarationList) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/converter2/issues/gh2636.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export abstract class A {
protected constructor(a: number) {
this.a = a;
}

/** a prop @hidden */
public readonly a: number;
}

export class B extends A {
/** @param a a comment */
public constructor(a: number) {
super(a);
}
}
6 changes: 6 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,4 +1649,10 @@ describe("Issue Tests", () => {
const project = convert();
equal(project.children?.map((c) => c.name) || [], []);
});

it("#2636 does not treat parameters as class properties", () => {
const project = convert();
const sig = querySig(project, "B.constructor");
equal(sig.parameters?.length, 1);
});
});

0 comments on commit 794d4ae

Please sign in to comment.