Skip to content

Commit

Permalink
Don't crash when observing invalid 'export' in object literal (#40295)
Browse files Browse the repository at this point in the history
Fixes #32870
  • Loading branch information
RyanCavanaugh committed Sep 12, 2020
1 parent d7cd405 commit ea51fab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/services/documentHighlights.ts
Expand Up @@ -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:
Expand Down Expand Up @@ -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.");
}
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/exportInObjectLiteral.ts
@@ -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] });

0 comments on commit ea51fab

Please sign in to comment.