fix(37539): extend scope for function expressions to include JSDoc (#41364)

This commit is contained in:
Oleksandr T
2020-12-11 19:00:05 +02:00
committed by GitHub
parent 06d37a2318
commit 1c1cd9b08d
6 changed files with 47 additions and 2 deletions

View File

@@ -2569,7 +2569,7 @@ namespace ts {
return result || emptyArray;
}
function getNextJSDocCommentLocation(node: Node) {
export function getNextJSDocCommentLocation(node: Node) {
const parent = node.parent;
if (parent.kind === SyntaxKind.PropertyAssignment ||
parent.kind === SyntaxKind.ExportAssignment ||

View File

@@ -1206,8 +1206,13 @@ namespace ts.FindAllReferences {
return undefined;
}
// The search scope is the container node
scope = container;
if (isFunctionExpression(scope)) {
let next: Node | undefined;
while (next = getNextJSDocCommentLocation(scope)) {
scope = next;
}
}
}
// If symbol.parent, this means we are in an export of an external module. (Otherwise we would have returned `undefined` above.)

View File

@@ -0,0 +1,10 @@
/*====== /tests/cases/fourslash/renameFunctionParameter1.ts ======*/
function Foo() {
/**
* @param {number} RENAME
*/
this.foo = function foo([|RENAME|]) {
return RENAME;
}
}

View File

@@ -0,0 +1,8 @@
/*====== /tests/cases/fourslash/renameFunctionParameter2.ts ======*/
/**
* @param {number} RENAME
*/
const foo = function foo([|RENAME|]) {
return RENAME;
}

View File

@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />
////function Foo() {
//// /**
//// * @param {number} p
//// */
//// this.foo = function foo(p/**/) {
//// return p;
//// }
////}
verify.baselineRename("", {});

View File

@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
/////**
//// * @param {number} p
//// */
////const foo = function foo(p/**/) {
//// return p;
////}
verify.baselineRename("", {});