mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibJS: Fix incorrect token column values (#2401)
- initializing m_line_column to 1 in the lexer results in incorrect column values in tokens on the first line of input. - not incrementing m_line_column when EOF is reached results in an incorrect column value on the last token.
This commit is contained in:
parent
7bb69bb9bf
commit
11405c5139
4 changed files with 15 additions and 17 deletions
|
@ -43,9 +43,7 @@ String MarkupGenerator::html_from_source(const StringView& source)
|
|||
auto lexer = Lexer(source);
|
||||
for (auto token = lexer.next(); token.type() != TokenType::Eof; token = lexer.next()) {
|
||||
auto length = token.value().length();
|
||||
auto start = token.line_column();
|
||||
// FIXME: Why do we need to do this magic math? This math isn't even accurate enough, code like "let x = 10" renders incorrectly.
|
||||
start = start < 2 ? 0 : start - 2;
|
||||
auto start = token.line_column() - 1;
|
||||
|
||||
if (start > source_cursor) {
|
||||
builder.append(source.substring_view(source_cursor, start - source_cursor));
|
||||
|
@ -321,4 +319,4 @@ String MarkupGenerator::wrap_string_in_style(String source, StyleType type)
|
|||
return String::format("<span style=\"%s\">%s</span>", style_from_style_type(type).characters(), source.characters());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue