mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Fix when branches to use lifting as well
This commit is contained in:
parent
e068ae6b5a
commit
c4077dc971
5 changed files with 62 additions and 19 deletions
|
@ -1605,27 +1605,25 @@ fn fmt_when<'a>(
|
||||||
|
|
||||||
let inner_indent = line_indent + INDENT;
|
let inner_indent = line_indent + INDENT;
|
||||||
|
|
||||||
match expr.value {
|
let expr = expr_lift_spaces(Parens::NotNeeded, buf.text.bump(), &expr.value);
|
||||||
Expr::SpaceBefore(nested, spaces) => {
|
fmt_spaces_no_blank_lines(buf, expr.before.iter(), inner_indent);
|
||||||
fmt_spaces_no_blank_lines(buf, spaces.iter(), inner_indent);
|
if is_multiline_expr {
|
||||||
|
buf.ensure_ends_with_newline();
|
||||||
|
} else {
|
||||||
|
buf.spaces(1);
|
||||||
|
}
|
||||||
|
|
||||||
if is_multiline_expr {
|
// expr.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, inner_indent);
|
||||||
buf.ensure_ends_with_newline();
|
format_expr_only(
|
||||||
} else {
|
&expr.item,
|
||||||
buf.spaces(1);
|
buf,
|
||||||
}
|
Parens::NotNeeded,
|
||||||
|
Newlines::Yes,
|
||||||
|
inner_indent,
|
||||||
|
);
|
||||||
|
|
||||||
nested.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, inner_indent);
|
if !expr.after.is_empty() {
|
||||||
}
|
format_spaces(buf, expr.after, Newlines::Yes, inner_indent);
|
||||||
_ => {
|
|
||||||
if is_multiline_expr {
|
|
||||||
buf.ensure_ends_with_newline();
|
|
||||||
} else {
|
|
||||||
buf.spaces(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
expr.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, inner_indent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_branch_was_multiline = is_multiline_expr || is_multiline_patterns;
|
prev_branch_was_multiline = is_multiline_expr || is_multiline_patterns;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
when
|
||||||
|
0
|
||||||
|
is
|
||||||
|
B ->
|
||||||
|
t
|
|
@ -0,0 +1,36 @@
|
||||||
|
@0-17 SpaceAfter(
|
||||||
|
When(
|
||||||
|
@5-6 SpaceAfter(
|
||||||
|
Num(
|
||||||
|
"0",
|
||||||
|
),
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
[
|
||||||
|
WhenBranch {
|
||||||
|
patterns: [
|
||||||
|
@10-11 Tag(
|
||||||
|
"B",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
value: @13-17 ParensAround(
|
||||||
|
SpaceBefore(
|
||||||
|
Var {
|
||||||
|
module_name: "",
|
||||||
|
ident: "t",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
guard: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
when 0
|
||||||
|
is B->(
|
||||||
|
t)
|
|
@ -735,6 +735,7 @@ mod test_snapshots {
|
||||||
pass/when_in_parens.expr,
|
pass/when_in_parens.expr,
|
||||||
pass/when_in_parens_indented.expr,
|
pass/when_in_parens_indented.expr,
|
||||||
pass/when_newline_after_condition.expr,
|
pass/when_newline_after_condition.expr,
|
||||||
|
pass/when_newline_before_is_and_in_branch_parens.expr,
|
||||||
pass/when_result_list.expr,
|
pass/when_result_list.expr,
|
||||||
pass/when_with_alternative_patterns.expr,
|
pass/when_with_alternative_patterns.expr,
|
||||||
pass/when_with_function_application.expr,
|
pass/when_with_function_application.expr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue