instance method
Prism::Translation::Ripper#visit_heredoc_node_whitespace
visit_heredoc_node_whitespace(parts)
lib/prism/translation/ripper.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/translation/ripper.rb, line 2981
def visit_heredoc_node_whitespace(parts)
common_whitespace = nil
dedent_next = true
parts.each do |part|
if part.is_a?(StringNode)
if dedent_next && !(content = part.content).chomp.empty?
common_whitespace = [
common_whitespace || Float::INFINITY,
content[/\A\s*/].each_char.inject(0) do |part_whitespace, char|
char == "\t" ? ((part_whitespace / 8 + 1) * 8) : (part_whitespace + 1)
end
].min
end
dedent_next = true
else
dedent_next = false
end
end
common_whitespace || 0
end
Ripper gives back the escaped string content but strips out the common leading whitespace. Prism gives back the unescaped string content and a location for the escaped string content. Unfortunately these don’t work well together, so here we need to re-derive the common leading whitespace.