diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index c55dfb785a5c..4c4eaa37977f 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -6424,6 +6424,18 @@ Parser::peekShouldParseLetDeclaration(bool* parseDeclOut, return true; } +template +typename ParseHandler::Node +Parser::variableStatement(YieldHandling yieldHandling) +{ + Node vars = declarationList(yieldHandling, PNK_VAR); + if (!vars) + return null(); + if (!MatchOrInsertSemicolonAfterExpression(tokenStream)) + return null(); + return vars; +} + template typename ParseHandler::Node Parser::statement(YieldHandling yieldHandling, bool canHaveDirectives) @@ -6442,14 +6454,8 @@ Parser::statement(YieldHandling yieldHandling, bool canHaveDirecti return blockStatement(yieldHandling); // VariableStatement[?Yield] - case TOK_VAR: { - Node pn = declarationList(yieldHandling, PNK_VAR); - if (!pn) - return null(); - if (!MatchOrInsertSemicolonAfterExpression(tokenStream)) - return null(); - return pn; - } + case TOK_VAR: + return variableStatement(yieldHandling); // EmptyStatement case TOK_SEMI: diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index b55b635e3cd6..69a3687b163f 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -1046,6 +1046,8 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter Node catchBlockStatement(YieldHandling yieldHandling, HandlePropertyName simpleCatchParam); Node debuggerStatement(); + Node variableStatement(YieldHandling yieldHandling); + Node lexicalDeclaration(YieldHandling yieldHandling, bool isConst); Node importDeclaration(); Node exportDeclaration();