Skip to content

Commit 94e8db7

Browse files
a-tarasyukDanielRosenwasser
authored andcommitted
fix(35043): TS Server: references does not mark isDefinition o… (#36051)
1 parent ce4c4b6 commit 94e8db7

9 files changed

+22
-17
lines changed

src/services/findAllReferences.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ namespace ts.FindAllReferences {
337337
return {
338338
...documentSpan,
339339
isWriteAccess: isWriteAccessForReference(node),
340-
isDefinition: node.kind === SyntaxKind.DefaultKeyword
341-
|| !!getDeclarationFromName(node)
342-
|| isLiteralComputedPropertyDeclarationName(node),
340+
isDefinition: isDefinitionForReference(node),
343341
isInString: kind === EntryKind.StringLiteral ? true : undefined,
344342
};
345343
}
@@ -470,6 +468,13 @@ namespace ts.FindAllReferences {
470468
return !!decl && declarationIsWriteAccess(decl) || node.kind === SyntaxKind.DefaultKeyword || isWriteAccess(node);
471469
}
472470

471+
function isDefinitionForReference(node: Node): boolean {
472+
return node.kind === SyntaxKind.DefaultKeyword
473+
|| !!getDeclarationFromName(node)
474+
|| isLiteralComputedPropertyDeclarationName(node)
475+
|| (node.kind === SyntaxKind.ConstructorKeyword && isConstructorDeclaration(node.parent));
476+
}
477+
473478
/**
474479
* True if 'decl' provides a value, as in `function f() {}`;
475480
* false if 'decl' is just a location for a future write, as in 'let x;'

tests/cases/fourslash/findAllReferencesOfConstructor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// @Filename: a.ts
44
////export class C {
5-
//// [|[|{| "contextRangeIndex": 0 |}constructor|](n: number);|]
6-
//// [|[|{| "contextRangeIndex": 2 |}constructor|]();|]
7-
//// [|[|{| "contextRangeIndex": 4 |}constructor|](n?: number){}|]
5+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](n: number);|]
6+
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]();|]
7+
//// [|[|{| "contextRangeIndex": 4, "isDefinition": true |}constructor|](n?: number){}|]
88
//// static f() {
99
//// this.f();
1010
//// new [|this|]();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// <reference path="fourslash.ts" />
22

33
////class C {
4-
//// [|[|{| "contextRangeIndex": 0 |}constructor|](n: number);|]
5-
//// [|[|{| "contextRangeIndex": 2 |}constructor|](){}|]
4+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](n: number);|]
5+
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|](){}|]
66
////}
77

88
verify.singleReferenceGroup("class C", "constructor");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
////export default class {
2-
//// [|[|{| "contextRangeIndex": 0 |}constructor|]() {}|]
2+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|]
33
////}
44

55
verify.singleReferenceGroup("class default", "constructor");

tests/cases/fourslash/findAllRefsOfConstructor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33

44
////class A {
5-
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
5+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
66
////}
77
////class B extends A { }
88
////class C extends B {
9-
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() {
9+
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() {
1010
//// [|super|]("");
1111
//// }|]
1212
////}

tests/cases/fourslash/findAllRefsOfConstructor2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33

44
////class A {
5-
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
5+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
66
////}
77
////class B extends A {
8-
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() { [|super|](""); }|]
8+
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() { [|super|](""); }|]
99
////}
1010
////class C extends B {
11-
//// [|[|{| "contextRangeIndex": 5 |}constructor|]() {
11+
//// [|[|{| "contextRangeIndex": 5, "isDefinition": true |}constructor|]() {
1212
//// [|super|]();
1313
//// }|]
1414
////}

tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @Filename: f.ts
44

55
////class A {
6-
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
6+
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
77
////}
88
////class B extends A { }
99
////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}A|], [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}B|] };|]

tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="fourslash.ts" />
22

33
////class X {
4-
//// [|public [|{| "contextRangeIndex": 0 |}constructor|]() {}|]
4+
//// [|public [|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|]
55
////}
66
////var x = new [|X|]();
77

tests/cases/fourslash/renameJsExports03.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @allowJs: true
44
// @Filename: a.js
55
////[|class [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}A|] {
6-
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() { }|]
6+
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() { }|]
77
////}|]
88
////[|module.exports = [|{| "contextRangeIndex": 4 |}A|];|]
99

0 commit comments

Comments
 (0)