From 1814e2a5c4b024fc56cf9291a26e2d3a746e4302 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 7 Jul 2020 10:37:52 -0700 Subject: [PATCH] Mark @typedef as a type declaration (#39468) * Mark @typedef as a type declaration This is only important right now for marking uses of deprecated tags due to the way that deprecated type references are computed. But I'm surprised it hasn't caused problems elsewhere. Fixes #39466 * Also mark @callback and @enum Requires making name lookup in isTypeDeclarationName smarter, but this is only used by services, so shouldn't be too performance sensitive. --- src/compiler/checker.ts | 7 ++++-- .../fourslash/jsdocDeprecated_suggestion5.ts | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/jsdocDeprecated_suggestion5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a39022e276..c090dc1c848 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -36107,16 +36107,19 @@ namespace ts { function isTypeDeclarationName(name: Node): boolean { return name.kind === SyntaxKind.Identifier && isTypeDeclaration(name.parent) && - name.parent.name === name; + getNameOfDeclaration(name.parent) === name; } - function isTypeDeclaration(node: Node): node is TypeParameterDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ImportClause | ImportSpecifier | ExportSpecifier { + function isTypeDeclaration(node: Node): node is TypeParameterDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag | EnumDeclaration | ImportClause | ImportSpecifier | ExportSpecifier { switch (node.kind) { case SyntaxKind.TypeParameter: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: + case SyntaxKind.JSDocTypedefTag: + case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.JSDocEnumTag: return true; case SyntaxKind.ImportClause: return (node as ImportClause).isTypeOnly; diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion5.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion5.ts new file mode 100644 index 00000000000..9693d291f1e --- /dev/null +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion5.ts @@ -0,0 +1,23 @@ +/// + +// @checkJs: true +// @allowJs: true +// @Filename: jsdocDeprecated_suggestion5.js +//// /** @typedef {{ email: string, nickName?: string }} U2 */ +//// /** @type {U2} */ +//// const u2 = { email: "" } + +//// /** +//// * @callback K +//// * @param {any} ctx +//// * @return {void} +//// */ +//// /** @type {K} */ +//// const cc = _k => {} + +//// /** @enum {number} */ +//// const DOOM = { e: 1, m: 1 } +//// /** @type {DOOM} */ +//// const kneeDeep = DOOM.e + +verify.getSuggestionDiagnostics([])