@@ -5062,20 +5062,37 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
5062
5062
}
5063
5063
5064
5064
bool starts_with_identifier = peek_any_identifier ();
5065
- ExpressionT expr = ParseExpression ();
5066
- if (peek () == Token::COLON && starts_with_identifier &&
5067
- impl ()->IsIdentifier (expr)) {
5068
- // The whole expression was a single identifier, and not, e.g.,
5069
- // something starting with an identifier or a parenthesized identifier.
5070
- impl ()->DeclareLabel (&labels, &own_labels,
5071
- impl ()->AsIdentifierExpression (expr));
5072
- Consume (Token::COLON);
5073
- // ES#sec-labelled-function-declarations Labelled Function Declarations
5074
- if (peek () == Token::FUNCTION && is_sloppy (language_mode ()) &&
5075
- allow_function == kAllowLabelledFunctionStatement ) {
5076
- return ParseFunctionDeclaration ();
5077
- }
5078
- return ParseStatement (labels, own_labels, allow_function);
5065
+
5066
+ ExpressionT expr;
5067
+ {
5068
+ // Effectively inlines ParseExpression, so potential labels can be extracted
5069
+ // from expression_scope.
5070
+ ExpressionParsingScope expression_scope (impl ());
5071
+ AcceptINScope scope (this , true );
5072
+ expr = ParseExpressionCoverGrammar ();
5073
+ expression_scope.ValidateExpression ();
5074
+
5075
+ if (peek () == Token::COLON && starts_with_identifier &&
5076
+ impl ()->IsIdentifier (expr)) {
5077
+ // The whole expression was a single identifier, and not, e.g.,
5078
+ // something starting with an identifier or a parenthesized identifier.
5079
+ DCHECK_EQ (expression_scope.variable_list ()->length (), 1 );
5080
+ VariableProxy* label = expression_scope.variable_list ()->at (0 ).first ;
5081
+ impl ()->DeclareLabel (&labels, &own_labels, label->raw_name ());
5082
+
5083
+ // Remove the "ghost" variable that turned out to be a label from the top
5084
+ // scope. This way, we don't try to resolve it during the scope
5085
+ // processing.
5086
+ this ->scope ()->DeleteUnresolved (label);
5087
+
5088
+ Consume (Token::COLON);
5089
+ // ES#sec-labelled-function-declarations Labelled Function Declarations
5090
+ if (peek () == Token::FUNCTION && is_sloppy (language_mode ()) &&
5091
+ allow_function == kAllowLabelledFunctionStatement ) {
5092
+ return ParseFunctionDeclaration ();
5093
+ }
5094
+ return ParseStatement (labels, own_labels, allow_function);
5095
+ }
5079
5096
}
5080
5097
5081
5098
// If we have an extension, we allow a native function declaration.
0 commit comments