diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-02 15:11:11 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-02 14:59:03 +0200 |
commit | 2e00731ddb646878caf7a6bdfae4f21feaf319b2 (patch) | |
tree | cdad08af9e9e7cd25a664f2dc4efca17a50f8557 /Userland/Libraries | |
parent | a6fe27423a1b98c157f98ccba7f989eea0105547 (diff) | |
download | serenity-2e00731ddb646878caf7a6bdfae4f21feaf319b2.zip |
LibJS: Allow 'yield' and 'await' as function expression names
The spec says so, and test262 checks for this too.
Diffstat (limited to 'Userland/Libraries')
-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(); +}); |