Better error reporting for "return();"
R=rossberg@chromium.org BUG=v8:4194 LOG=N Review URL: https://codereview.chromium.org/1191303002 Cr-Commit-Position: refs/heads/master@{#29153}
This commit is contained in:
parent
8076d6ee2d
commit
d940c02724
@ -323,6 +323,8 @@ class CallSite {
|
||||
T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
|
||||
T(MalformedRegExp, "Invalid regular expression: /%/: %") \
|
||||
T(MalformedRegExpFlags, "Invalid regular expression flags") \
|
||||
T(MissingArrow, \
|
||||
"Expected () to start arrow function, but got '%' instead of '=>'") \
|
||||
T(ModuleExportUndefined, "Export '%' is not defined in module") \
|
||||
T(MultipleDefaultsInSwitch, \
|
||||
"More than one default clause in switch statement") \
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2152,6 +2153,13 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
|
||||
classifier->RecordBindingPatternError(scanner()->location(),
|
||||
MessageTemplate::kUnexpectedToken,
|
||||
Token::String(Token::RPAREN));
|
||||
// Give a good error to the user who might have typed e.g. "return();".
|
||||
if (peek() != Token::ARROW) {
|
||||
ReportUnexpectedTokenAt(scanner_->peek_location(), peek(),
|
||||
MessageTemplate::kMissingArrow);
|
||||
*ok = false;
|
||||
return this->EmptyExpression();
|
||||
}
|
||||
Scope* scope =
|
||||
this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
|
||||
scope->set_start_position(beg_pos);
|
||||
|
7
test/message/arrow-missing.js
Normal file
7
test/message/arrow-missing.js
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright 2015 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.
|
||||
//
|
||||
// Flags: --harmony-rest-parameters --harmony-arrow-functions
|
||||
|
||||
function foo() { return(); }
|
4
test/message/arrow-missing.out
Normal file
4
test/message/arrow-missing.out
Normal file
@ -0,0 +1,4 @@
|
||||
*%(basename)s:7: SyntaxError: Expected () to start arrow function, but got ';' instead of '=>'
|
||||
function foo() { return(); }
|
||||
^
|
||||
SyntaxError: Expected () to start arrow function, but got ';' instead of '=>'
|
Loading…
Reference in New Issue
Block a user