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
Notes: sideshowbarker 2024-07-19 08:13:56 +09:00
2 changed files with 4 additions and 7 deletions

View file

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

View file

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