Bug 1101265 - Simplify parsing empty arrow function parameter. r=Waldo

This commit is contained in:
Tooru Fujisawa 2014-12-13 15:51:12 +09:00
parent fec35502e3
commit 3b04a893ea
2 changed files with 32 additions and 21 deletions

View File

@ -8109,8 +8109,30 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
case TOK_LET:
return letBlock(LetExpression);
case TOK_LP:
return parenExprOrGeneratorComprehension();
case TOK_LP: {
TokenKind next;
if (!tokenStream.peekToken(&next, TokenStream::Operand))
return null();
if (next != TOK_RP)
return parenExprOrGeneratorComprehension();
// Not valid expression syntax, but this is valid in an arrow function
// with no params: `() => body`.
tokenStream.consumeKnownToken(next);
if (!tokenStream.peekToken(&next))
return null();
if (next != TOK_ARROW) {
report(ParseError, false, null(), JSMSG_UNEXPECTED_TOKEN,
"expression", TokenKindToDesc(TOK_RP));
return null();
}
// Now just return something that will allow parsing to continue.
// It doesn't matter what; when we reach the =>, we will rewind and
// reparse the whole arrow function. See Parser::assignExpr.
return handler.newNullLiteral(pos());
}
case TOK_TEMPLATE_HEAD:
return templateLiteral();
@ -8143,24 +8165,6 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
case TOK_NULL:
return handler.newNullLiteral(pos());
case TOK_RP: {
TokenKind next;
if (!tokenStream.peekToken(&next))
return null();
// Not valid expression syntax, but this is valid in an arrow function
// with no params: `() => body`.
if (next == TOK_ARROW) {
tokenStream.ungetToken(); // put back right paren
// Now just return something that will allow parsing to continue.
// It doesn't matter what; when we reach the =>, we will rewind and
// reparse the whole arrow function. See Parser::assignExpr.
return handler.newNullLiteral(pos());
}
goto unexpected_token;
}
case TOK_TRIPLEDOT: {
TokenKind next;
@ -8199,7 +8203,6 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
}
default:
unexpected_token:
report(ParseError, false, null(), JSMSG_UNEXPECTED_TOKEN,
"expression", TokenKindToDesc(tt));
return null();

View File

@ -0,0 +1,8 @@
var caught = false;
try {
eval("1\n)=>");
} catch (e) {
assertEq(e instanceof SyntaxError, true);
caught = true;
}
assertEq(caught, true);