1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

LibJS: Use ScopePusher to correctly push the scope in for statements

We were previously pushing a scope but forgetting to actually set it as
the current scope.
This commit is contained in:
Ali Mohammad Pur 2021-09-16 22:09:28 +04:30 committed by Andreas Kling
parent 63a0ebcc90
commit c7a99aafac

View file

@ -2687,19 +2687,13 @@ NonnullRefPtr<Statement> Parser::parse_for_statement()
consume(TokenType::ParenOpen);
bool in_scope = false;
ScopeGuard guard([&]() {
if (in_scope)
m_state.let_scopes.take_last();
});
Optional<ScopePusher> scope_pusher;
RefPtr<ASTNode> init;
if (!match(TokenType::Semicolon)) {
if (match_variable_declaration()) {
if (!match(TokenType::Var)) {
m_state.let_scopes.append(NonnullRefPtrVector<VariableDeclaration>());
in_scope = true;
}
if (!match(TokenType::Var))
scope_pusher.emplace(*this, ScopePusher::Let, Scope::Block);
init = parse_variable_declaration(true);
if (match_for_in_of())
return parse_for_in_of_statement(*init);