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

LibJS: Add TokenType::TemplateLiteral

This is required for template literals - we're not quite there yet, but at
least the parser can now tell us when this token is encountered -
currently this yields "Unexpected token Invalid". Not really helpful.

The character is a "backtick", but as we already have
TokenType::{StringLiteral,RegexLiteral} this seemed like a fitting name.

This also enables syntax highlighting for template literals in the js
REPL and LibGUI's JSSyntaxHighlighter.
This commit is contained in:
Linus Groh 2020-04-24 00:20:02 +01:00 committed by Andreas Kling
parent 57caca3171
commit 95b51e857d
6 changed files with 13 additions and 3 deletions

View file

@ -74,7 +74,7 @@ double Token::double_value() const
String Token::string_value() const
{
ASSERT(type() == TokenType::StringLiteral);
ASSERT(type() == TokenType::StringLiteral || type() == TokenType::TemplateLiteral);
StringBuilder builder;
for (size_t i = 1; i < m_value.length() - 1; ++i) {
if (m_value[i] == '\\' && i + 1 < m_value.length() - 1) {
@ -107,6 +107,9 @@ String Token::string_value() const
case '"':
builder.append('"');
break;
case '`':
builder.append('`');
break;
case '\\':
builder.append('\\');
break;