Skip to content

Commit e858de9

Browse files
author
Andy
authored
Simplify handling of parameter properties in forEachRelatedSymbol (#23213)
* Simplify handling of parameter properties in forEachRelatedSymbol * Add assert for other paramProps symbol
1 parent 98a5e5c commit e858de9

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/services/findAllReferences.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,13 @@ namespace ts.FindAllReferences.Core {
13761376
const result: Symbol[] = [];
13771377
forEachRelatedSymbol<void>(symbol, location, checker,
13781378
(sym, root, base) => { result.push(base || root || sym); },
1379-
parameterProperties => { result.push(...parameterProperties); },
13801379
/*allowBaseTypes*/ () => !implementations);
13811380
return result;
13821381
}
13831382

13841383
function forEachRelatedSymbol<T>(
13851384
symbol: Symbol, location: Node, checker: TypeChecker,
13861385
cbSymbol: (symbol: Symbol, rootSymbol?: Symbol, baseSymbol?: Symbol) => T | undefined,
1387-
cbParameterProperties: (s: Symbol[]) => T | undefined,
13881386
allowBaseTypes: (rootSymbol: Symbol) => boolean,
13891387
): T | undefined {
13901388
const containingObjectLiteralElement = getContainingObjectLiteralElement(location);
@@ -1421,14 +1419,11 @@ namespace ts.FindAllReferences.Core {
14211419
const res = fromRoot(symbol);
14221420
if (res) return res;
14231421

1424-
// If the symbol.valueDeclaration is a property parameter declaration,
1425-
// we should include both parameter declaration symbol and property declaration symbol
1426-
// Parameter Declaration symbol is only visible within function scope, so the symbol is stored in constructor.locals.
1427-
// Property Declaration symbol is a member of the class, so the symbol is stored in its class Declaration.symbol.members
1428-
if (symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isParameterPropertyDeclaration(symbol.valueDeclaration)) {
1429-
const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(symbol.valueDeclaration, symbol.name);
1430-
const res = paramProps && cbParameterProperties(paramProps);
1431-
if (res) return res;
1422+
if (symbol.valueDeclaration && isParameterPropertyDeclaration(symbol.valueDeclaration)) {
1423+
// For a parameter property, now try on the other symbol (property if this was a parameter, parameter if this was a property).
1424+
const paramProps = checker.getSymbolsOfParameterPropertyDeclaration(cast(symbol.valueDeclaration, isParameter), symbol.name);
1425+
Debug.assert(paramProps.length === 2 && !!(paramProps[0].flags & SymbolFlags.FunctionScopedVariable) && !!(paramProps[1].flags & SymbolFlags.Property)); // is [parameter, property]
1426+
return fromRoot(symbol.flags & SymbolFlags.FunctionScopedVariable ? paramProps[1] : paramProps[0]);
14321427
}
14331428

14341429
// If this is symbol of binding element without propertyName declaration in Object binding pattern
@@ -1487,9 +1482,6 @@ namespace ts.FindAllReferences.Core {
14871482
// For a base type, use the symbol for the derived type. For a synthetic (e.g. union) property, use the union symbol.
14881483
? rootSymbol && !(getCheckFlags(sym) & CheckFlags.Synthetic) ? rootSymbol : sym
14891484
: undefined,
1490-
paramProps => referenceSymbol.flags & SymbolFlags.FunctionScopedVariable
1491-
? getRelatedSymbol(search, find(paramProps, x => !!(x.flags & SymbolFlags.Property))!, referenceLocation, state)
1492-
: undefined,
14931485
/*allowBaseTypes*/ rootSymbol =>
14941486
!(search.parents && !some(search.parents, parent => explicitlyInheritsFrom(rootSymbol.parent, parent, state.inheritsFromCache, checker))));
14951487
}

0 commit comments

Comments
 (0)