summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-18 23:44:33 +0000
committerLinus Groh <mail@linusgroh.de>2022-01-19 20:33:08 +0000
commit95a9f12b97ff18c895ae1e29321dae793d503275 (patch)
tree7a13e4381be7ae6097f2d68237e169d187bfa2d5 /Userland
parentc1d3b557d5c6dc7bee53388f3b2e1db82b799ed8 (diff)
downloadserenity-95a9f12b97ff18c895ae1e29321dae793d503275.zip
LibJS: Set Token's m_offset to the value's start index
This makes much more sense than the current way of setting it to the Lexer's m_position after consuming the full value.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Lexer.cpp6
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp7
2 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp
index a71469f362..685e915d2b 100644
--- a/Userland/Libraries/LibJS/Lexer.cpp
+++ b/Userland/Libraries/LibJS/Lexer.cpp
@@ -832,7 +832,7 @@ Token Lexer::next()
m_filename,
m_line_number,
m_line_column - 1,
- m_position);
+ value_start + 1);
m_hit_invalid_unicode.clear();
// Do not produce any further tokens.
VERIFY(is_eof());
@@ -845,7 +845,7 @@ Token Lexer::next()
m_filename,
value_start_line_number,
value_start_column_number,
- m_position);
+ value_start - 1);
}
if (identifier.has_value())
@@ -889,7 +889,7 @@ Token Lexer::force_slash_as_regex()
m_filename,
m_current_token.line_number(),
m_current_token.line_column(),
- m_position);
+ value_start - 1);
if constexpr (LEXER_DEBUG) {
dbgln("------------------------------");
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 6772e2fff8..9b6e353c2f 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -2138,7 +2138,12 @@ RefPtr<BindingPattern> Parser::synthesize_binding_pattern(Expression const& expr
return error.position.has_value() && range.contains(*error.position);
});
// Make a parser and parse the source for this expression as a binding pattern.
- auto source = m_state.lexer.source().substring_view(expression.source_range().start.offset - 2, expression.source_range().end.offset - expression.source_range().start.offset);
+ // NOTE: There's currently a fundamental problem that we pass the *next* (a.k.a. `current_token`)
+ // token's position to most nodes' SourceRange when using `rule_start.position(), position()`.
+ // This means that `source` will contain the subsequent token's trivia, if any (which is fine).
+ auto source_start_offset = expression.source_range().start.offset;
+ auto source_end_offset = expression.source_range().end.offset;
+ auto source = m_state.lexer.source().substring_view(source_start_offset, source_end_offset - source_start_offset);
Lexer lexer { source, m_state.lexer.filename(), expression.source_range().start.line, expression.source_range().start.column };
Parser parser { lexer };