LibJS: Allow 'yield' and 'await' as function expression names

The spec says so, and test262 checks for this too.
This commit is contained in:
Ali Mohammad Pur 2021-07-02 15:11:11 +04:30 committed by Andreas Kling
parent a6fe27423a
commit 2e00731ddb
Notes: sideshowbarker 2024-07-18 11:07:33 +09:00
2 changed files with 8 additions and 0 deletions

View file

@ -1417,6 +1417,7 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
ScopePusher scope(*this, ScopePusher::Var | ScopePusher::Function);
constexpr auto is_function_expression = IsSame<FunctionNodeType, FunctionExpression>;
auto is_generator = (parse_options & FunctionNodeParseOptions::IsGeneratorFunction) != 0;
String name;
if (parse_options & FunctionNodeParseOptions::CheckForFunctionAndName) {
@ -1431,6 +1432,8 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options)
if (FunctionNodeType::must_have_name() || match(TokenType::Identifier))
name = consume(TokenType::Identifier).value();
else if (is_function_expression && (match(TokenType::Yield) || match(TokenType::Await)))
name = consume().value();
}
consume(TokenType::ParenOpen);
i32 function_length = -1;

View file

@ -49,3 +49,8 @@ describe("parsing classes with generator methods", () => {
expect(`class Foo { *constructor() { yield 42; } }`).not.toEval();
});
});
test("function expression names equal to 'yield'", () => {
expect(`function *foo() { (function yield() {}); }`).toEval();
expect(`function *foo() { function yield() {} }`).not.toEval();
});