diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 5379c891d5..cb758c802c 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -2153,7 +2153,7 @@ NonnullRefPtr Parser::parse_yield_expression() } if (yield_from || match_expression() || match(TokenType::Class)) - argument = parse_expression(0); + argument = parse_expression(2); } return create_ast_node({ m_state.current_token.filename(), rule_start.position(), position() }, move(argument), yield_from); diff --git a/Userland/Libraries/LibJS/Tests/syntax/generators.js b/Userland/Libraries/LibJS/Tests/syntax/generators.js index 99e0968c4b..c70bc6cf72 100644 --- a/Userland/Libraries/LibJS/Tests/syntax/generators.js +++ b/Userland/Libraries/LibJS/Tests/syntax/generators.js @@ -12,6 +12,12 @@ describe("parsing freestanding generators", () => { expect(`function foo() { yield; }`).toEval(); expect(`function foo() { yield 3; }`).not.toEval(); }); + + test("yield expression only gets the first expression", () => { + expect("function* foo() { yield 2,3 }").toEval(); + expect("function* foo() { ({...yield yield, }) }").toEval(); + }); + test("yield-from expression", () => { expect(`function* foo() { yield *bar; }`).toEval(); expect(`function* foo() { yield *(yield); }`).toEval();