mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix find-all-references for destructured getter (#17483)
* Fix find-all-references for destructured getter * Handle setter too * Use SymbolFlags.Accessor
This commit is contained in:
@@ -604,11 +604,16 @@ namespace ts.FindAllReferences.Core {
|
||||
|
||||
function getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol: Symbol, checker: TypeChecker): Symbol | undefined {
|
||||
const bindingElement = getObjectBindingElementWithoutPropertyName(symbol);
|
||||
if (bindingElement) {
|
||||
const typeOfPattern = checker.getTypeAtLocation(bindingElement.parent);
|
||||
return typeOfPattern && checker.getPropertyOfType(typeOfPattern, (<Identifier>bindingElement.name).text);
|
||||
if (!bindingElement) return undefined;
|
||||
|
||||
const typeOfPattern = checker.getTypeAtLocation(bindingElement.parent);
|
||||
const propSymbol = typeOfPattern && checker.getPropertyOfType(typeOfPattern, (<Identifier>bindingElement.name).text);
|
||||
if (propSymbol && propSymbol.flags & SymbolFlags.Accessor) {
|
||||
// See GH#16922
|
||||
Debug.assert(!!(propSymbol.flags & SymbolFlags.Transient));
|
||||
return (propSymbol as TransientSymbol).target;
|
||||
}
|
||||
return undefined;
|
||||
return propSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class Test {
|
||||
//// get [|{| "isDefinition": true, "isWriteAccess": true |}x|]() { return 0; }
|
||||
////
|
||||
//// set [|{| "isDefinition": true, "isWriteAccess": true |}y|](a: number) {}
|
||||
////}
|
||||
////const { [|{| "isDefinition": true, "isWriteAccess": true |}x|], [|{| "isDefinition": true, "isWriteAccess": true |}y|] } = new Test();
|
||||
////[|x|]; [|y|];
|
||||
|
||||
const [x0, y0, x1, y1, x2, y2] = test.ranges();
|
||||
verify.referenceGroups(x0, [{ definition: "(property) Test.x: number", ranges: [x0, x1, x2] }]);
|
||||
verify.referenceGroups([x1, x2], [
|
||||
{ definition: "(property) Test.x: number", ranges: [x0] },
|
||||
{ definition: "const x: number", ranges: [x1, x2] },
|
||||
]);
|
||||
|
||||
verify.referenceGroups(y0, [{ definition: "(property) Test.y: number", ranges: [y0, y1, y2] }]);
|
||||
verify.referenceGroups([y1, y2], [
|
||||
{ definition: "(property) Test.y: number", ranges: [y0] },
|
||||
{ definition: "const y: number", ranges: [y1, y2] },
|
||||
]);
|
||||
Reference in New Issue
Block a user