Skip to content

Commit

Permalink
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -924,4 +924,7 @@ describe Crystal::Formatter do
assert_format %(x : {"foo bar": Int32})

assert_format %(def foo("bar baz" qux)\nend)
assert_format "{ {{FOO}}, nil}", "{ {{FOO}}, nil }"
assert_format "{ {% begin %}1{% end %}, nil }"
assert_format "{ {% for x in 1..2 %}3{% end %}, nil }"
end
9 changes: 8 additions & 1 deletion src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -674,7 +674,14 @@ module Crystal
current_element = current_element.key
end

if prefix == :"{" && i == 0 && !wrote_newline && (current_element.is_a?(TupleLiteral) || current_element.is_a?(NamedTupleLiteral) || current_element.is_a?(HashLiteral))
if prefix == :"{" && i == 0 && !wrote_newline && (
current_element.is_a?(TupleLiteral) ||
current_element.is_a?(NamedTupleLiteral) ||
current_element.is_a?(HashLiteral) ||
current_element.is_a?(MacroExpression) ||
current_element.is_a?(MacroIf) ||
current_element.is_a?(MacroFor)
)
write " "
write_space_at_end = true
end

0 comments on commit 8b0ea3d

Please sign in to comment.