From 2d802a62c4609ef705e80aa5bd006a598f362518 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 7 Jul 2017 10:34:11 -0700 Subject: [PATCH] Have `isObjectBindingPatternElementWithoutPropertyName` return the binding element (#16956) --- src/services/findAllReferences.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 7d52a9f6486..9fc3588ddb9 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -593,16 +593,18 @@ namespace ts.FindAllReferences.Core { checker.getPropertySymbolOfDestructuringAssignment(location); } - function isObjectBindingPatternElementWithoutPropertyName(symbol: Symbol): boolean { + function getObjectBindingElementWithoutPropertyName(symbol: Symbol): BindingElement | undefined { const bindingElement = getDeclarationOfKind(symbol, SyntaxKind.BindingElement); - return bindingElement && + if (bindingElement && bindingElement.parent.kind === SyntaxKind.ObjectBindingPattern && - !bindingElement.propertyName; + !bindingElement.propertyName) { + return bindingElement; + } } function getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol: Symbol, checker: TypeChecker): Symbol | undefined { - if (isObjectBindingPatternElementWithoutPropertyName(symbol)) { - const bindingElement = getDeclarationOfKind(symbol, SyntaxKind.BindingElement); + const bindingElement = getObjectBindingElementWithoutPropertyName(symbol); + if (bindingElement) { const typeOfPattern = checker.getTypeAtLocation(bindingElement.parent); return typeOfPattern && checker.getPropertyOfType(typeOfPattern, unescapeLeadingUnderscores((bindingElement.name).text)); } @@ -641,7 +643,7 @@ namespace ts.FindAllReferences.Core { // If symbol is of object binding pattern element without property name we would want to // look for property too and that could be anywhere - if (isObjectBindingPatternElementWithoutPropertyName(symbol)) { + if (getObjectBindingElementWithoutPropertyName(symbol)) { return undefined; }