Skip to content

Commit a70c773

Browse files
committed
Fixes 57026
1 parent 1539234 commit a70c773

5 files changed

Lines changed: 46 additions & 13 deletions

File tree

src/services/findAllReferences.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,8 @@ export namespace Core {
10131013
const checker = program.getTypeChecker();
10141014
// constructors should use the class symbol, detected by name, if present
10151015
const symbol = checker.getSymbolAtLocation(isConstructorDeclaration(node) && node.parent.name || node);
1016-
10171016
// Could not find a symbol e.g. unknown identifier
1018-
if (!symbol) {
1017+
if (!symbol || (isStringLiteralLike(node) && isStringLiteralPropertyReference(node, checker))) {
10191018
// String literal might be a property (and thus have a symbol), so do this here rather than in getReferencedSymbolsSpecial.
10201019
if (!options.implementations && isStringLiteralLike(node)) {
10211020
if (isModuleSpecifierLike(node)) {
@@ -1389,7 +1388,8 @@ export namespace Core {
13891388
/** Only set if `options.implementations` is true. These are the symbols checked to get the implementations of a property access. */
13901389
readonly parents: readonly Symbol[] | undefined;
13911390
readonly allSearchSymbols: readonly Symbol[];
1392-
1391+
/** The node that we are searching for. This is used for searching. */
1392+
readonly node: Node | undefined;
13931393
/**
13941394
* Whether a symbol is in the search set.
13951395
* Do not compare directly to `symbol` because there may be related symbols to search for. See `populateSearchSymbolSet`.
@@ -1474,7 +1474,7 @@ export namespace Core {
14741474
} = searchOptions;
14751475
const escapedText = escapeLeadingUnderscores(text);
14761476
const parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
1477-
return { symbol, comingFrom, text, escapedText, parents, allSearchSymbols, includes: sym => contains(allSearchSymbols, sym) };
1477+
return { symbol, comingFrom, text, escapedText, parents, allSearchSymbols, node: location, includes: sym => contains(allSearchSymbols, sym) };
14781478
}
14791479

14801480
private readonly symbolIdToReferences: Entry[][] = [];
@@ -1921,7 +1921,15 @@ export namespace Core {
19211921
// 'FindReferences' will just filter out these results.
19221922
state.addStringOrCommentReference(sourceFile.fileName, createTextSpan(position, search.text.length));
19231923
}
1924-
1924+
// if ( search.node &&!state.checker.getSymbolAtLocation(referenceLocation) && !state.options.implementations && isStringLiteralLike(search.node) && isStringLiteralLike(referenceLocation) )
1925+
// {
1926+
// const type = getContextualTypeFromParentOrAncestorTypeNode(search.node, state.checker)
1927+
// const refType = getContextualTypeFromParentOrAncestorTypeNode(referenceLocation, state.checker)
1928+
// if (type !== state.checker.getStringType() && type === refType)
1929+
// {
1930+
// addReference(referenceLocation, referenceLocation.symbol, state);
1931+
// }
1932+
// }
19251933
return;
19261934
}
19271935

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// === findRenameLocations ===
22
// === /tests/cases/fourslash/renameStringLiteralTypes5.ts ===
3-
// type T = {
4-
// <|"[|Prop 1RENAME|]": string;|>
3+
// declare const Att_1: "[|Att 2RENAME|]"/*RENAME*/
4+
//
5+
// interface Case_1 {
6+
// [Att_1]: string
57
// }
68
//
7-
// declare const fn: <K extends keyof T>(p: K) => void
9+
// declare const fnc_1: <K extends keyof Case_1>(p: K) => void
810
//
9-
// fn("[|Prop 1RENAME|]"/*RENAME*/)
11+
// fnc_1("[|Att 2RENAME|]")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// === findRenameLocations ===
2+
// === /tests/cases/fourslash/renameStringLiteralTypes6.ts ===
3+
// interface Case_1 {
4+
// <|"[|Att 2RENAME|]"/*RENAME*/: string|>
5+
// }
6+
//
7+
// declare const fnc_1: <K extends keyof Case_1>(p: K) => void
8+
//
9+
// fnc_1("[|Att 2RENAME|]")
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/// <reference path="fourslash.ts" />
22

3-
////type T = {
4-
//// "Prop 1": string;
3+
////declare const Att_1: "Att 2"/**/
4+
////
5+
////interface Case_1 {
6+
//// [Att_1]: string
57
////}
68
////
7-
////declare const fn: <K extends keyof T>(p: K) => void
9+
////declare const fnc_1: <K extends keyof Case_1>(p: K) => void
810
////
9-
////fn("Prop 1"/**/)
11+
////fnc_1("Att 2")
1012

1113
verify.baselineRename("", {});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
4+
////interface Case_1 {
5+
//// "Att 2"/**/: string
6+
////}
7+
////
8+
////declare const fnc_1: <K extends keyof Case_1>(p: K) => void
9+
////
10+
////fnc_1("Att 2")
11+
12+
verify.baselineRename("", {});

0 commit comments

Comments
 (0)