diff --git a/spec/compiler/parser/to_s_spec.cr b/spec/compiler/parser/to_s_spec.cr index abb3d260a460..c7469f26b7e1 100644 --- a/spec/compiler/parser/to_s_spec.cr +++ b/spec/compiler/parser/to_s_spec.cr @@ -624,6 +624,30 @@ describe "ASTNode#to_s" do %} CR + expect_to_s <<-'CR', <<-'CR' + {% + ({"a" => "b"} of Nil => Nil).each do |k, v| + # stuff and things + k + v + + # foo bar + + k + v + end + %} + CR + {% + ({"a" => "b"} of Nil => Nil).each do |k, v| + + k + v + + + + k + v + end + %} + CR + expect_to_s <<-'CR' {% vals = "foo".strip.strip.strip diff --git a/src/compiler/crystal/syntax/to_s.cr b/src/compiler/crystal/syntax/to_s.cr index c6bf5d85f939..c7f36605651f 100644 --- a/src/compiler/crystal/syntax/to_s.cr +++ b/src/compiler/crystal/syntax/to_s.cr @@ -1195,6 +1195,8 @@ module Crystal @str << '|' end + write_extra_newlines node.location, node.body.location + if single_line_block @str << ' ' node.body.accept self