Skip to content

Commit ea51fab

Browse files
Don't crash when observing invalid 'export' in object literal (microsoft#40295)
Fixes microsoft#32870
1 parent d7cd405 commit ea51fab

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/services/documentHighlights.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ namespace ts {
204204

205205
function getNodesToSearchForModifier(declaration: Node, modifierFlag: ModifierFlags): readonly Node[] | undefined {
206206
// Types of node whose children might have modifiers.
207-
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration;
207+
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration | ObjectLiteralExpression;
208208
switch (container.kind) {
209209
case SyntaxKind.ModuleBlock:
210210
case SyntaxKind.SourceFile:
@@ -240,6 +240,11 @@ namespace ts {
240240
return [...nodes, container];
241241
}
242242
return nodes;
243+
244+
// Syntactically invalid positions that the parser might produce anyway
245+
case SyntaxKind.ObjectLiteralExpression:
246+
return undefined;
247+
243248
default:
244249
Debug.assertNever(container, "Invalid container kind.");
245250
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: a.ts
4+
//// const k = {
5+
//// [|export|] f() { }
6+
//// }
7+
8+
verify.documentHighlightsOf(test.ranges()[0], [], { filesToSearch: [test.ranges()[0].fileName] });
9+

0 commit comments

Comments
 (0)