In getModifierOccurrences, support additional container kinds (#18947)

This commit is contained in:
Andy 2017-10-04 09:52:51 -07:00 committed by GitHub
parent fe9129b1ab
commit 6617819bf3
2 changed files with 25 additions and 1 deletions

View File

@ -302,12 +302,15 @@ namespace ts.DocumentHighlights {
switch (container.kind) {
case SyntaxKind.ModuleBlock:
case SyntaxKind.SourceFile:
case SyntaxKind.Block:
case SyntaxKind.CaseClause:
case SyntaxKind.DefaultClause:
// Container is either a class declaration or the declaration is a classDeclaration
if (modifierFlag & ModifierFlags.Abstract) {
nodes = [...(<ClassDeclaration>declaration).members, declaration];
}
else {
nodes = (<Block>container).statements;
nodes = (<ModuleBlock | SourceFile | Block | CaseClause | DefaultClause>container).statements;
}
break;
case SyntaxKind.Constructor:

View File

@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
// Tests that we don't crash when encountering an abstract class in these scopes:
////function f() {
//// [|abstract|] class A {
//// [|abstract|] m(): void;
//// }
//// abstract class B {}
////}
////switch (0) {
//// case 0:
//// [|abstract|] class A { [|abstract|] m(): void; }
//// default:
//// [|abstract|] class B { [|abstract|] m(): void; }
////}
const [r0, r1, r2, r3, r4, r5] = test.ranges();
verify.rangesAreDocumentHighlights([r0, r1]);
verify.rangesAreDocumentHighlights([r2, r3]);
verify.rangesAreDocumentHighlights([r4, r5]);