lib/unparser/writer/dynamic_string.rb in unparser-0.5.0 vs lib/unparser/writer/dynamic_string.rb in unparser-0.5.1

- old
+ new

@@ -44,11 +44,11 @@ def heredoc_header need_squiggly? ? '<<~HEREDOC' : '<<-HEREDOC' end def heredoc? - children.empty? || (nl_last_child? && heredoc_pattern?) + !children.empty? && (nl_last_child? && heredoc_pattern?) end def emit_heredoc_header write(heredoc_header) end @@ -167,11 +167,15 @@ def emit_dynamic_component(node) visit(node) if node end def emit_dstr - segments.each_with_index do |children, index| - emit_segment(children, index) + if children.empty? + write('%()') + else + segments.each_with_index do |children, index| + emit_segment(children, index) + end end end def breakpoint?(child, current) last_type = current.last&.type