Skip to content

Commit

Permalink
Make ASTNode#reset_line_info support beginless and endless ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
stackmystack committed Sep 12, 2024
1 parent bed9562 commit 5453a3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/yard/parser/ruby/ast_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ def reset_line_info
elsif !children.empty?
f = children.first
l = children.last
self.line_range = Range.new(f.line_range.first, l.line_range.last)
self.source_range = Range.new(f.source_range.first, l.source_range.last)
self.line_range = Range.new(f.line_range.begin, l.line_range.end)
self.source_range = Range.new(f.source_range.begin, l.source_range.end)
elsif @fallback_line || @fallback_source
self.line_range = @fallback_line
self.source_range = @fallback_source
Expand Down
18 changes: 18 additions & 0 deletions spec/parser/ruby/ast_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,22 @@
expect(obj.line).to eq 2
end
end

describe "#reset_line_info" do
skip "Unsupported ruby version" if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.6')
it "does not break on beginless or endless ranges" do
obj = YARD::Parser::Ruby::RubyParser.parse("# x\ndef fn(arg); 42; end", "x").ast
obj = obj.first
expect(obj.children.size).to eq 3
fst = obj.children.first
lst = obj.children.last
fst.line_range = (..10)
fst.source_range = (..10)
lst.line_range = (2..)
lst.source_range = (2..)
obj.send(:reset_line_info)
expect(obj.line_range).to eq (nil..nil)
expect(obj.source_range).to eq (nil..nil)
end
end
end if HAVE_RIPPER

0 comments on commit 5453a3b

Please sign in to comment.