Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Fix bug in record update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie committed Feb 16, 2023
1 parent 1146f54 commit 5e7fed0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/ditto-fmt/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,20 @@ pub fn gen_expression(expr: Expression, _needs_parens: bool) -> PrintItems {
let gen_separated_values_result =
gen_comma_sep1(updates, gen_record_field, true, force_use_new_lines);

let is_multiple_lines = gen_separated_values_result.is_multi_line_condition_ref;

let element_items = gen_separated_values_result.items.into_rc_path();
items.push_condition(conditions::if_true_or(
"dunnoYet",
is_multiple_lines.create_resolver(),
"multiLineRecordUpdate",
gen_separated_values_result
.is_multi_line_condition_ref
.create_resolver(),
{
let mut items: PrintItems = Signal::NewLine.into();
items.extend(ir_helpers::with_indent({
let mut items = PrintItems::new();
items.extend(gen_expression(target.clone(), true));
items.extend(space());
items.extend(gen_pipe(pipe.clone()));
items.push_signal(Signal::ExpectNewLine);
items.extend(element_items.into());
items
}));
Expand Down Expand Up @@ -799,5 +800,11 @@ mod tests {
assert_fmt!("{\n\tr |\n\t\t-- comment\n\t\tfoo = 2,\n}");
assert_fmt!("{ --comment\n\tr |\n\t\t-- comment\n\t\tfoo = 2,\n}");
assert_fmt!("{\n\tr |\n\t\tfoo = 2,\n\t-- comment\n}");

assert_fmt!(
"{ foo = { foo | bar = do_something_with(foo.bar) }, baz = true }",
"{\n\tfoo = {\n\t\tfoo |\n\t\t\tbar = do_something_with(foo.bar),\n\t},\n\tbaz = true,\n}",
50
);
}
}

0 comments on commit 5e7fed0

Please sign in to comment.