Преглед изворни кода

LibJS: Remove DeprecatedString usage from Token

Evan Smal пре 2 година
родитељ
комит
cfa6b4d815

+ 3 - 3
Userland/Libraries/LibJS/Lexer.cpp

@@ -836,7 +836,7 @@ Token Lexer::next()
 
     if (m_hit_invalid_unicode.has_value()) {
         value_start = m_hit_invalid_unicode.value() - 1;
-        m_current_token = Token(TokenType::Invalid, "Invalid unicode codepoint in source",
+        m_current_token = Token(TokenType::Invalid, String::from_utf8("Invalid unicode codepoint in source"sv).release_value_but_fixme_should_propagate_errors(),
             ""sv, // Since the invalid unicode can occur anywhere in the current token the trivia is not correct
             m_source.substring_view(value_start + 1, min(4u, m_source.length() - value_start - 2)),
             m_filename,
@@ -849,7 +849,7 @@ Token Lexer::next()
     } else {
         m_current_token = Token(
             token_type,
-            token_message,
+            String::from_deprecated_string(token_message).release_value_but_fixme_should_propagate_errors(),
             m_source.substring_view(trivia_start - 1, value_start - trivia_start),
             m_source.substring_view(value_start - 1, m_position - value_start),
             m_filename,
@@ -893,7 +893,7 @@ Token Lexer::force_slash_as_regex()
 
     m_current_token = Token(
         token_type,
-        "",
+        String {},
         m_current_token.trivia(),
         m_source.substring_view(value_start - 1, m_position - value_start),
         m_filename,

+ 1 - 1
Userland/Libraries/LibJS/Parser.cpp

@@ -4133,7 +4133,7 @@ Token Parser::consume_and_validate_numeric_literal()
 
 void Parser::expected(char const* what)
 {
-    auto message = m_state.current_token.message();
+    auto message = m_state.current_token.message().to_deprecated_string();
     if (message.is_empty())
         message = DeprecatedString::formatted("Unexpected token {}. Expected {}", m_state.current_token.name(), what);
     syntax_error(message);

+ 5 - 5
Userland/Libraries/LibJS/Token.h

@@ -7,7 +7,7 @@
 #pragma once
 
 #include <AK/DeprecatedFlyString.h>
-#include <AK/DeprecatedString.h>
+#include <AK/String.h>
 #include <AK/StringView.h>
 #include <AK/Variant.h>
 
@@ -181,9 +181,9 @@ class Token {
 public:
     Token() = default;
 
-    Token(TokenType type, DeprecatedString message, StringView trivia, StringView value, StringView filename, size_t line_number, size_t line_column, size_t offset)
+    Token(TokenType type, String message, StringView trivia, StringView value, StringView filename, size_t line_number, size_t line_column, size_t offset)
         : m_type(type)
-        , m_message(message)
+        , m_message(move(message))
         , m_trivia(trivia)
         , m_original_value(value)
         , m_value(value)
@@ -200,7 +200,7 @@ public:
     char const* name() const;
     static char const* name(TokenType);
 
-    DeprecatedString const& message() const { return m_message; }
+    String const& message() const { return m_message; }
     StringView trivia() const { return m_trivia; }
     StringView original_value() const { return m_original_value; }
     StringView value() const
@@ -246,7 +246,7 @@ public:
 
 private:
     TokenType m_type { TokenType::Invalid };
-    DeprecatedString m_message;
+    String m_message;
     StringView m_trivia;
     StringView m_original_value;
     Variant<Empty, StringView, DeprecatedFlyString> m_value {};