Skip to content

Commit

Permalink
julefmt: improve conditional formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 24, 2024
1 parent 6e20327 commit 9d049de
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,14 @@ impl ScopeFormatter {
fn conditional_case(self, mut c: &ast::If) {
self.write("if ")
self.fmt.format_expr(c.expr)
self.write(" ")
self.format(c.scope)
self.write(" {\n")
if c.scope.stmts.len > 0 {
self.fmt.add_indent()
self.format_stmts(c.scope.stmts)
self.fmt.done_indent()
}
self.write(self.fmt.indent)
self.write("}")
}

fn conditional(self, mut c: &ast::Conditional) {
Expand All @@ -801,8 +807,14 @@ impl ScopeFormatter {
self.conditional_case(t)
}
if c.default != nil {
self.write(" else ")
self.format(c.default.scope)
self.write(" else {\n")
if c.default.scope.stmts.len > 0 {
self.fmt.add_indent()
self.format_stmts(c.default.scope.stmts)
self.fmt.done_indent()
}
self.write(self.fmt.indent)
self.write("}")
}
}

Expand Down

0 comments on commit 9d049de

Please sign in to comment.