Skip to content

Commit

Permalink
Fix "Node#source" for case with no expression
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Sep 23, 2020
1 parent c3add0a commit 92f6745
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ def each_node(*types, &block)
self
end

# Note: Some rare nodes may have no source, like `s(:args)` in `foo {}`
# @return [String, nil]
def source
loc.expression.source
loc.expression&.source
end

def source_range
Expand Down

0 comments on commit 92f6745

Please sign in to comment.