diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 624846154c..63c86d214f 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -645,7 +645,9 @@ Parser::PrimaryExpressionParseResult Parser::parse_primary_expression() case TokenType::ParenOpen: { auto paren_position = position(); consume(TokenType::ParenOpen); - if ((match(TokenType::ParenClose) || match(TokenType::Identifier) || match(TokenType::TripleDot)) && !try_parse_arrow_function_expression_failed_at_position(paren_position)) { + if ((match(TokenType::ParenClose) || match(TokenType::Identifier) || match(TokenType::TripleDot) || match(TokenType::CurlyOpen) || match(TokenType::BracketOpen)) + && !try_parse_arrow_function_expression_failed_at_position(paren_position)) { + auto arrow_function_result = try_parse_arrow_function_expression(true); if (!arrow_function_result.is_null()) return { arrow_function_result.release_nonnull() }; diff --git a/Userland/Libraries/LibJS/Tests/functions/arrow-functions.js b/Userland/Libraries/LibJS/Tests/functions/arrow-functions.js index 6af8790514..5b25d4a66b 100644 --- a/Userland/Libraries/LibJS/Tests/functions/arrow-functions.js +++ b/Userland/Libraries/LibJS/Tests/functions/arrow-functions.js @@ -162,3 +162,10 @@ test("syntax errors", () => { expect("(a = 1 = 2) => {}").not.toEval(); expect("()\n=> {}").not.toEval(); }); + +test("destructuring parameters", () => { + expect(`({ a }) => {}`).toEval(); + expect(`([ a ]) => {}`).toEval(); + expect(`{ a } => {}`).not.toEval(); + expect(`[ a ] => {}`).not.toEval(); +});