Don't do empty record destructure elision when the body is itself Defs

This commit is contained in:
Joshua Warner 2024-12-02 17:26:32 -08:00
parent cabe67f88d
commit 89a64fed74
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 83 additions and 0 deletions

View file

@ -1039,6 +1039,7 @@ pub fn fmt_body<'a>(
&& collection.is_empty() && collection.is_empty()
&& pattern_extracted.before.iter().all(|s| s.is_newline()) && pattern_extracted.before.iter().all(|s| s.is_newline())
&& pattern_extracted.after.iter().all(|s| s.is_newline()) && pattern_extracted.after.iter().all(|s| s.is_newline())
&& !matches!(body.extract_spaces().item, Expr::Defs(..))
} else { } else {
false false
}; };

View file

@ -0,0 +1,73 @@
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-9,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Body(
@0-2 RecordDestructure(
[],
),
@5-9 SpaceBefore(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@5-6,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@5-6 Var {
module_name: "",
ident: "p",
},
),
],
},
@8-9 SpaceBefore(
Var {
module_name: "",
ident: "t",
},
[
Newline,
],
),
),
[
Newline,
],
),
),
],
},
@10-11 SpaceBefore(
Tag(
"J",
),
[
Newline,
],
),
)

View file

@ -604,6 +604,7 @@ mod test_snapshots {
pass/spaces_inside_empty_list.expr, pass/spaces_inside_empty_list.expr,
pass/standalone_module_defs.moduledefs, pass/standalone_module_defs.moduledefs,
pass/stmt_parens_minus.expr, pass/stmt_parens_minus.expr,
pass/stmts_in_empty_record_assignment.expr,
pass/str_block_multiple_newlines.expr, pass/str_block_multiple_newlines.expr,
pass/string_without_escape.expr, pass/string_without_escape.expr,
pass/sub_var_with_spaces.expr, pass/sub_var_with_spaces.expr,