@@ -2634,13 +2634,13 @@ namespace ts {
26342634 let result : ( JSDoc | JSDocTag ) [ ] | undefined ;
26352635 // Pull parameter comments from declaring function as well
26362636 if ( isVariableLike ( hostNode ) && hasInitializer ( hostNode ) && hasJSDocNodes ( hostNode . initializer ! ) ) {
2637- result = append ( result , last ( ( hostNode . initializer as HasJSDoc ) . jsDoc ! ) ) ;
2637+ result = addRange ( result , filterOwnedJSDocTags ( hostNode , last ( ( hostNode . initializer as HasJSDoc ) . jsDoc ! ) ) ) ;
26382638 }
26392639
26402640 let node : Node | undefined = hostNode ;
26412641 while ( node && node . parent ) {
26422642 if ( hasJSDocNodes ( node ) ) {
2643- result = append ( result , last ( node . jsDoc ! ) ) ;
2643+ result = addRange ( result , filterOwnedJSDocTags ( hostNode , last ( node . jsDoc ! ) ) ) ;
26442644 }
26452645
26462646 if ( node . kind === SyntaxKind . Parameter ) {
@@ -2656,6 +2656,26 @@ namespace ts {
26562656 return result || emptyArray ;
26572657 }
26582658
2659+ function filterOwnedJSDocTags ( hostNode : Node , jsDoc : JSDoc | JSDocTag ) {
2660+ if ( isJSDoc ( jsDoc ) ) {
2661+ const ownedTags = filter ( jsDoc . tags , tag => ownsJSDocTag ( hostNode , tag ) ) ;
2662+ return jsDoc . tags === ownedTags ? [ jsDoc ] : ownedTags ;
2663+ }
2664+ return ownsJSDocTag ( hostNode , jsDoc ) ? [ jsDoc ] : undefined ;
2665+ }
2666+
2667+ /**
2668+ * Determines whether a host node owns a jsDoc tag. A `@type` tag attached to a
2669+ * a ParenthesizedExpression belongs only to the ParenthesizedExpression.
2670+ */
2671+ function ownsJSDocTag ( hostNode : Node , tag : JSDocTag ) {
2672+ return ! isJSDocTypeTag ( tag )
2673+ || ! tag . parent
2674+ || ! isJSDoc ( tag . parent )
2675+ || ! isParenthesizedExpression ( tag . parent . parent )
2676+ || tag . parent . parent === hostNode ;
2677+ }
2678+
26592679 export function getNextJSDocCommentLocation ( node : Node ) {
26602680 const parent = node . parent ;
26612681 if ( parent . kind === SyntaxKind . PropertyAssignment ||
0 commit comments