mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Correct node used for isDefinition calculation (#48499)
It should be adjusted as in `getReferencedSymbolsForNode`. The baseline changes show that it was incorrectly returning false at keywords preceding definitions.
This commit is contained in:
@@ -206,9 +206,10 @@ namespace ts.FindAllReferences {
|
||||
|
||||
export function findReferencedSymbols(program: Program, cancellationToken: CancellationToken, sourceFiles: readonly SourceFile[], sourceFile: SourceFile, position: number): ReferencedSymbol[] | undefined {
|
||||
const node = getTouchingPropertyName(sourceFile, position);
|
||||
const referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, { use: FindReferencesUse.References });
|
||||
const options = { use: FindReferencesUse.References };
|
||||
const referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
|
||||
const checker = program.getTypeChecker();
|
||||
const symbol = checker.getSymbolAtLocation(node);
|
||||
const symbol = checker.getSymbolAtLocation(getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
|
||||
return !referencedSymbols || !referencedSymbols.length ? undefined : mapDefined<SymbolAndEntries, ReferencedSymbol>(referencedSymbols, ({ definition, references }) =>
|
||||
// Only include referenced symbols that have a valid definition.
|
||||
definition && {
|
||||
@@ -622,12 +623,7 @@ namespace ts.FindAllReferences {
|
||||
export namespace Core {
|
||||
/** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */
|
||||
export function getReferencedSymbolsForNode(position: number, node: Node, program: Program, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken, options: Options = {}, sourceFilesSet: ReadonlySet<string> = new Set(sourceFiles.map(f => f.fileName))): readonly SymbolAndEntries[] | undefined {
|
||||
if (options.use === FindReferencesUse.References) {
|
||||
node = getAdjustedReferenceLocation(node);
|
||||
}
|
||||
else if (options.use === FindReferencesUse.Rename) {
|
||||
node = getAdjustedRenameLocation(node);
|
||||
}
|
||||
node = getAdjustedNode(node, options);
|
||||
if (isSourceFile(node)) {
|
||||
const resolvedRef = GoToDefinition.getReferenceAtPosition(node, position, program);
|
||||
if (!resolvedRef?.file) {
|
||||
@@ -695,6 +691,16 @@ namespace ts.FindAllReferences {
|
||||
return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
|
||||
}
|
||||
|
||||
export function getAdjustedNode(node: Node, options: Options) {
|
||||
if (options.use === FindReferencesUse.References) {
|
||||
node = getAdjustedReferenceLocation(node);
|
||||
}
|
||||
else if (options.use === FindReferencesUse.Rename) {
|
||||
node = getAdjustedRenameLocation(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
export function getReferencesForFileName(fileName: string, program: Program, sourceFiles: readonly SourceFile[], sourceFilesSet: ReadonlySet<string> = new Set(sourceFiles.map(f => f.fileName))): readonly Entry[] {
|
||||
const moduleSymbol = program.getSourceFile(fileName)?.symbol;
|
||||
if (moduleSymbol) {
|
||||
|
||||
Reference in New Issue
Block a user