LibJS: Prefer FunctionDeclaration if a statement begins with "function"
This commit is contained in:
parent
1a10470c1d
commit
73d28a0551
Notes:
sideshowbarker
2024-07-19 08:13:56 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/73d28a0551e
2 changed files with 4 additions and 7 deletions
|
@ -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!");
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue