Skip to content

Commit b00c13b

Browse files
author
Andy
authored
Fix bug: Handle QualifiedName in getMeaningFromRightHandSideOfImportEquals (#21779)
* Fix bug: Handle QualifiedName in getMeaningFromRightHandSideOfImportEquals * Fix lint
1 parent 98baea9 commit b00c13b

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/harness/fourslash.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ namespace FourSlash {
10861086
}
10871087
}
10881088

1089-
public verifyReferenceGroups(startRanges: Range | Range[], parts: FourSlashInterface.ReferenceGroup[]): void {
1089+
public verifyReferenceGroups(starts: string | string[] | Range | Range[], parts: FourSlashInterface.ReferenceGroup[]): void {
10901090
interface ReferenceGroupJson {
10911091
definition: string | { text: string, range: ts.TextSpan };
10921092
references: ts.ReferenceEntry[];
@@ -1105,8 +1105,13 @@ namespace FourSlash {
11051105
}),
11061106
}));
11071107

1108-
for (const startRange of toArray(startRanges)) {
1109-
this.goToRangeStart(startRange);
1108+
for (const start of toArray<string | Range>(starts)) {
1109+
if (typeof start === "string") {
1110+
this.goToMarker(start);
1111+
}
1112+
else {
1113+
this.goToRangeStart(start);
1114+
}
11101115
const fullActual = ts.map<ts.ReferencedSymbol, ReferenceGroupJson>(this.findReferencesAtCaret(), ({ definition, references }, i) => {
11111116
const text = definition.displayParts.map(d => d.text).join("");
11121117
return {
@@ -4075,8 +4080,8 @@ namespace FourSlashInterface {
40754080
this.state.verifyReferencesOf(start, references);
40764081
}
40774082

4078-
public referenceGroups(startRanges: FourSlash.Range[], parts: ReferenceGroup[]) {
4079-
this.state.verifyReferenceGroups(startRanges, parts);
4083+
public referenceGroups(starts: string | string[] | FourSlash.Range | FourSlash.Range[], parts: ReferenceGroup[]) {
4084+
this.state.verifyReferenceGroups(starts, parts);
40804085
}
40814086

40824087
public noReferences(markerNameOrRange?: string | FourSlash.Range) {

src/services/utilities.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ts {
9292
return SemanticMeaning.All;
9393
}
9494
else if (isInRightSideOfInternalImportEqualsDeclaration(node)) {
95-
return getMeaningFromRightHandSideOfImportEquals(node);
95+
return getMeaningFromRightHandSideOfImportEquals(node as Identifier);
9696
}
9797
else if (isDeclarationName(node)) {
9898
return getMeaningFromDeclaration(node.parent);
@@ -112,19 +112,12 @@ namespace ts {
112112
}
113113
}
114114

115-
function getMeaningFromRightHandSideOfImportEquals(node: Node) {
116-
Debug.assert(node.kind === SyntaxKind.Identifier);
117-
115+
function getMeaningFromRightHandSideOfImportEquals(node: Node): SemanticMeaning {
118116
// import a = |b|; // Namespace
119117
// import a = |b.c|; // Value, type, namespace
120118
// import a = |b.c|.d; // Namespace
121-
122-
if (node.parent.kind === SyntaxKind.QualifiedName &&
123-
(<QualifiedName>node.parent).right === node &&
124-
node.parent.parent.kind === SyntaxKind.ImportEqualsDeclaration) {
125-
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
126-
}
127-
return SemanticMeaning.Namespace;
119+
const name = node.kind === SyntaxKind.QualifiedName ? node : isQualifiedName(node.parent) && node.parent.right === node ? node.parent : undefined;
120+
return name && name.parent.kind === SyntaxKind.ImportEqualsDeclaration ? SemanticMeaning.All : SemanticMeaning.Namespace;
128121
}
129122

130123
export function isInRightSideOfInternalImportEqualsDeclaration(node: Node) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////import j = N./**/ [|q|];
4+
////namespace N { export const [|{| "isWriteAccess": true, "isDefinition": true |}q|] = 0; }
5+
6+
goTo.marker();
7+
verify.referenceGroups("", [{ definition: "const N.q: 0", ranges: test.ranges() }]);

tests/cases/fourslash/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ declare namespace FourSlashInterface {
256256
*/
257257
referencesOf(start: Range, references: Range[]): void;
258258
/**
259-
* For each of startRanges, asserts the ranges that are referenced from there.
259+
* For each of starts, asserts the ranges that are referenced from there.
260260
* This uses the 'findReferences' command instead of 'getReferencesAtPosition', so references are grouped by their definition.
261261
*/
262-
referenceGroups(startRanges: Range | Range[], parts: Array<{ definition: ReferencesDefinition, ranges: Range[] }>): void;
262+
referenceGroups(starts: string | string[] | Range | Range[], parts: Array<{ definition: ReferencesDefinition, ranges: Range[] }>): void;
263263
singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void;
264264
rangesAreOccurrences(isWriteAccess?: boolean): void;
265265
rangesWithSameTextAreRenameLocations(): void;

0 commit comments

Comments
 (0)