Don't crash when observing invalid 'export' in object literal (#40295)

Fixes #32870
This commit is contained in:
Ryan Cavanaugh 2020-09-11 17:18:23 -07:00 committed by GitHub
parent d7cd405bb2
commit ea51fabb7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -204,7 +204,7 @@ namespace ts {
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;
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration | ObjectLiteralExpression;
switch (container.kind) {
case SyntaxKind.ModuleBlock:
case SyntaxKind.SourceFile:
@ -240,6 +240,11 @@ namespace ts {
return [...nodes, container];
}
return nodes;
// Syntactically invalid positions that the parser might produce anyway
case SyntaxKind.ObjectLiteralExpression:
return undefined;
default:
Debug.assertNever(container, "Invalid container kind.");
}

View file

@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />
// @Filename: a.ts
//// const k = {
//// [|export|] f() { }
//// }
verify.documentHighlightsOf(test.ranges()[0], [], { filesToSearch: [test.ranges()[0].fileName] });