diff --git a/core/engine/src/tests/class.rs b/core/engine/src/tests/class.rs index f15bbaccc32..b77cd4f4e4b 100644 --- a/core/engine/src/tests/class.rs +++ b/core/engine/src/tests/class.rs @@ -117,3 +117,56 @@ fn property_initializer_reference_escaped_variable() { TestAction::assert_eq("Z.getD()", js_str!("D")), ]); } + +// https://github.com/boa-dev/boa/issues/4605 +#[test] +fn class_boolean_literal_method_names() { + run_test_actions([ + TestAction::run(indoc! {r#" + class A { + true() { return 1; } + false() { return 2; } + null() { return 3; } + } + var a = new A(); + "#}), + TestAction::assert_eq("a.true()", 1), + TestAction::assert_eq("a.false()", 2), + TestAction::assert_eq("a.null()", 3), + ]); +} + +// https://github.com/boa-dev/boa/issues/4605 +#[test] +fn class_boolean_literal_static_method_names() { + run_test_actions([ + TestAction::run(indoc! {r#" + class B { + static true() { return 10; } + static false() { return 20; } + } + "#}), + TestAction::assert_eq("B.true()", 10), + TestAction::assert_eq("B.false()", 20), + ]); +} + +// https://github.com/boa-dev/boa/issues/4605 +#[test] +fn class_boolean_literal_getter_setter_names() { + run_test_actions([ + TestAction::run(indoc! {r#" + class C { + get true() { return this._true; } + set true(v) { this._true = v; } + get false() { return this._false; } + set false(v) { this._false = v; } + } + var c = new C(); + c.true = 42; + c.false = 84; + "#}), + TestAction::assert_eq("c.true", 42), + TestAction::assert_eq("c.false", 84), + ]); +} diff --git a/core/parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs b/core/parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs index d8837384b57..c16b10a325b 100644 --- a/core/parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs +++ b/core/parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs @@ -548,6 +548,7 @@ where | TokenKind::NumericLiteral(_) | TokenKind::Keyword(_) | TokenKind::NullLiteral(_) + | TokenKind::BooleanLiteral(_) | TokenKind::PrivateIdentifier(_) | TokenKind::Punctuator( Punctuator::OpenBracket | Punctuator::Mul | Punctuator::OpenBlock, @@ -918,6 +919,7 @@ where | TokenKind::NumericLiteral(_) | TokenKind::Keyword(_) | TokenKind::NullLiteral(_) + | TokenKind::BooleanLiteral(_) | TokenKind::Punctuator(Punctuator::OpenBracket) => { let name_position = token.span().start(); let name = PropertyName::new(self.allow_yield, self.allow_await) @@ -1020,6 +1022,7 @@ where | TokenKind::NumericLiteral(_) | TokenKind::Keyword(_) | TokenKind::NullLiteral(_) + | TokenKind::BooleanLiteral(_) | TokenKind::Punctuator(Punctuator::OpenBracket) => { let name = PropertyName::new(self.allow_yield, self.allow_await) .parse(cursor, interner)?; @@ -1152,6 +1155,7 @@ where | TokenKind::NumericLiteral(_) | TokenKind::Keyword(_) | TokenKind::NullLiteral(_) + | TokenKind::BooleanLiteral(_) | TokenKind::Punctuator(Punctuator::OpenBracket) => { let start = token.span().start(); let name = PropertyName::new(self.allow_yield, self.allow_await) diff --git a/core/parser/src/parser/tests/format/function/class.rs b/core/parser/src/parser/tests/format/function/class.rs index 21e8c3e42a1..f2faedc513f 100644 --- a/core/parser/src/parser/tests/format/function/class.rs +++ b/core/parser/src/parser/tests/format/function/class.rs @@ -104,3 +104,23 @@ fn class_declaration_elements_private_static() { "#, ); } + +// https://github.com/boa-dev/boa/issues/4605 +#[test] +fn class_declaration_boolean_literal_method_names() { + test_formatting( + r#" + class A { + true() {} + false() {} + null() {} + get true() {} + set true(value) {} + get false() {} + set false(value) {} + static true() {} + static false() {} + } + "#, + ); +}