Browse Source

Allow `true`, `false` and `null` in object patterns (#2994)

* Allow `true`, `false` and `null` in object patterns

* Add test
pull/2995/head
José Julián Espina 2 years ago committed by GitHub
parent
commit
ee97198d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      boa_engine/src/tests/mod.rs
  2. 2
      boa_parser/src/parser/statement/mod.rs

18
boa_engine/src/tests/mod.rs

@ -481,3 +481,21 @@ fn template_literal() {
"result: 10 and 20",
)]);
}
#[test]
fn null_bool_in_object_pattern() {
run_test_actions([
TestAction::run(indoc! {r#"
let obj = {
null: 0,
true: 10,
false: 100
};
let { null: a, true: b, false: c } = obj;
"#}),
TestAction::assert_eq("a", 0),
TestAction::assert_eq("b", 10),
TestAction::assert_eq("c", 100),
]);
}

2
boa_parser/src/parser/statement/mod.rs

@ -529,6 +529,8 @@ where
| TokenKind::NumericLiteral(_) => true,
TokenKind::IdentifierName(_) if next_token_is_colon => true,
TokenKind::Keyword(_) if next_token_is_colon => true,
TokenKind::BooleanLiteral(_) if next_token_is_colon => true,
TokenKind::NullLiteral(_) if next_token_is_colon => true,
_ => false,
};

Loading…
Cancel
Save