Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ describe "ASTNode#to_s" do
expect_to_s %({{ foo }})
expect_to_s %({% if foo %}\n foo_then\n{% end %})
expect_to_s %({% if foo %}\n foo_then\n{% else %}\n foo_else\n{% end %})
expect_to_s %({% unless foo %}\n foo_then\n{% end %})
expect_to_s %({% unless foo %}\n foo_then\n{% else %}\n foo_else\n{% end %})
expect_to_s %({% for foo in bar %}\n {{ foo }}\n{% end %})
expect_to_s %(macro foo\n {% for foo in bar %}\n {{ foo }}\n {% end %}\nend)
expect_to_s %[1.as(Int32)]
Expand Down
19 changes: 15 additions & 4 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -885,18 +885,29 @@ module Crystal
end

def visit(node : MacroIf)
@str << "{% if "
if node.is_unless?
@str << "{% unless "
then_node = node.else
else_node = node.then
else
@str << "{% if "
then_node = node.then
else_node = node.else
end
node.cond.accept self
@str << " %}"

inside_macro do
node.then.accept self
then_node.accept self
end
unless node.else.nop?

unless else_node.nop?
@str << "{% else %}"
inside_macro do
node.else.accept self
else_node.accept self
end
end

@str << "{% end %}"
false
end
Expand Down
Loading