Skip to content

Commit

Permalink
Avoid choking on Ruby 2.3 heredoc syntax
Browse files Browse the repository at this point in the history
Ruby 2.3 introduces `<<~` heredoc syntax, but when ripper-tags is ran on
Ruby 2.2, it acts weirdly around the heredoc, passing a `:~` symbol to
`on_stmts_add`.

This change avoids Ruby chrashing when encountering this syntax which it
doesn't understand.
  • Loading branch information
mislav committed Dec 14, 2016
1 parent 7ebaec5 commit 3acb37f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ripper-tags/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def on_#{event}(tok)
end

def on_stmts_add(first, *rest)
return if first == :~
(first || []) + rest.compact
end

Expand Down
16 changes: 16 additions & 0 deletions test/test_ripper_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,20 @@ class A
assert_equal 1, tags.size
assert_equal 'A', tags[0][:name]
end

def test_heredoc
tags = extract(<<-EOC)
def foo
puts "hello", <<~EOF
world
EOF
end
def bar; end
EOC

assert_equal 2, tags.size
assert_equal 'foo', tags[0][:name]
assert_equal 'bar', tags[1][:name]
end
end

0 comments on commit 3acb37f

Please sign in to comment.