Skip to content

Commit 06a4239

Browse files
committed
Pick up shorthand property's variable comments
Resolves #2999
1 parent e5cd9d1 commit 06a4239

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ title: Changelog
44

55
## Unreleased
66

7+
### Features
8+
9+
- Object properties declared with shorthand property assignment will now use the variable's comment
10+
if they do not have their own comment, #2999.
11+
712
### Bug Fixes
813

914
- Fixed link resolution not working correctly in first comment on the file in some cases, #2994.

src/lib/converter/comments/discovery.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,22 @@ function declarationToCommentNodes(
525525
});
526526
}
527527

528+
// #2999 automatically pick up comments from the value symbol for shorthand assignments
529+
if (ts.isShorthandPropertyAssignment(node)) {
530+
const sourceSymbol = checker.getShorthandAssignmentValueSymbol(node);
531+
if (sourceSymbol?.valueDeclaration) {
532+
const commentNode = declarationToCommentNodeIgnoringParents(sourceSymbol.valueDeclaration);
533+
if (commentNode) {
534+
result.push(
535+
{
536+
node: commentNode,
537+
inheritedFromParentDeclaration: true,
538+
},
539+
);
540+
}
541+
}
542+
}
543+
528544
// With overloaded functions/methods, TypeScript will use the comment on the first signature
529545
// declaration
530546
if (
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* A test object with property a.
3+
*/
4+
const LocalObject = {
5+
a: 1,
6+
};
7+
8+
export const Options = {
9+
LocalObject,
10+
};

src/test/issues.c2.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,4 +2150,12 @@ describe("Issue Tests", () => {
21502150
const link = project.comment?.summary.find(part => part.kind === "inline-tag");
21512151
ok(link?.target instanceof ReflectionSymbolId);
21522152
});
2153+
2154+
it("#2999 picks up parent comments from shorthand property assignments", () => {
2155+
const project = convert();
2156+
const opts = query(project, "Options");
2157+
equal(opts.type?.type, "reflection");
2158+
const local = opts.type.declaration.getChildByName("LocalObject");
2159+
equal(Comment.combineDisplayParts(local?.comment?.summary), "A test object with property a.");
2160+
});
21532161
});

0 commit comments

Comments
 (0)