Skip to content

Handle nested Expressions within blocks and conditional logic #15613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
46 changes: 46 additions & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,52 @@ describe "ASTNode#to_s" do
end
CR

expect_to_s <<-CR
{%
a = 1

if true
b = 2
c = 3
end

d = 4
%}
CR

expect_to_s <<-CR
{%
a = 1

unless false
b = 2
c = 3
end

d = 4
%}
CR

expect_to_s <<-CR
{%
arr.each do
b = 2
a = 1
end

c = 3
%}
CR

expect_to_s <<-CR
{%
arr.each do
b = 2
a = 1
end
%}
CR

expect_to_s %(asm("nop" ::::))
expect_to_s %(asm("nop" : "a"(1), "b"(2) : "c"(3), "d"(4) : "e", "f" : "volatile", "alignstack", "intel"))
expect_to_s %(asm("nop" :: "c"(3), "d"(4) ::))
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ module Crystal
newline
accept_with_indent(node.else)
end
newline unless @write_trailing_newline
append_indent
@str << "end"
false
Expand Down Expand Up @@ -1134,6 +1135,7 @@ module Crystal
newline
accept_with_indent(node.body)

newline unless @write_trailing_newline
append_indent
@str << "end"

Expand Down
Loading