diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index 6ed27e2bee..b0282393cc 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -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."); } diff --git a/tests/cases/fourslash/exportInObjectLiteral.ts b/tests/cases/fourslash/exportInObjectLiteral.ts new file mode 100644 index 0000000000..9d95ff5ff5 --- /dev/null +++ b/tests/cases/fourslash/exportInObjectLiteral.ts @@ -0,0 +1,9 @@ +/// + +// @Filename: a.ts +//// const k = { +//// [|export|] f() { } +//// } + +verify.documentHighlightsOf(test.ranges()[0], [], { filesToSearch: [test.ranges()[0].fileName] }); +