Skip to content

Commit a4ae3c4

Browse files
authored
Don't crash when observing invalid exports in any kind of container (#59376)
1 parent 71fb864 commit a4ae3c4

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/services/documentHighlights.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import {
6969
modifierToFlag,
7070
ModuleBlock,
7171
Node,
72-
ObjectLiteralExpression,
7372
ObjectTypeDeclaration,
7473
Program,
7574
ReturnStatement,
@@ -294,7 +293,7 @@ export namespace DocumentHighlights {
294293

295294
function getNodesToSearchForModifier(declaration: Node, modifierFlag: ModifierFlags): readonly Node[] | undefined {
296295
// Types of node whose children might have modifiers.
297-
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration | ObjectLiteralExpression;
296+
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration;
298297
switch (container.kind) {
299298
case SyntaxKind.ModuleBlock:
300299
case SyntaxKind.SourceFile:
@@ -332,11 +331,8 @@ export namespace DocumentHighlights {
332331
return nodes;
333332

334333
// Syntactically invalid positions that the parser might produce anyway
335-
case SyntaxKind.ObjectLiteralExpression:
336-
return undefined;
337-
338334
default:
339-
Debug.assertNever(container, "Invalid container kind.");
335+
return undefined;
340336
}
341337
}
342338

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// === documentHighlights ===
2+
// filesToSearch:
3+
// /tests/cases/fourslash/a.ts
4+
5+
// === /tests/cases/fourslash/a.ts ===
6+
// subTitle:
7+
// /*HIGHLIGHTS*/export const title: string
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: a.ts
4+
//// subTitle:
5+
//// [|export|] const title: string
6+
7+
verify.baselineDocumentHighlights(test.ranges()[0], { filesToSearch: [test.ranges()[0].fileName] });
8+

0 commit comments

Comments
 (0)