Reviewers: arv, marja,
Message:
PTAL --- much tinier fixup for arrow fns this time =)
I'm not totally sure about the `( (a) \n => a )` case, to me it feels like
the
surrounding parentheses should prevent ASI. But the spec seems to argue that
that doesn't happen
Description:
[parser] parse arrow function only if no linefeed before =>
BUG=v8:3954
LOG=N
[email protected], [email protected]
Please review this at https://codereview.chromium.org/987203003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+36, -1 lines):
M src/preparser.h
M test/cctest/test-parsing.cc
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
1b9af9e732600c75d36b9f3e14d8919e0f3e7bae..7d9fef2a275c4d599889b475dd2bc8c777fd8c89
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:
@@ -1679,9 +1680,16 @@ 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 +2854,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;
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
f27cd34e6c3c3e89f8ad7240f6cc2da547ecaf65..12e1fe907ed558ad1564bf92f081521530e9ff84
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -5564,3 +5564,21 @@ TEST(StrongForIn) {
RunParserSyncTest(strong_context_data, data, kError, NULL, 0,
always_flags,
arraysize(always_flags));
}
+
+
+TEST(ArrowFunctionASIErrors) {
+ const char* context_data[][2] = {{"'use strict';", ""}, {"", ""},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "(a\n=> a)(1)",
+ "(a/*\n*/=> a)(1)",
+ "((a)\n=> a)(1)",
+ "((a)/*\n*/=> a)(1)",
+ "((a, b)\n=> a + b)(1, 2)",
+ "((a, b)/*\n*/=> a + b)(1, 2)",
+ NULL};
+ static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.