Fix bogus use before def in jsdoc (#25532)

Block scoped variables, classes and enums would issue a bogus
use-before-def error in jsdoc because name resolution always adds Value,
even when resolving a type.

Fixes #25097
This commit is contained in:
Nathan Shively-Sanders 2018-07-10 08:33:19 -07:00 committed by GitHub
parent 60c0dfeb25
commit c344a3ea5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View File

@ -1059,6 +1059,7 @@ namespace ts {
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
// or if usage is in a type context:
// 1. inside a type query (typeof in type position)
// 2. inside a jsdoc comment
if (usage.parent.kind === SyntaxKind.ExportSpecifier || (usage.parent.kind === SyntaxKind.ExportAssignment && (usage.parent as ExportAssignment).isExportEquals)) {
// export specifiers do not use the variable, they only make it available for use
return true;
@ -1069,7 +1070,7 @@ namespace ts {
}
const container = getEnclosingBlockScopeContainer(declaration);
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);
return !!(usage.flags & NodeFlags.JSDoc) || isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
const container = getEnclosingBlockScopeContainer(declaration);

View File

@ -0,0 +1,9 @@
=== tests/cases/conformance/jsdoc/bug25097.js ===
/** @type {C | null} */
const c = null
>c : Symbol(c, Decl(bug25097.js, 1, 5))
class C {
>C : Symbol(C, Decl(bug25097.js, 1, 14))
}

View File

@ -0,0 +1,10 @@
=== tests/cases/conformance/jsdoc/bug25097.js ===
/** @type {C | null} */
const c = null
>c : C
>null : null
class C {
>C : C
}

View File

@ -0,0 +1,8 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug25097.js
/** @type {C | null} */
const c = null
class C {
}