diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 5a8ae1a3f4b3e..5215b28a40396 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -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, }; } @@ -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;' diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor.ts b/tests/cases/fourslash/findAllReferencesOfConstructor.ts index a952a2c6ee740..eecf3185ebae9 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor.ts @@ -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|](); diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts index c343df86e7a7f..00ca23cda2785 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts @@ -1,8 +1,8 @@ /// ////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"); diff --git a/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts b/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts index 5a882023c22f6..3d374fefbb435 100644 --- a/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts +++ b/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts @@ -1,5 +1,5 @@ ////export default class { -//// [|[|{| "contextRangeIndex": 0 |}constructor|]() {}|] +//// [|[|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|] ////} verify.singleReferenceGroup("class default", "constructor"); diff --git a/tests/cases/fourslash/findAllRefsOfConstructor.ts b/tests/cases/fourslash/findAllRefsOfConstructor.ts index b5c02e09c03f0..d703126a6354b 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor.ts @@ -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|](""); //// }|] ////} diff --git a/tests/cases/fourslash/findAllRefsOfConstructor2.ts b/tests/cases/fourslash/findAllRefsOfConstructor2.ts index 5c65a098f4fa7..b9d9219693a64 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor2.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor2.ts @@ -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|](); //// }|] ////} diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts b/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts index f768cb1df2655..4d5418f6c7a20 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts @@ -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|] };|] diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts index f89bd730a772a..a8df6c05b3e3c 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts @@ -1,7 +1,7 @@ /// ////class X { -//// [|public [|{| "contextRangeIndex": 0 |}constructor|]() {}|] +//// [|public [|{| "contextRangeIndex": 0, "isDefinition": true |}constructor|]() {}|] ////} ////var x = new [|X|](); diff --git a/tests/cases/fourslash/renameJsExports03.ts b/tests/cases/fourslash/renameJsExports03.ts index d1fafa70c8089..02704eda8c7dc 100644 --- a/tests/cases/fourslash/renameJsExports03.ts +++ b/tests/cases/fourslash/renameJsExports03.ts @@ -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|];|]