Skip to content

Commit 1c1cd9b

Browse files
authored
fix(37539): extend scope for function expressions to include JSDoc (#41364)
1 parent 06d37a2 commit 1c1cd9b

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,7 @@ namespace ts {
25692569
return result || emptyArray;
25702570
}
25712571

2572-
function getNextJSDocCommentLocation(node: Node) {
2572+
export function getNextJSDocCommentLocation(node: Node) {
25732573
const parent = node.parent;
25742574
if (parent.kind === SyntaxKind.PropertyAssignment ||
25752575
parent.kind === SyntaxKind.ExportAssignment ||

src/services/findAllReferences.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,13 @@ namespace ts.FindAllReferences {
12061206
return undefined;
12071207
}
12081208

1209-
// The search scope is the container node
12101209
scope = container;
1210+
if (isFunctionExpression(scope)) {
1211+
let next: Node | undefined;
1212+
while (next = getNextJSDocCommentLocation(scope)) {
1213+
scope = next;
1214+
}
1215+
}
12111216
}
12121217

12131218
// If symbol.parent, this means we are in an export of an external module. (Otherwise we would have returned `undefined` above.)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*====== /tests/cases/fourslash/renameFunctionParameter1.ts ======*/
2+
3+
function Foo() {
4+
/**
5+
* @param {number} RENAME
6+
*/
7+
this.foo = function foo([|RENAME|]) {
8+
return RENAME;
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*====== /tests/cases/fourslash/renameFunctionParameter2.ts ======*/
2+
3+
/**
4+
* @param {number} RENAME
5+
*/
6+
const foo = function foo([|RENAME|]) {
7+
return RENAME;
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function Foo() {
4+
//// /**
5+
//// * @param {number} p
6+
//// */
7+
//// this.foo = function foo(p/**/) {
8+
//// return p;
9+
//// }
10+
////}
11+
12+
verify.baselineRename("", {});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
/////**
4+
//// * @param {number} p
5+
//// */
6+
////const foo = function foo(p/**/) {
7+
//// return p;
8+
////}
9+
10+
verify.baselineRename("", {});

0 commit comments

Comments
 (0)