Skip to content

Commit

Permalink
Skip visits to child nodes of entity names in visitExistingNodeTreeSy…
Browse files Browse the repository at this point in the history
…mbols (#58067)
  • Loading branch information
weswigham authored Apr 4, 2024
1 parent 772c290 commit 83e3d6a
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8679,15 +8679,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else {
context.tracker.trackSymbol(sym, context.enclosingDeclaration, meaning);
}
if (isIdentifier(node)) {
const type = getDeclaredTypeOfSymbol(sym);
const name = sym.flags & SymbolFlags.TypeParameter ? typeParameterToName(type, context) : factory.cloneNode(node);
name.symbol = sym; // for quickinfo, which uses identifier symbol information
return { introducesError, node: setTextRange(setEmitFlags(setOriginalNode(name, node), EmitFlags.NoAsciiEscaping), node) };
}
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
}

return { introducesError, node };

/**
* Attaches a `.symbol` member to an identifier, cloning it to do so, so symbol information
* is smuggled out for symbol display information.
*/
function attachSymbolToLeftmostIdentifier(node: Node): Node {
if (node === leftmost) {
const type = getDeclaredTypeOfSymbol(sym!);
const name = sym!.flags & SymbolFlags.TypeParameter ? typeParameterToName(type, context) : factory.cloneNode(node as Identifier);
name.symbol = sym!; // for quickinfo, which uses identifier symbol information
return setTextRange(setEmitFlags(setOriginalNode(name, node), EmitFlags.NoAsciiEscaping), node);
}
const updated = visitEachChild(node, c => attachSymbolToLeftmostIdentifier(c), /*context*/ undefined);
if (updated !== node) {
setTextRange(updated, node);
}
return updated;
}
}

/**
Expand Down Expand Up @@ -8856,11 +8869,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

if (isEntityName(node) || isEntityNameExpression(node)) {
if (isDeclarationName(node)) {
return node;
}
const { introducesError, node: result } = trackExistingEntityName(node, context);
hadError = hadError || introducesError;
if (result !== node) {
return result;
}
// We should not go to child nodes of the entity name, they will not be accessible
return result;
}

if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
Expand Down

0 comments on commit 83e3d6a

Please sign in to comment.