@@ -2634,13 +2634,13 @@ namespace ts {
2634
2634
let result : ( JSDoc | JSDocTag ) [ ] | undefined ;
2635
2635
// Pull parameter comments from declaring function as well
2636
2636
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 ! ) ) ) ;
2638
2638
}
2639
2639
2640
2640
let node : Node | undefined = hostNode ;
2641
2641
while ( node && node . parent ) {
2642
2642
if ( hasJSDocNodes ( node ) ) {
2643
- result = append ( result , last ( node . jsDoc ! ) ) ;
2643
+ result = addRange ( result , filterOwnedJSDocTags ( hostNode , last ( node . jsDoc ! ) ) ) ;
2644
2644
}
2645
2645
2646
2646
if ( node . kind === SyntaxKind . Parameter ) {
@@ -2656,6 +2656,26 @@ namespace ts {
2656
2656
return result || emptyArray ;
2657
2657
}
2658
2658
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
+
2659
2679
export function getNextJSDocCommentLocation ( node : Node ) {
2660
2680
const parent = node . parent ;
2661
2681
if ( parent . kind === SyntaxKind . PropertyAssignment ||
0 commit comments