From 639f5cb6e5f8ae61eee1ca9828ad14c6ea43ada5 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 13 Jan 2017 08:10:58 -0800 Subject: [PATCH] Fix bug for constructor with modifier --- src/services/findAllReferences.ts | 5 ++--- src/services/utilities.ts | 2 +- .../fourslash/findAllRefsOfConstructor_withModifier.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index d6092644c73..287c16d5e7e 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -502,9 +502,8 @@ namespace ts.FindAllReferences { const result: Node[] = []; for (const decl of classSymbol.members["__constructor"].declarations) { - Debug.assert(decl.kind === SyntaxKind.Constructor); - const ctrKeyword = decl.getChildAt(0); - Debug.assert(ctrKeyword.kind === SyntaxKind.ConstructorKeyword); + const ctrKeyword = ts.findChildOfKind(decl, ts.SyntaxKind.ConstructorKeyword, sourceFile)! + Debug.assert(decl.kind === SyntaxKind.Constructor && !!ctrKeyword); result.push(ctrKeyword); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 47608a59e75..def7ab8e4bd 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -600,7 +600,7 @@ namespace ts { return !!findChildOfKind(n, kind, sourceFile); } - export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node { + export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node | undefined { return forEach(n.getChildren(sourceFile), c => c.kind === kind && c); } diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts new file mode 100644 index 00000000000..0954945a546 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts @@ -0,0 +1,10 @@ +/// + +////class X { +//// public [|constructor|]() {} +////} +////var x = new [|X|](); + +const ranges = test.ranges(); +const ctr = ranges[0]; +verify.referencesOf(ctr, ranges);