[parser] Parenthesized identifiers are invalid as part of a declaration

Bug: v8:8659
Change-Id: I7208589dcb5c40dd915a50517f83f3da646202be
Reviewed-on: https://chromium-review.googlesource.com/c/1402547
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58657}
This commit is contained in:
Toon Verwaest 2019-01-09 11:20:00 +01:00 committed by Commit Bot
parent c26b4977d6
commit 5b4d4c2401
2 changed files with 10 additions and 0 deletions

View File

@ -4320,6 +4320,11 @@ ParserBase<Impl>::ParsePossibleDestructuringSubPattern(
// themselves are not allowed, e.g., "[(x)] = []". Only accumulate
// assignment pattern errors if the parsed expression is more complex.
if (impl()->IsIdentifier(result)) {
if (result->is_parenthesized()) {
expression_scope()->RecordDeclarationError(
Scanner::Location(begin, end_position()),
MessageTemplate::kInvalidDestructuringTarget);
}
IdentifierT identifier = impl()->AsIdentifier(result);
ClassifyParameter(identifier, begin, end_position());
if (impl()->IsLet(identifier)) {

View File

@ -0,0 +1,5 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertThrows("const [(x)] = []", SyntaxError);