From 32016d39244d3171d866a1497dee24f5b81b8d14 Mon Sep 17 00:00:00 2001 From: davidot Date: Fri, 26 Nov 2021 16:40:27 +0100 Subject: [PATCH] LibJS: Allow object properties called 'async' --- Userland/Libraries/LibJS/Parser.cpp | 3 ++- Userland/Libraries/LibJS/Tests/syntax/async-await.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 01e5df3aeb..04d4e058a2 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1486,7 +1486,8 @@ NonnullRefPtr Parser::parse_object_expression() if (match(TokenType::Async)) { auto lookahead_token = next_token(); - if (lookahead_token.type() != TokenType::ParenOpen && !lookahead_token.trivia_contains_line_terminator()) { + if (lookahead_token.type() != TokenType::ParenOpen && lookahead_token.type() != TokenType::Colon + && !lookahead_token.trivia_contains_line_terminator()) { consume(TokenType::Async); function_kind = FunctionKind::Async; } diff --git a/Userland/Libraries/LibJS/Tests/syntax/async-await.js b/Userland/Libraries/LibJS/Tests/syntax/async-await.js index 0cc231278f..d7f5b367be 100644 --- a/Userland/Libraries/LibJS/Tests/syntax/async-await.js +++ b/Userland/Libraries/LibJS/Tests/syntax/async-await.js @@ -18,6 +18,14 @@ describe("parsing object literal async functions", () => { expect(`x = { async foo() { } }`).not.toEval(); }); + + test("property on object called async", () => { + expect(`x = { async() { } }`).toEval(); + expect(`x = { async() { await 4; } }`).not.toEval(); + expect(`x = { async: 3 }`).toEval(); + expect(`x = { async: await 3, }`).not.toEval(); + }); + test("await expression", () => { expect(`x = { foo() { await bar(); } }`).not.toEval(); expect(`x = { foo() { await; } }`).toEval();