fix(54268): Renaming JSDoc @param symbol only renames the first instance (#56226)

This commit is contained in:
Oleksandr T
2023-11-17 13:46:42 -08:00
committed by GitHub
parent 196dcf8a95
commit f07c0dd637
3 changed files with 47 additions and 0 deletions
+25
View File
@@ -41,6 +41,7 @@ import {
firstDefined,
firstOrUndefined,
flatMap,
forEach,
forEachChild,
forEachChildRecursively,
forEachReturnStatement,
@@ -131,7 +132,9 @@ import {
isInString,
isInterfaceDeclaration,
isJSDocMemberName,
isJSDocPropertyLikeTag,
isJSDocTag,
isJSDocTypeLiteral,
isJsxClosingElement,
isJsxElement,
isJsxFragment,
@@ -185,7 +188,9 @@ import {
isVariableStatement,
isVoidExpression,
isWriteAccess,
JSDocPropertyLikeTag,
JSDocTag,
length,
map,
mapDefined,
MethodDeclaration,
@@ -1928,6 +1933,15 @@ export namespace Core {
return;
}
if (
isJSDocPropertyLikeTag(parent) && parent.isNameFirst &&
parent.typeExpression && isJSDocTypeLiteral(parent.typeExpression.type) &&
parent.typeExpression.type.jsDocPropertyTags && length(parent.typeExpression.type.jsDocPropertyTags)
) {
getReferencesAtJSDocTypeLiteral(parent.typeExpression.type.jsDocPropertyTags, referenceLocation, search, state);
return;
}
const relatedSymbol = getRelatedSymbol(search, referenceSymbol, referenceLocation, state);
if (!relatedSymbol) {
getReferenceForShorthandProperty(referenceSymbol, search, state);
@@ -1963,6 +1977,17 @@ export namespace Core {
getImportOrExportReferences(referenceLocation, referenceSymbol, search, state);
}
function getReferencesAtJSDocTypeLiteral(jsDocPropertyTags: readonly JSDocPropertyLikeTag[], referenceLocation: Node, search: Search, state: State) {
const addRef = state.referenceAdder(search.symbol);
addReference(referenceLocation, search.symbol, state);
forEach(jsDocPropertyTags, propTag => {
if (isQualifiedName(propTag.name)) {
addRef(propTag.name.left);
}
});
}
function getReferencesAtExportSpecifier(
referenceLocation: Identifier,
referenceSymbol: Symbol,
@@ -0,0 +1,8 @@
// === findRenameLocations ===
// === /a.js ===
// /**
// * @param {Object} [|optionsRENAME|]
// * @param {string} [|optionsRENAME|].foo
// * @param {number} [|optionsRENAME|].bar
// */
// function foo(/*RENAME*/[|optionsRENAME|]) {}
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @checkJs: true
// @filename: /a.js
/////**
//// * @param {Object} options
//// * @param {string} options.foo
//// * @param {number} options.bar
//// */
////function foo(/**/options) {}
goTo.file("/a.js");
verify.baselineRename("", { });