File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff 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 .
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change 1+ /**
2+ * A test object with property a.
3+ */
4+ const LocalObject = {
5+ a : 1 ,
6+ } ;
7+
8+ export const Options = {
9+ LocalObject,
10+ } ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments