Use only immediately preceding JSDoc

Now only the immediately preceding jsdoc of a node is retrieved by
getJSDoc, although it still does the correct non-local lookup for nodes
like ParameterDeclaration.

This doesn't change parsing or binding, which use the per-node Node.jsdoc
property directly. But it does change everything that relies on getJSDoc,
which includes the checker and language service.

Fixes #32062, which contains the analysis that justifies the change.
This commit is contained in:
Nathan Shively-Sanders
2019-06-29 08:05:10 -07:00
parent 410b71751e
commit fefb857847
5 changed files with 33 additions and 40 deletions

View File

@@ -2201,13 +2201,13 @@ namespace ts {
let result: (JSDoc | JSDocTag)[] | undefined;
// Pull parameter comments from declaring function as well
if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer!)) {
result = addRange(result, (hostNode.initializer as HasJSDoc).jsDoc!);
result = append(result, last((hostNode.initializer as HasJSDoc).jsDoc!));
}
let node: Node | undefined = hostNode;
while (node && node.parent) {
if (hasJSDocNodes(node)) {
result = addRange(result, node.jsDoc!);
result = append(result, last(node.jsDoc!));
}
if (node.kind === SyntaxKind.Parameter) {