diff options
author | davidot <davidot@serenityos.org> | 2021-11-26 23:38:36 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-30 17:05:32 +0000 |
commit | 4d7e79fb72c33bf341688428948c3c8e90898960 (patch) | |
tree | ed4de356490d03b98f8861566ef54430c571f957 | |
parent | 156dfe3d629f36a03bdcde3a9a253934e45dd4de (diff) | |
download | serenity-4d7e79fb72c33bf341688428948c3c8e90898960.zip |
LibJS: Stop parsing an expression on comma after a yield
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/syntax/generators.js | 6 |
2 files changed, 7 insertions, 1 deletions
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<YieldExpression> Parser::parse_yield_expression() } if (yield_from || match_expression() || match(TokenType::Class)) - argument = parse_expression(0); + argument = parse_expression(2); } return create_ast_node<YieldExpression>({ 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(); |