Kaynağa Gözat

LibJS: Fix do..while parsing by consuming parentheses explicitly (#1652)

Before this patch the parser accepted conditions without enclosing
parentheses (like: .."while number < 9").
Maxim Brunnmeier 5 yıl önce
ebeveyn
işleme
2c4a5849f6
1 değiştirilmiş dosya ile 7 ekleme ve 0 silme
  1. 7 0
      Libraries/LibJS/Parser.cpp

+ 7 - 0
Libraries/LibJS/Parser.cpp

@@ -729,9 +729,16 @@ NonnullRefPtr<TryStatement> Parser::parse_try_statement()
 NonnullRefPtr<DoWhileStatement> Parser::parse_do_while_statement()
 {
     consume(TokenType::Do);
+
     auto body = parse_statement();
+
     consume(TokenType::While);
+    consume(TokenType::ParenOpen);
+
     auto test = parse_expression(0);
+
+    consume(TokenType::ParenClose);
+
     return create_ast_node<DoWhileStatement>(move(test), move(body));
 }