Remove bogus @implements errors (#37114)

* Remove bogus @implements errors

Make the search for the actual host more comprehensive by reusing the
code that previously only searched for functions. I don't know what to
call this function now, since the old name wasn't accurate either.

* undo gratuitous name change

* Improve name and make calling more uniform

It's slightly less efficient but I think worthwhile for readability.
This commit is contained in:
Nathan Shively-Sanders
2020-03-02 09:48:53 -08:00
committed by GitHub
parent 1e46185506
commit 392fd0ac0b
7 changed files with 284 additions and 10 deletions

View File

@@ -2910,8 +2910,8 @@ namespace ts {
return getDeclarationOfJSPrototypeContainer(symbol);
}
}
const sig = getHostSignatureFromJSDocHost(host);
if (sig) {
const sig = getEffectiveJSDocHost(node);
if (sig && isFunctionLike(sig)) {
const symbol = getSymbolOfNode(sig);
return symbol && symbol.valueDeclaration;
}
@@ -30444,15 +30444,14 @@ namespace ts {
}
function checkJSDocImplementsTag(node: JSDocImplementsTag): void {
const classLike = getJSDocHost(node);
if (!isClassDeclaration(classLike) && !isClassExpression(classLike)) {
const classLike = getEffectiveJSDocHost(node);
if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) {
error(classLike, Diagnostics.JSDoc_0_is_not_attached_to_a_class, idText(node.tagName));
return;
}
}
function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void {
const classLike = getJSDocHost(node);
if (!isClassDeclaration(classLike) && !isClassExpression(classLike)) {
const classLike = getEffectiveJSDocHost(node);
if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) {
error(classLike, Diagnostics.JSDoc_0_is_not_attached_to_a_class, idText(node.tagName));
return;
}

View File

@@ -2466,19 +2466,22 @@ namespace ts {
}
export function getHostSignatureFromJSDoc(node: Node): SignatureDeclaration | undefined {
return getHostSignatureFromJSDocHost(getJSDocHost(node));
const host = getEffectiveJSDocHost(node);
return host && isFunctionLike(host) ? host : undefined;
}
export function getHostSignatureFromJSDocHost(host: HasJSDoc): SignatureDeclaration | undefined {
export function getEffectiveJSDocHost(node: Node): Node | undefined {
const host = getJSDocHost(node);
const decl = getSourceOfDefaultedAssignment(host) ||
getSourceOfAssignment(host) ||
getSingleInitializerOfVariableStatementOrPropertyDeclaration(host) ||
getSingleVariableOfVariableStatement(host) ||
getNestedModuleDeclaration(host) ||
host;
return decl && isFunctionLike(decl) ? decl : undefined;
return decl;
}
/** Use getEffectiveJSDocHost if you additionally need to look for jsdoc on parent nodes, like assignments. */
export function getJSDocHost(node: Node): HasJSDoc {
return Debug.checkDefined(findAncestor(node.parent, isJSDoc)).parent;
}