Skip to content

Commit

Permalink
Merge pull request #1603 from ruby/remove-visitor-usage
Browse files Browse the repository at this point in the history
Remove visitor usage to not rely on overriding visit
  • Loading branch information
kddnewton authored Sep 26, 2023
2 parents b5a9de1 + 6903860 commit c1707f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions rakelib/check_manifest.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ task :check_manifest => [:templates] do
autom4te.cache
bin
build
doc
fuzz
java
pkg
Expand Down
21 changes: 15 additions & 6 deletions test/yarp/newline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ def assert_newlines(base, relative)

result = YARP.parse_file(filepath)
assert_empty result.errors

result.mark_newlines!
visitor = NewlineVisitor.new(result.source)

result.value.accept(visitor)
actual = visitor.newlines
actual = yarp_lines(result)

source.each_line.with_index(1) do |line, line_number|
# Lines like `while (foo = bar)` result in two line flags in the
Expand Down Expand Up @@ -92,5 +87,19 @@ def rubyvm_lines(source)

lines.sort
end

def yarp_lines(result)
result.mark_newlines!

queue = [result.value]
newlines = []

while node = queue.shift
queue.concat(node.compact_child_nodes)
newlines << result.source.line(node.location.start_offset) if node&.newline?
end

newlines
end
end
end

0 comments on commit c1707f6

Please sign in to comment.