summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Token.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-26 16:30:05 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-26 16:30:35 +0200
commit49018553d332280bc1f15ee102ad8235d66ce76d (patch)
tree2bf885800fcd37948ad4abdc5e6c16d9d7902cbd /Userland/Libraries/LibJS/Token.cpp
parent527c639c1f60ed562bb274de3714d72ec74e5c9d (diff)
downloadserenity-49018553d332280bc1f15ee102ad8235d66ce76d.zip
LibJS+LibCrypto: Allow '_' as a numeric literal separator :^)
This patch adds support for the NumericLiteralSeparator concept from the ECMAScript grammar.
Diffstat (limited to 'Userland/Libraries/LibJS/Token.cpp')
-rw-r--r--Userland/Libraries/LibJS/Token.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Token.cpp b/Userland/Libraries/LibJS/Token.cpp
index 177fac6d61..6f2b0ebde0 100644
--- a/Userland/Libraries/LibJS/Token.cpp
+++ b/Userland/Libraries/LibJS/Token.cpp
@@ -53,7 +53,16 @@ TokenCategory Token::category() const
double Token::double_value() const
{
VERIFY(type() == TokenType::NumericLiteral);
- String value_string(m_value);
+
+ StringBuilder builder;
+
+ for (auto ch : m_value) {
+ if (ch == '_')
+ continue;
+ builder.append(ch);
+ }
+
+ String value_string = builder.to_string();
if (value_string[0] == '0' && value_string.length() >= 2) {
if (value_string[1] == 'x' || value_string[1] == 'X') {
// hexadecimal