From 4d7e79fb72c33bf341688428948c3c8e90898960 Mon Sep 17 00:00:00 2001 From: davidot Date: Fri, 26 Nov 2021 23:38:36 +0100 Subject: [PATCH] LibJS: Stop parsing an expression on comma after a yield --- Userland/Libraries/LibJS/Parser.cpp | 2 +- Userland/Libraries/LibJS/Tests/syntax/generators.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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();