summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-11-10 19:19:58 +0200
committerLinus Groh <mail@linusgroh.de>2021-11-10 18:11:26 +0000
commitd5f637fa215ecc8b33b0b0b8592defc735fb3b80 (patch)
treebe855610810496d5488ab8d2e80c484809c149b4 /Userland/Libraries/LibJS
parentad5061bb7a7d020bcea4f0c361600091ac5b9f62 (diff)
downloadserenity-d5f637fa215ecc8b33b0b0b8592defc735fb3b80.zip
LibJS: Do not parse async methods with a new line after the "async"
This was already checked in normal function expressions, but was missing for Object Expressions.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp2
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/async-await.js2
2 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 730207be93..80c47e7fa6 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -1449,7 +1449,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
function_kind = FunctionKind::Generator;
} else if (match_identifier()) {
auto identifier = consume();
- if (identifier.original_value() == "async" && match_property_key()) {
+ if (identifier.original_value() == "async" && match_property_key() && !m_state.current_token.trivia_contains_line_terminator()) {
property_type = ObjectProperty::Type::KeyValue;
property_name = parse_property_key();
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 6173c7d05a..33224aa86d 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/async-await.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/async-await.js
@@ -16,7 +16,7 @@ describe("parsing object literal async functions", () => {
test("simple", () => {
expect(`x = { async foo() { } }`).toEval();
expect(`x = { async
- foo() { } }`).toEval();
+ foo() { } }`).not.toEval();
});
test("await expression", () => {
expect(`x = { foo() { await bar(); } }`).not.toEval();