Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Unified Diff: src/preparser.h

Issue 987203003: [parser] parse arrow function only if no linefeed before => (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove extra newline between functions Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 1b9af9e732600c75d36b9f3e14d8919e0f3e7bae..be03c76928d04aa15b92dd919a97a35ffc96f50d 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -538,6 +538,7 @@ class ParserBase : public Traits {
}
void ReportUnexpectedToken(Token::Value token);
+ void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token);
// Recursive descent functions:
@@ -1681,7 +1682,13 @@ ParserBase<Traits>::FunctionState::~FunctionState() {
template<class Traits>
void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
- Scanner::Location source_location = scanner()->location();
+ return ReportUnexpectedTokenAt(scanner_->location(), token);
+}
+
+
+template<class Traits>
+void ParserBase<Traits>::ReportUnexpectedTokenAt(
+ Scanner::Location source_location, Token::Value token) {
// Four of the tokens are treated specially
switch (token) {
@@ -2846,6 +2853,15 @@ typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
ExpressionT params_ast,
bool* ok) {
+ if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
+ // ASI inserts `;` after arrow parameters if a line terminator is found.
+ // `=> ...` is never a valid expression, so report as syntax error.
+ // If next token is not `=>`, it's a syntax error anyways.
+ ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
+ *ok = false;
+ return this->EmptyExpression();
+ }
+
Scope* scope = this->NewScope(scope_, ARROW_SCOPE);
typename Traits::Type::StatementList body;
int num_parameters = -1;
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698