Fix expr_lift_spaces of Closure

This commit is contained in:
Joshua Warner 2024-12-02 18:24:54 -08:00
parent 19f8cc532a
commit cae47cf2a6
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 49 additions and 6 deletions

View file

@ -999,10 +999,24 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
after: final_expr_lifted.after, after: final_expr_lifted.after,
} }
} }
Expr::If { .. } | Expr::When(_, _) | Expr::Return(_, _) | Expr::Closure(..) => { Expr::Closure(pats, body) => {
let res = if parens == Parens::InApply if parens == Parens::InApply {
|| (parens == Parens::InApplyLastArg && !matches!(expr, Expr::Closure(..))) return Spaces {
{ before: &[],
item: Expr::ParensAround(arena.alloc(*expr)),
after: &[],
};
}
let body_lifted = expr_lift_spaces_after(Parens::NotNeeded, arena, &body.value);
Spaces {
before: &[],
item: Expr::Closure(pats, arena.alloc(Loc::at(body.region, body_lifted.item))),
after: body_lifted.after,
}
}
Expr::If { .. } | Expr::When(_, _) | Expr::Return(_, _) => {
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
Spaces { Spaces {
before: &[], before: &[],
item: Expr::ParensAround(arena.alloc(*expr)), item: Expr::ParensAround(arena.alloc(*expr)),
@ -1014,8 +1028,7 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
item: *expr, item: *expr,
after: &[], after: &[],
} }
}; }
dbg!(res)
} }
Expr::Backpassing(pats, call, continuation) => { Expr::Backpassing(pats, call, continuation) => {
let pats = arena.alloc_slice_copy(pats); let pats = arena.alloc_slice_copy(pats);

View file

@ -0,0 +1,25 @@
SpaceAfter(
Closure(
[
@1-2 Tag(
"L",
),
],
@4-10 ParensAround(
SpaceAfter(
Tag(
"E",
),
[
Newline,
LineComment(
"",
),
],
),
),
),
[
Newline,
],
)

View file

@ -328,6 +328,7 @@ mod test_snapshots {
pass/body_with_unneeded_parens.expr, pass/body_with_unneeded_parens.expr,
pass/call_bang.expr, pass/call_bang.expr,
pass/call_bang_no_space.expr, pass/call_bang_no_space.expr,
pass/capture_body_parens_comment.expr,
pass/closure_in_apply_in_binop.expr, pass/closure_in_apply_in_binop.expr,
pass/closure_in_binop_with_spaces.expr, pass/closure_in_binop_with_spaces.expr,
pass/closure_pat_reccord_comment.expr, pass/closure_pat_reccord_comment.expr,