Skip to content

Handle nil symbol in BasicVisitor#visit #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/syntax_tree/basic_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def visit_methods
end

def visit(node)
node&.accept(self)
return if node.nil? || node.is_a?(Symbol)

node.accept(self)
end

def visit_all(nodes)
Expand Down
20 changes: 20 additions & 0 deletions test/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ def baz; end
assert_equal(%w[Foo foo Bar bar baz], visitor.visited_nodes)
end

def test_visit_for_symbols
parsed_tree = SyntaxTree.parse(<<~RUBY)
def foo(**nil)
end

foo do |**nil|
end

->(**nil) {}

case foo
in **nil
end
RUBY

visitor = DummyVisitor.new
visitor.visit(parsed_tree)
assert_equal(%w[foo], visitor.visited_nodes)
end

class DummyVisitor < Visitor
attr_reader :visited_nodes

Expand Down