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

LibJS: Fix that windows style line endings were not ignored or converted

These are tested by test262 but the current test262-runner reads the
files in python which automatically converts \r\n to \n.
This meant that we passed the tests while we should not have.
This commit is contained in:
davidot 2021-09-01 18:34:19 +02:00 committed by Linus Groh
parent f2512071f2
commit 3fee7b0d0b
4 changed files with 51 additions and 1 deletions

View file

@ -106,6 +106,16 @@ String Token::string_value(StringValueStatus& status) const
while (!lexer.is_eof()) {
// No escape, consume one char and continue
if (!lexer.next_is('\\')) {
if (is_template && lexer.next_is('\r')) {
lexer.ignore();
if (lexer.next_is('\n'))
lexer.ignore();
builder.append('\n');
continue;
}
builder.append(lexer.consume());
continue;
}
@ -132,6 +142,8 @@ String Token::string_value(StringValueStatus& status) const
// Line continuation
if (lexer.next_is('\n') || lexer.next_is('\r')) {
if (lexer.next_is("\r\n"))
lexer.ignore();
lexer.ignore();
continue;
}
@ -192,6 +204,15 @@ String Token::string_value(StringValueStatus& status) const
return builder.to_string();
}
// 12.8.6.2 Static Semantics: TRV, https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-static-semantics-trv
String Token::raw_template_value() const
{
String base = value().to_string();
base.replace("\r\n", "\n", true);
base.replace("\r", "\n", true);
return base;
}
bool Token::bool_value() const
{
VERIFY(type() == TokenType::BoolLiteral);