From e858de95200324969e9c4c27836045e2b0f00e17 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 9 Apr 2018 13:26:10 -0700 Subject: [PATCH] Simplify handling of parameter properties in forEachRelatedSymbol (#23213) * Simplify handling of parameter properties in forEachRelatedSymbol * Add assert for other paramProps symbol --- src/services/findAllReferences.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 98dd4666e8d..41d08bc6582 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1376,7 +1376,6 @@ namespace ts.FindAllReferences.Core { const result: Symbol[] = []; forEachRelatedSymbol(symbol, location, checker, (sym, root, base) => { result.push(base || root || sym); }, - parameterProperties => { result.push(...parameterProperties); }, /*allowBaseTypes*/ () => !implementations); return result; } @@ -1384,7 +1383,6 @@ namespace ts.FindAllReferences.Core { function forEachRelatedSymbol( symbol: Symbol, location: Node, checker: TypeChecker, cbSymbol: (symbol: Symbol, rootSymbol?: Symbol, baseSymbol?: Symbol) => T | undefined, - cbParameterProperties: (s: Symbol[]) => T | undefined, allowBaseTypes: (rootSymbol: Symbol) => boolean, ): T | undefined { const containingObjectLiteralElement = getContainingObjectLiteralElement(location); @@ -1421,14 +1419,11 @@ namespace ts.FindAllReferences.Core { const res = fromRoot(symbol); if (res) return res; - // If the symbol.valueDeclaration is a property parameter declaration, - // we should include both parameter declaration symbol and property declaration symbol - // Parameter Declaration symbol is only visible within function scope, so the symbol is stored in constructor.locals. - // Property Declaration symbol is a member of the class, so the symbol is stored in its class Declaration.symbol.members - if (symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isParameterPropertyDeclaration(symbol.valueDeclaration)) { - const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(symbol.valueDeclaration, symbol.name); - const res = paramProps && cbParameterProperties(paramProps); - if (res) return res; + if (symbol.valueDeclaration && isParameterPropertyDeclaration(symbol.valueDeclaration)) { + // For a parameter property, now try on the other symbol (property if this was a parameter, parameter if this was a property). + const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(cast(symbol.valueDeclaration, isParameter), symbol.name); + Debug.assert(paramProps.length === 2 && !!(paramProps[0].flags & SymbolFlags.FunctionScopedVariable) && !!(paramProps[1].flags & SymbolFlags.Property)); // is [parameter, property] + return fromRoot(symbol.flags & SymbolFlags.FunctionScopedVariable ? paramProps[1] : paramProps[0]); } // If this is symbol of binding element without propertyName declaration in Object binding pattern @@ -1487,9 +1482,6 @@ namespace ts.FindAllReferences.Core { // For a base type, use the symbol for the derived type. For a synthetic (e.g. union) property, use the union symbol. ? rootSymbol && !(getCheckFlags(sym) & CheckFlags.Synthetic) ? rootSymbol : sym : undefined, - paramProps => referenceSymbol.flags & SymbolFlags.FunctionScopedVariable - ? getRelatedSymbol(search, find(paramProps, x => !!(x.flags & SymbolFlags.Property))!, referenceLocation, state) - : undefined, /*allowBaseTypes*/ rootSymbol => !(search.parents && !some(search.parents, parent => explicitlyInheritsFrom(rootSymbol.parent, parent, state.inheritsFromCache, checker)))); }