1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibJS: Prefer FunctionDeclaration if a statement begins with "function"

This commit is contained in:
Andreas Kling 2020-03-19 18:07:07 +01:00
parent 1a10470c1d
commit 73d28a0551
2 changed files with 4 additions and 7 deletions

View file

@ -2,10 +2,9 @@
<html> <html>
<head> <head>
<script> <script>
function foo() { document.addEventListener("DOMContentLoaded", function() {
alert("It loaded!"); alert("It loaded!");
} );
document.addEventListener("DOMContentLoaded", foo);
function on_mousedown() { function on_mousedown() {
alert("Mouse down!"); alert("Mouse down!");

View file

@ -181,10 +181,6 @@ NonnullRefPtr<Program> Parser::parse_program()
NonnullRefPtr<Statement> Parser::parse_statement() NonnullRefPtr<Statement> Parser::parse_statement()
{ {
if (match_expression()) {
return adopt(*new ExpressionStatement(parse_expression(0)));
}
switch (m_current_token.type()) { switch (m_current_token.type()) {
case TokenType::Function: case TokenType::Function:
return parse_function_node<FunctionDeclaration>(); return parse_function_node<FunctionDeclaration>();
@ -199,6 +195,8 @@ NonnullRefPtr<Statement> Parser::parse_statement()
case TokenType::For: case TokenType::For:
return parse_for_statement(); return parse_for_statement();
default: default:
if (match_expression())
return adopt(*new ExpressionStatement(parse_expression(0)));
m_has_errors = true; m_has_errors = true;
expected("statement (missing switch case)"); expected("statement (missing switch case)");
consume(); consume();