diff options
author | Linus Groh <mail@linusgroh.de> | 2020-06-06 01:14:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-07 19:29:40 +0200 |
commit | 0ff9d7e1898c224033fde7b03ac9c92db893bfca (patch) | |
tree | bafbbc17fa7c6fdcc2b07c4c4e806f8bfc2eebaa /Libraries/LibJS/Parser.cpp | |
parent | 40829b849ae30d3a9de330d4d66af74f547fbaf1 (diff) | |
download | serenity-0ff9d7e1898c224033fde7b03ac9c92db893bfca.zip |
LibJS: Add BigInt
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index d21b0171c2..7924c4913a 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -451,6 +451,8 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression() } case TokenType::NumericLiteral: return create_ast_node<NumericLiteral>(consume().double_value()); + case TokenType::BigIntLiteral: + return create_ast_node<BigIntLiteral>(consume().value()); case TokenType::BoolLiteral: return create_ast_node<BooleanLiteral>(consume().bool_value()); case TokenType::StringLiteral: @@ -547,7 +549,8 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() return match_identifier_name() || type == TokenType::BracketOpen || type == TokenType::StringLiteral - || type == TokenType::NumericLiteral; + || type == TokenType::NumericLiteral + || type == TokenType::BigIntLiteral; }; auto parse_property_key = [&]() -> NonnullRefPtr<Expression> { @@ -555,6 +558,9 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() return parse_string_literal(consume()); } else if (match(TokenType::NumericLiteral)) { return create_ast_node<StringLiteral>(consume(TokenType::NumericLiteral).value()); + } else if (match(TokenType::BigIntLiteral)) { + auto value = consume(TokenType::BigIntLiteral).value(); + return create_ast_node<StringLiteral>(value.substring_view(0, value.length() - 1)); } else if (match(TokenType::BracketOpen)) { consume(TokenType::BracketOpen); auto result = parse_expression(0); @@ -1448,6 +1454,7 @@ bool Parser::match_expression() const auto type = m_parser_state.m_current_token.type(); return type == TokenType::BoolLiteral || type == TokenType::NumericLiteral + || type == TokenType::BigIntLiteral || type == TokenType::StringLiteral || type == TokenType::TemplateLiteralStart || type == TokenType::NullLiteral |