diff options
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/syntax/generators.js | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 93e110f83e..624846154c 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -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; diff --git a/Userland/Libraries/LibJS/Tests/syntax/generators.js b/Userland/Libraries/LibJS/Tests/syntax/generators.js index ba521f9fed..99e0968c4b 100644 --- a/Userland/Libraries/LibJS/Tests/syntax/generators.js +++ b/Userland/Libraries/LibJS/Tests/syntax/generators.js @@ -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(); +}); |