1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

LibJS: Allow BigInts as destructuring property names

These are simply treated as their numerical value which means that above
2^32 - 1 they are strings.
This commit is contained in:
davidot 2022-08-20 00:24:30 +02:00 committed by Linus Groh
parent e663504df1
commit fce2b33758
3 changed files with 37 additions and 1 deletions

View file

@ -2762,7 +2762,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern(Parser::AllowDuplicates all
name = static_ptr_cast<Identifier>(expression);
else
syntax_error("Invalid destructuring assignment target", expression_position);
} else if (match_identifier_name() || match(TokenType::StringLiteral) || match(TokenType::NumericLiteral)) {
} else if (match_identifier_name() || match(TokenType::StringLiteral) || match(TokenType::NumericLiteral) || match(TokenType::BigIntLiteral)) {
if (match(TokenType::StringLiteral) || match(TokenType::NumericLiteral))
needs_alias = true;
@ -2773,6 +2773,12 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern(Parser::AllowDuplicates all
name = create_ast_node<Identifier>(
{ m_state.current_token.filename(), rule_start.position(), position() },
string_literal->value());
} else if (match(TokenType::BigIntLiteral)) {
auto string_value = consume().flystring_value();
VERIFY(string_value.ends_with("n"sv));
name = create_ast_node<Identifier>(
{ m_state.current_token.filename(), rule_start.position(), position() },
FlyString(string_value.view().substring_view(0, string_value.length() - 1)));
} else {
name = create_ast_node<Identifier>(
{ m_state.current_token.filename(), rule_start.position(), position() },