Skip to content

Commit 2ccfe50

Browse files
author
Andy
authored
Fix scope of @typedef references (#16718)
* Fix scope of @typedef references * Remove unused variables
1 parent 9013665 commit 2ccfe50

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/services/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ namespace ts {
275275
}
276276

277277
export function getContainerNode(node: Node): Declaration {
278+
if (node.kind === SyntaxKind.JSDocTypedefTag) {
279+
// This doesn't just apply to the node immediately under the comment, but to everything in its parent's scope.
280+
// node.parent = the JSDoc comment, node.parent.parent = the node having the comment.
281+
// Then we get parent again in the loop.
282+
node = node.parent.parent;
283+
}
284+
278285
while (true) {
279286
node = node.parent;
280287
if (!node) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// Tests that the scope of @typedef is not just the node immediately below it.
4+
5+
// @allowJs: true
6+
7+
// @Filename: /a.js
8+
/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */
9+
////
10+
/////**
11+
//// * @return {[|T|]}
12+
//// */
13+
////function f(obj) { return 0; }
14+
////
15+
/////**
16+
//// * @return {[|T|]}
17+
//// */
18+
////function f2(obj) { return 0; }
19+
20+
verify.singleReferenceGroup("type T = number");

0 commit comments

Comments
 (0)