get appropriate parent jsdoc node for arrow functions

This commit is contained in:
xiaofa
2019-01-26 23:59:32 +08:00
parent c9c9f859f3
commit ddbac8f3fe
3 changed files with 25 additions and 8 deletions

View File

@@ -274,7 +274,17 @@ namespace ts.codefix {
return !!merged;
}));
const tag = createJSDocComment(comments.join("\n"), createNodeArray([...(oldTags || emptyArray), ...unmergedNewTags]));
changes.insertJsdocCommentBefore(sourceFile, parent, tag);
const jsDocNode = parent.kind === SyntaxKind.ArrowFunction ? getJsDocNodeForArrowFunction(parent) : parent;
jsDocNode.jsDoc = parent.jsDoc;
jsDocNode.jsDocCache = parent.jsDocCache;
changes.insertJsdocCommentBefore(sourceFile, jsDocNode, tag);
}
function getJsDocNodeForArrowFunction(signature: ArrowFunction): HasJSDoc {
if (signature.parent.kind === SyntaxKind.PropertyDeclaration) {
return <HasJSDoc>signature.parent;
}
return <HasJSDoc>signature.parent.parent;
}
function tryMergeJsdocTags(oldTag: JSDocTag, newTag: JSDocTag): JSDocTag | undefined {