summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibJS/Lexer.cpp1
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp1
-rw-r--r--Userland/Libraries/LibJS/Tests/classes/class-private-fields.js13
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js1
4 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp
index 30e00eb636..dc70354ed1 100644
--- a/Userland/Libraries/LibJS/Lexer.cpp
+++ b/Userland/Libraries/LibJS/Lexer.cpp
@@ -498,6 +498,7 @@ bool Lexer::slash_means_division() const
|| type == TokenType::NumericLiteral
|| type == TokenType::ParenClose
|| type == TokenType::PlusPlus
+ || type == TokenType::PrivateIdentifier
|| type == TokenType::RegexLiteral
|| type == TokenType::StringLiteral
|| type == TokenType::TemplateLiteralEnd
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 04d4e058a2..12478418d2 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -1989,6 +1989,7 @@ RefPtr<BindingPattern> Parser::synthesize_binding_pattern(Expression const& expr
parser.m_state.string_legacy_octal_escape_sequence_in_scope = m_state.string_legacy_octal_escape_sequence_in_scope;
parser.m_state.in_class_field_initializer = m_state.in_class_field_initializer;
parser.m_state.in_class_static_init_block = m_state.in_class_static_init_block;
+ parser.m_state.referenced_private_names = m_state.referenced_private_names;
auto result = parser.parse_binding_pattern(AllowDuplicates::Yes, AllowMemberExpressions::Yes);
if (parser.has_errors())
diff --git a/Userland/Libraries/LibJS/Tests/classes/class-private-fields.js b/Userland/Libraries/LibJS/Tests/classes/class-private-fields.js
index 06cf102a6d..286019a538 100644
--- a/Userland/Libraries/LibJS/Tests/classes/class-private-fields.js
+++ b/Userland/Libraries/LibJS/Tests/classes/class-private-fields.js
@@ -83,6 +83,19 @@ test("static fields", () => {
expect("A.#simple").not.toEval();
});
+test("slash after private identifier is treated as division", () => {
+ class A {
+ static #field = 4;
+ static #divided = this.#field / 2;
+
+ static getDivided() {
+ return this.#divided;
+ }
+ }
+
+ expect(A.getDivided()).toBe(2);
+});
+
test("cannot have static and non static field with the same description", () => {
expect("class A { static #simple; #simple; }").not.toEval();
});
diff --git a/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js b/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js
index c3c9771f1a..3fea8feb0a 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js
@@ -17,6 +17,7 @@ test("slash token resolution in lexer", () => {
expect("+a-- / 1").toEval();
expect("a.in / b").toEval();
expect("a.instanceof / b").toEval();
+ expect("class A { #name; d = a.#name / b; }").toEval();
// FIXME: Even more 'reserved' words are valid however the cases below do still need to pass.
//expect("a.void / b").toEval();