Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions core/engine/src/tests/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ where
| TokenKind::NumericLiteral(_)
| TokenKind::Keyword(_)
| TokenKind::NullLiteral(_)
| TokenKind::BooleanLiteral(_)
| TokenKind::PrivateIdentifier(_)
| TokenKind::Punctuator(
Punctuator::OpenBracket | Punctuator::Mul | Punctuator::OpenBlock,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions core/parser/src/parser/tests/format/function/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
"#,
);
}
Loading