1337143 - Tweak the parser to eliminate two complexifying peekTokens where getToken could be used.

master
Fedor 2019-09-05 20:05:57 +03:00
parent df9455157d
commit c979d57203
1 changed files with 30 additions and 17 deletions

View File

@ -4663,12 +4663,11 @@ bool
Parser<FullParseHandler>::namedImportsOrNamespaceImport(TokenKind tt, Node importSpecSet)
{
if (tt == TOK_LC) {
TokenStream::Modifier modifier = TokenStream::KeywordIsName;
while (true) {
// Handle the forms |import {} from 'a'| and
// |import { ..., } from 'a'| (where ... is non empty), by
// escaping the loop early if the next token is }.
if (!tokenStream.peekToken(&tt, TokenStream::KeywordIsName))
if (!tokenStream.getToken(&tt, TokenStream::KeywordIsName))
return false;
if (tt == TOK_RC)
@ -4677,7 +4676,11 @@ Parser<FullParseHandler>::namedImportsOrNamespaceImport(TokenKind tt, Node impor
// If the next token is a keyword, the previous call to
// peekToken matched it as a TOK_NAME, and put it in the
// lookahead buffer, so this call will match keywords as well.
MUST_MATCH_TOKEN_MOD(TOK_NAME, TokenStream::KeywordIsName, JSMSG_NO_IMPORT_NAME);
if (tt != TOK_NAME) {
error(JSMSG_NO_IMPORT_NAME);
return false;
}
Rooted<PropertyName*> importName(context, tokenStream.currentName());
TokenPos importNamePos = pos();
@ -4735,17 +4738,18 @@ Parser<FullParseHandler>::namedImportsOrNamespaceImport(TokenKind tt, Node impor
handler.addList(importSpecSet, importSpec);
bool matched;
if (!tokenStream.matchToken(&matched, TOK_COMMA))
TokenKind next;
if (!tokenStream.getToken(&next))
return false;
if (!matched) {
modifier = TokenStream::None;
if (next == TOK_RC)
break;
if (next != TOK_COMMA) {
error(JSMSG_RC_AFTER_IMPORT_SPEC_LIST);
return false;
}
}
MUST_MATCH_TOKEN_MOD(TOK_RC, modifier, JSMSG_RC_AFTER_IMPORT_SPEC_LIST);
} else {
MOZ_ASSERT(tt == TOK_MUL);
if (!tokenStream.getToken(&tt))
@ -4986,12 +4990,17 @@ Parser<FullParseHandler>::exportDeclaration()
// Handle the forms |export {}| and |export { ..., }| (where ...
// is non empty), by escaping the loop early if the next token
// is }.
if (!tokenStream.peekToken(&tt))
if (!tokenStream.getToken(&tt))
return null();
if (tt == TOK_RC)
break;
MUST_MATCH_TOKEN(TOK_NAME, JSMSG_NO_BINDING_NAME);
if (tt != TOK_NAME) {
error(JSMSG_NO_BINDING_NAME);
return null();
}
Node bindingName = newName(tokenStream.currentName());
if (!bindingName)
return null();
@ -5015,14 +5024,18 @@ Parser<FullParseHandler>::exportDeclaration()
handler.addList(kid, exportSpec);
bool matched;
if (!tokenStream.matchToken(&matched, TOK_COMMA))
TokenKind next;
if (!tokenStream.getToken(&next))
return null();
if (!matched)
break;
}
MUST_MATCH_TOKEN(TOK_RC, JSMSG_RC_AFTER_EXPORT_SPEC_LIST);
if (next == TOK_RC)
break;
if (next != TOK_COMMA) {
error(JSMSG_RC_AFTER_EXPORT_SPEC_LIST);
return null();
}
}
// Careful! If |from| follows, even on a new line, it must start a
// FromClause: