Commit 94bf354a authored by vabr's avatar vabr Committed by Commit bot

Raise SyntaxError on let [ starting an ExpressionStatement

ES2017 forbids the sequence of tokens "let [" in in expression statements [1].

This CL makes ParserBase report those instances as SyntaxError. It also adds a
customised error message for that, because the standard "Unexpected token" is
not applicable: "let" itself is not forbidden in those context, only the
sequence of "let [".

[1] https://tc39.github.io/ecma262/#sec-expression-statement

BUG=v8:5686

Review-Url: https://codereview.chromium.org/2694003002
Cr-Commit-Position: refs/heads/master@{#43258}
parent b593f1a5
......@@ -640,6 +640,8 @@ class ErrorUtils : public AllStatic {
T(UnexpectedTokenNumber, "Unexpected number") \
T(UnexpectedTokenString, "Unexpected string") \
T(UnexpectedTokenRegExp, "Unexpected regular expression") \
T(UnexpectedLexicalDeclaration, \
"Lexical declaration cannot appear in a single-statement context") \
T(UnknownLabel, "Undefined label '%'") \
T(UnresolvableExport, \
"The requested module does not provide an export named '%'") \
......
......@@ -4935,6 +4935,12 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
ReportUnexpectedToken(Next());
*ok = false;
return impl()->NullStatement();
case Token::LET:
if (PeekAhead() != Token::LBRACK) break;
impl()->ReportMessageAt(scanner()->peek_location(),
MessageTemplate::kUnexpectedLexicalDeclaration);
*ok = false;
return impl()->NullStatement();
default:
break;
}
......
// Copyright 2017 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.
with ({}) let [a] = [];
*%(basename)s:5: SyntaxError: Lexical declaration cannot appear in a single-statement context
with ({}) let [a] = [];
^^^
SyntaxError: Lexical declaration cannot appear in a single-statement context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment