diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 315cbf2684..7512b02d18 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -3277,7 +3277,13 @@ ParserBase::ParseLeftHandSideContinuation(ExpressionT result) { if (is_optional) { DCHECK_EQ(scanner()->current_token(), Token::QUESTION_PERIOD); int pos = position(); - ExpressionT key = ParsePropertyOrPrivatePropertyName(); + Token::Value next = Next(); + if (V8_UNLIKELY(!Token::IsPropertyName(next))) { + ReportUnexpectedToken(next); + return impl()->FailureExpression(); + } + IdentifierT name = impl()->GetSymbol(); + ExpressionT key = factory()->NewStringLiteral(name, position()); result = factory()->NewProperty(result, key, pos, is_optional); break; } diff --git a/test/mjsunit/harmony/optional-chaining.js b/test/mjsunit/harmony/optional-chaining.js index 72b0559e00..a6121f5fcb 100644 --- a/test/mjsunit/harmony/optional-chaining.js +++ b/test/mjsunit/harmony/optional-chaining.js @@ -101,6 +101,7 @@ shouldThrowSyntaxError('function foo() { new?.target; }'); shouldThrowSyntaxError('function tag() {} tag?.``;'); shouldThrowSyntaxError('const o = { tag() {} }; o?.tag``;'); +shouldThrowSyntaxError('class A { #foo = "hi"; constructor() { this?.#foo; } }') const o2 = { count: 0,