mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Stop parsing an expression on comma after a yield
This commit is contained in:
parent
156dfe3d62
commit
4d7e79fb72
Notes:
sideshowbarker
2024-07-17 23:18:18 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/4d7e79fb72c Pull-request: https://github.com/SerenityOS/serenity/pull/11088 Issue: https://github.com/SerenityOS/serenity/issues/11078 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
2 changed files with 7 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue