| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index 862b7fb40dd894b53dfcec80d36aedde5b441e3f..238fb89ac8c9b6a9afece0a03c638fa3ce064e07 100644
|
| --- a/src/preparser.h
|
| +++ b/src/preparser.h
|
| @@ -502,7 +502,9 @@ class ParserBase : public Traits {
|
| }
|
|
|
| void ReportUnexpectedToken(Token::Value token);
|
| - void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token);
|
| + void ReportUnexpectedTokenAt(
|
| + Scanner::Location location, Token::Value token,
|
| + MessageTemplate::Template message = MessageTemplate::kUnexpectedToken);
|
|
|
|
|
| void ReportClassifierError(const ExpressionClassifier::Error& error) {
|
| @@ -1814,10 +1816,10 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
|
| }
|
|
|
|
|
| -template<class Traits>
|
| +template <class Traits>
|
| void ParserBase<Traits>::ReportUnexpectedTokenAt(
|
| - Scanner::Location source_location, Token::Value token) {
|
| -
|
| + Scanner::Location source_location, Token::Value token,
|
| + MessageTemplate::Template message) {
|
| // Four of the tokens are treated specially
|
| switch (token) {
|
| case Token::EOS:
|
| @@ -1850,8 +1852,7 @@ void ParserBase<Traits>::ReportUnexpectedTokenAt(
|
| default:
|
| const char* name = Token::String(token);
|
| DCHECK(name != NULL);
|
| - Traits::ReportMessageAt(source_location,
|
| - MessageTemplate::kUnexpectedToken, name);
|
| + Traits::ReportMessageAt(source_location, message, name);
|
| }
|
| }
|
|
|
| @@ -3610,7 +3611,17 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
|
| FunctionState function_state(&function_state_, &scope_, scope,
|
| kArrowFunction, &function_factory);
|
|
|
| - Expect(Token::ARROW, CHECK_OK);
|
| + // ParseArrowFunctionLiteral can be called in two ways: after seeing a
|
| + // formal parameter list that *must* be followed by an arrow, to wit "()" or
|
| + // "(...x)", or after reading a comma expression that is followed by =>. In
|
| + // the former cases we want to give a good error to the user who might have
|
| + // typed e.g. "return();".
|
| + if (!Check(Token::ARROW)) {
|
| + ReportUnexpectedTokenAt(scanner_->peek_location(), peek(),
|
| + MessageTemplate::kMissingArrow);
|
| + *ok = false;
|
| + return this->EmptyExpression();
|
| + }
|
|
|
| if (peek() == Token::LBRACE) {
|
| // Multiple statement body
|
|
|