Skip to content

Commit 6617819

Browse files
author
Andy
authored
In getModifierOccurrences, support additional container kinds (microsoft#18947)
1 parent fe9129b commit 6617819

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/services/documentHighlights.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,15 @@ namespace ts.DocumentHighlights {
302302
switch (container.kind) {
303303
case SyntaxKind.ModuleBlock:
304304
case SyntaxKind.SourceFile:
305+
case SyntaxKind.Block:
306+
case SyntaxKind.CaseClause:
307+
case SyntaxKind.DefaultClause:
305308
// Container is either a class declaration or the declaration is a classDeclaration
306309
if (modifierFlag & ModifierFlags.Abstract) {
307310
nodes = [...(<ClassDeclaration>declaration).members, declaration];
308311
}
309312
else {
310-
nodes = (<Block>container).statements;
313+
nodes = (<ModuleBlock | SourceFile | Block | CaseClause | DefaultClause>container).statements;
311314
}
312315
break;
313316
case SyntaxKind.Constructor:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Tests that we don't crash when encountering an abstract class in these scopes:
4+
5+
////function f() {
6+
//// [|abstract|] class A {
7+
//// [|abstract|] m(): void;
8+
//// }
9+
//// abstract class B {}
10+
////}
11+
////switch (0) {
12+
//// case 0:
13+
//// [|abstract|] class A { [|abstract|] m(): void; }
14+
//// default:
15+
//// [|abstract|] class B { [|abstract|] m(): void; }
16+
////}
17+
18+
const [r0, r1, r2, r3, r4, r5] = test.ranges();
19+
verify.rangesAreDocumentHighlights([r0, r1]);
20+
verify.rangesAreDocumentHighlights([r2, r3]);
21+
verify.rangesAreDocumentHighlights([r4, r5]);

0 commit comments

Comments
 (0)