Commit 84bad8ec authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Minor simplification to for in/of scope handling

Always pass in the target scope for the body, and check whether we're in
LexicalVariableMode instead to distinguish for(let/const from for(var.

Change-Id: Idf59423466f45eebe7c9d716f8eb6ccd92235abc
Reviewed-on: https://chromium-review.googlesource.com/c/1388534Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58445}
parent ee0eb614
...@@ -5411,7 +5411,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( ...@@ -5411,7 +5411,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
if (CheckInOrOf(&for_info.mode)) { if (CheckInOrOf(&for_info.mode)) {
return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels, return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels,
own_labels, nullptr); own_labels, scope());
} }
init = impl()->BuildInitializationBlock(&for_info.parsing_result, nullptr); init = impl()->BuildInitializationBlock(&for_info.parsing_result, nullptr);
...@@ -5506,18 +5506,14 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations( ...@@ -5506,18 +5506,14 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations(
Expect(Token::RPAREN); Expect(Token::RPAREN);
Scope* for_scope = nullptr; if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
if (inner_block_scope != nullptr) { inner_block_scope->set_start_position(position());
for_scope = inner_block_scope->outer_scope();
DCHECK_EQ(for_scope, scope());
inner_block_scope->set_start_position(scanner()->location().beg_pos);
} }
ExpressionT each_variable = impl()->NullExpression(); ExpressionT each_variable = impl()->NullExpression();
BlockT body_block = impl()->NullBlock(); BlockT body_block = impl()->NullBlock();
{ {
BlockState block_state( BlockState block_state(&scope_, inner_block_scope);
&scope_, inner_block_scope != nullptr ? inner_block_scope : scope_);
SourceRange body_range; SourceRange body_range;
StatementT body = impl()->NullStatement(); StatementT body = impl()->NullStatement();
...@@ -5531,9 +5527,9 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations( ...@@ -5531,9 +5527,9 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations(
&each_variable); &each_variable);
body_block->statements()->Add(body, zone()); body_block->statements()->Add(body, zone());
if (inner_block_scope != nullptr) { if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
inner_block_scope->set_end_position(end_position()); scope()->set_end_position(end_position());
body_block->set_scope(inner_block_scope->FinalizeBlockScope()); body_block->set_scope(scope()->FinalizeBlockScope());
} }
} }
...@@ -5542,19 +5538,16 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations( ...@@ -5542,19 +5538,16 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations(
init_block = impl()->CreateForEachStatementTDZ(init_block, *for_info); init_block = impl()->CreateForEachStatementTDZ(init_block, *for_info);
if (for_scope != nullptr) {
for_scope->set_end_position(end_position());
for_scope = for_scope->FinalizeBlockScope();
}
// Parsed for-in loop w/ variable declarations. // Parsed for-in loop w/ variable declarations.
if (!impl()->IsNull(init_block)) { if (!impl()->IsNull(init_block)) {
init_block->statements()->Add(final_loop, zone()); init_block->statements()->Add(final_loop, zone());
init_block->set_scope(for_scope); if (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode)) {
scope()->set_end_position(end_position());
init_block->set_scope(scope()->FinalizeBlockScope());
}
return init_block; return init_block;
} }
DCHECK_NULL(for_scope);
return final_loop; return final_loop;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment