From 2ccfe502f7b8697e83cd44a6cdd8f4c5d334c2ed Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 28 Jun 2017 13:30:23 -0700 Subject: [PATCH] Fix scope of @typedef references (#16718) * Fix scope of @typedef references * Remove unused variables --- src/services/utilities.ts | 7 +++++++ .../fourslash/findAllRefsJsDocTypeDef_js.ts | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 089e2de2b29..851ad4905fb 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -275,6 +275,13 @@ namespace ts { } export function getContainerNode(node: Node): Declaration { + if (node.kind === SyntaxKind.JSDocTypedefTag) { + // This doesn't just apply to the node immediately under the comment, but to everything in its parent's scope. + // node.parent = the JSDoc comment, node.parent.parent = the node having the comment. + // Then we get parent again in the loop. + node = node.parent.parent; + } + while (true) { node = node.parent; if (!node) { diff --git a/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts b/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts new file mode 100644 index 00000000000..a2d0cad3886 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts @@ -0,0 +1,20 @@ +/// + +// Tests that the scope of @typedef is not just the node immediately below it. + +// @allowJs: true + +// @Filename: /a.js +/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */ +//// +/////** +//// * @return {[|T|]} +//// */ +////function f(obj) { return 0; } +//// +/////** +//// * @return {[|T|]} +//// */ +////function f2(obj) { return 0; } + +verify.singleReferenceGroup("type T = number");