mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
LibJS: Partially revert e3fa32b
This was causing some syntactically wrong inputs to crash and subsequently broke CI (test262 parser tests).
This commit is contained in:
parent
6453a9aa8e
commit
99662975ed
1 changed files with 8 additions and 19 deletions
|
@ -107,26 +107,15 @@ public:
|
||||||
{
|
{
|
||||||
if (!position.has_value())
|
if (!position.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
// We need to modify the source to match what the lexer considers one line - normalizing
|
||||||
StringBuilder builder;
|
// line terminators to \n is easier than splitting using all different LT characters.
|
||||||
String source_string { source };
|
String source_string { source };
|
||||||
GenericLexer lexer(source_string);
|
source_string.replace("\r\n", "\n");
|
||||||
// Skip to the line we want
|
source_string.replace("\r", "\n");
|
||||||
size_t current_line = 0;
|
source_string.replace(LINE_SEPARATOR, "\n");
|
||||||
while (current_line < position.value().line - 1) {
|
source_string.replace(PARAGRAPH_SEPARATOR, "\n");
|
||||||
if (lexer.consume_specific("\n") || lexer.consume_specific("\r\n") || lexer.consume_specific(LINE_SEPARATOR) || lexer.consume_specific(PARAGRAPH_SEPARATOR))
|
StringBuilder builder;
|
||||||
current_line++;
|
builder.append(source_string.split_view('\n', true)[position.value().line - 1]);
|
||||||
else
|
|
||||||
lexer.ignore();
|
|
||||||
VERIFY(!lexer.is_eof());
|
|
||||||
}
|
|
||||||
// We are at the line, now add the chars to the string
|
|
||||||
while (!lexer.is_eof()) {
|
|
||||||
if (lexer.consume_specific("\n") || lexer.consume_specific("\r\n") || lexer.consume_specific(LINE_SEPARATOR) || lexer.consume_specific(PARAGRAPH_SEPARATOR))
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
builder.append(lexer.consume());
|
|
||||||
}
|
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
for (size_t i = 0; i < position.value().column - 1; ++i)
|
for (size_t i = 0; i < position.value().column - 1; ++i)
|
||||||
builder.append(spacer);
|
builder.append(spacer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue