Skip to content

Commit 83e3d6a

Browse files
authored
Skip visits to child nodes of entity names in visitExistingNodeTreeSymbols (#58067)
1 parent 772c290 commit 83e3d6a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/compiler/checker.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8679,15 +8679,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
86798679
else {
86808680
context.tracker.trackSymbol(sym, context.enclosingDeclaration, meaning);
86818681
}
8682-
if (isIdentifier(node)) {
8683-
const type = getDeclaredTypeOfSymbol(sym);
8684-
const name = sym.flags & SymbolFlags.TypeParameter ? typeParameterToName(type, context) : factory.cloneNode(node);
8685-
name.symbol = sym; // for quickinfo, which uses identifier symbol information
8686-
return { introducesError, node: setTextRange(setEmitFlags(setOriginalNode(name, node), EmitFlags.NoAsciiEscaping), node) };
8687-
}
8682+
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
86888683
}
86898684

86908685
return { introducesError, node };
8686+
8687+
/**
8688+
* Attaches a `.symbol` member to an identifier, cloning it to do so, so symbol information
8689+
* is smuggled out for symbol display information.
8690+
*/
8691+
function attachSymbolToLeftmostIdentifier(node: Node): Node {
8692+
if (node === leftmost) {
8693+
const type = getDeclaredTypeOfSymbol(sym!);
8694+
const name = sym!.flags & SymbolFlags.TypeParameter ? typeParameterToName(type, context) : factory.cloneNode(node as Identifier);
8695+
name.symbol = sym!; // for quickinfo, which uses identifier symbol information
8696+
return setTextRange(setEmitFlags(setOriginalNode(name, node), EmitFlags.NoAsciiEscaping), node);
8697+
}
8698+
const updated = visitEachChild(node, c => attachSymbolToLeftmostIdentifier(c), /*context*/ undefined);
8699+
if (updated !== node) {
8700+
setTextRange(updated, node);
8701+
}
8702+
return updated;
8703+
}
86918704
}
86928705

86938706
/**
@@ -8856,11 +8869,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
88568869
}
88578870

88588871
if (isEntityName(node) || isEntityNameExpression(node)) {
8872+
if (isDeclarationName(node)) {
8873+
return node;
8874+
}
88598875
const { introducesError, node: result } = trackExistingEntityName(node, context);
88608876
hadError = hadError || introducesError;
8861-
if (result !== node) {
8862-
return result;
8863-
}
8877+
// We should not go to child nodes of the entity name, they will not be accessible
8878+
return result;
88648879
}
88658880

88668881
if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {

0 commit comments

Comments
 (0)