Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ namespace ts.FindAllReferences {
return {
...documentSpan,
isWriteAccess: isWriteAccessForReference(node),
isDefinition: node.kind === SyntaxKind.DefaultKeyword
|| !!getDeclarationFromName(node)
|| isLiteralComputedPropertyDeclarationName(node),
isDefinition: isDefinitionForReference(node),
isInString: kind === EntryKind.StringLiteral ? true : undefined,
};
}
Expand Down Expand Up @@ -470,6 +468,13 @@ namespace ts.FindAllReferences {
return !!decl && declarationIsWriteAccess(decl) || node.kind === SyntaxKind.DefaultKeyword || isWriteAccess(node);
}

function isDefinitionForReference(node: Node): boolean {
return node.kind === SyntaxKind.DefaultKeyword
|| !!getDeclarationFromName(node)
|| isLiteralComputedPropertyDeclarationName(node)
|| (node.kind === SyntaxKind.ConstructorKeyword && isConstructorDeclaration(node.parent));
}

/**
* True if 'decl' provides a value, as in `function f() {}`;
* false if 'decl' is just a location for a future write, as in 'let x;'
Expand Down
6 changes: 3 additions & 3 deletions tests/cases/fourslash/findAllReferencesOfConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

// @Filename: a.ts
////export class C {
//// [|[|{| "contextRangeIndex": 0 |}constructor|](n: number);|]
//// [|[|{| "contextRangeIndex": 2 |}constructor|]();|]
//// [|[|{| "contextRangeIndex": 4 |}constructor|](n?: number){}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](n: number);|]
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]();|]
//// [|[|{| "contextRangeIndex": 4, "isDefinition": true |}constructor|](n?: number){}|]
//// static f() {
//// this.f();
//// new [|this|]();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference path="fourslash.ts" />

////class C {
//// [|[|{| "contextRangeIndex": 0 |}constructor|](n: number);|]
//// [|[|{| "contextRangeIndex": 2 |}constructor|](){}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](n: number);|]
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|](){}|]
////}

verify.singleReferenceGroup("class C", "constructor");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////export default class {
//// [|[|{| "contextRangeIndex": 0 |}constructor|]() {}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|]
////}

verify.singleReferenceGroup("class default", "constructor");
4 changes: 2 additions & 2 deletions tests/cases/fourslash/findAllRefsOfConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


////class A {
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
////}
////class B extends A { }
////class C extends B {
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() {
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() {
//// [|super|]("");
//// }|]
////}
Expand Down
6 changes: 3 additions & 3 deletions tests/cases/fourslash/findAllRefsOfConstructor2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


////class A {
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
////}
////class B extends A {
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() { [|super|](""); }|]
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() { [|super|](""); }|]
////}
////class C extends B {
//// [|[|{| "contextRangeIndex": 5 |}constructor|]() {
//// [|[|{| "contextRangeIndex": 5, "isDefinition": true |}constructor|]() {
//// [|super|]();
//// }|]
////}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @Filename: f.ts

////class A {
//// [|[|{| "contextRangeIndex": 0 |}constructor|](s: string) {}|]
//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|](s: string) {}|]
////}
////class B extends A { }
////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}A|], [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}B|] };|]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="fourslash.ts" />

////class X {
//// [|public [|{| "contextRangeIndex": 0 |}constructor|]() {}|]
//// [|public [|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|]
////}
////var x = new [|X|]();

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/fourslash/renameJsExports03.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @allowJs: true
// @Filename: a.js
////[|class [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}A|] {
//// [|[|{| "contextRangeIndex": 2 |}constructor|]() { }|]
//// [|[|{| "contextRangeIndex": 2, "isDefinition": true |}constructor|]() { }|]
////}|]
////[|module.exports = [|{| "contextRangeIndex": 4 |}A|];|]

Expand Down