Fix an error for Prism::Translation::Parser::Lexer
This PR fixes the following error for `Prism::Translation::Parser::Lexer` on the main branch: ```console $ cat example.rb 'a' # aあ " #{x} " $ bundle exec rubocop Parser::Source::Range: end_pos must not be less than begin_pos /Users/koic/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/parser-3.3.0.5/lib/parser/source/range.rb:39:in `initialize' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser/lexer.rb:299:in `new' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser/lexer.rb:299:in `block in to_a' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser/lexer.rb:297:in `map' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser/lexer.rb:297:in `to_a' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:263:in `build_tokens' /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:92:in `tokenize' ``` This change was made in https://github.com/ruby/prism/pull/2557, and it seems there was an inconsistency in Range due to forgetting to apply `offset_cache` to `start_offset`.
This commit is contained in:
parent
4756eaf5aa
commit
af8a4205bf
@ -296,7 +296,7 @@ module Prism
|
||||
start_offset = offset_cache[token.location.start_offset]
|
||||
lines.map do |line|
|
||||
end_offset = start_offset + line.length
|
||||
tokens << [:tSTRING_CONTENT, [line, Range.new(source_buffer, start_offset, offset_cache[end_offset])]]
|
||||
tokens << [:tSTRING_CONTENT, [line, Range.new(source_buffer, offset_cache[start_offset], offset_cache[end_offset])]]
|
||||
start_offset = end_offset
|
||||
end
|
||||
next
|
||||
|
Loading…
x
Reference in New Issue
Block a user