Don't crash when observing invalid exports in any kind of container (#59376)

This commit is contained in:
Mateusz Burzyński
2024-07-23 00:58:39 +02:00
committed by GitHub
parent 71fb864138
commit a4ae3c46b6
3 changed files with 17 additions and 6 deletions

View File

@@ -69,7 +69,6 @@ import {
modifierToFlag,
ModuleBlock,
Node,
ObjectLiteralExpression,
ObjectTypeDeclaration,
Program,
ReturnStatement,
@@ -294,7 +293,7 @@ export namespace DocumentHighlights {
function getNodesToSearchForModifier(declaration: Node, modifierFlag: ModifierFlags): readonly Node[] | undefined {
// Types of node whose children might have modifiers.
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration | ObjectLiteralExpression;
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration;
switch (container.kind) {
case SyntaxKind.ModuleBlock:
case SyntaxKind.SourceFile:
@@ -332,11 +331,8 @@ export namespace DocumentHighlights {
return nodes;
// Syntactically invalid positions that the parser might produce anyway
case SyntaxKind.ObjectLiteralExpression:
return undefined;
default:
Debug.assertNever(container, "Invalid container kind.");
return undefined;
}
}

View File

@@ -0,0 +1,7 @@
// === documentHighlights ===
// filesToSearch:
// /tests/cases/fourslash/a.ts
// === /tests/cases/fourslash/a.ts ===
// subTitle:
// /*HIGHLIGHTS*/export const title: string

View File

@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
// @Filename: a.ts
//// subTitle:
//// [|export|] const title: string
verify.baselineDocumentHighlights(test.ranges()[0], { filesToSearch: [test.ranges()[0].fileName] });