summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-02 14:55:53 +0430
committerAndreas Kling <kling@serenityos.org>2021-07-02 14:59:03 +0200
commita6fe27423a1b98c157f98ccba7f989eea0105547 (patch)
tree3eb9290df96880ba38b0870904c7c27759fccfb9 /Userland/Libraries/LibJS
parentbd9f28bba694b7b015454fc486e43cd78b5418cf (diff)
downloadserenity-a6fe27423a1b98c157f98ccba7f989eea0105547.zip
LibJS: Allow binding patterns as for in/of targets
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp2
-rw-r--r--Userland/Libraries/LibJS/Tests/loops/for-in-basic.js4
-rw-r--r--Userland/Libraries/LibJS/Tests/loops/for-of-basic.js4
3 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index b423529c68..93e110f83e 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -1701,7 +1701,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(bool for_l
init = parse_expression(2);
} else if (!for_loop_variable_declaration && declaration_kind == DeclarationKind::Const) {
syntax_error("Missing initializer in 'const' variable declaration");
- } else if (target.has<NonnullRefPtr<BindingPattern>>()) {
+ } else if (!for_loop_variable_declaration && target.has<NonnullRefPtr<BindingPattern>>()) {
syntax_error("Missing initializer in destructuring assignment");
}
diff --git a/Userland/Libraries/LibJS/Tests/loops/for-in-basic.js b/Userland/Libraries/LibJS/Tests/loops/for-in-basic.js
index ee60bd5eb8..62b59ff708 100644
--- a/Userland/Libraries/LibJS/Tests/loops/for-in-basic.js
+++ b/Userland/Libraries/LibJS/Tests/loops/for-in-basic.js
@@ -49,3 +49,7 @@ test("use already-declared variable", () => {
for (property in "abc");
expect(property).toBe("2");
});
+
+test("allow binding patterns", () => {
+ expect(`for (let [a, b] in foo) {}`).toEval();
+});
diff --git a/Userland/Libraries/LibJS/Tests/loops/for-of-basic.js b/Userland/Libraries/LibJS/Tests/loops/for-of-basic.js
index e08d096c68..4f6277e3f3 100644
--- a/Userland/Libraries/LibJS/Tests/loops/for-of-basic.js
+++ b/Userland/Libraries/LibJS/Tests/loops/for-of-basic.js
@@ -98,3 +98,7 @@ describe("errors", () => {
}).toThrowWithMessage(TypeError, "[object Object] is not iterable");
});
});
+
+test("allow binding patterns", () => {
+ expect(`for (let [a, b] of foo) {}`).toEval();
+});