--- a/crates/jrsonnet-evaluator/src/obj/mod.rs +++ b/crates/jrsonnet-evaluator/src/obj/mod.rs @@ -239,7 +239,6 @@ struct ObjValueInner { cores: Vec, assertions_ran: Cell, - #[trace(skip)] has_assertions: bool, value_cache: RefCell>, } --- a/crates/jrsonnet-formatter/src/lib.rs +++ b/crates/jrsonnet-formatter/src/lib.rs @@ -450,6 +450,63 @@ fn print(&self, out: &mut PrintItems) { match self { Self::ObjBodyComp(l) => { + fn gen_obj_comp( + members: Vec>, + member_end_comments: EndingComments, + compspecs: Vec>, + multi_line: ConditionResolver, + ) -> PrintItems { + let mut out = PrintItems::new(); + for mem in members { + if mem.should_start_with_newline { + p!(out, nl); + } + format_comments( + &mem.before_trivia, + CommentLocation::AboveItem, + &mut out, + ); + p!(&mut out, {mem.value}); + p!(out, if("trailing comma", multi_line, str(","))); + format_comments( + &mem.inline_trivia, + CommentLocation::ItemInline, + &mut out, + ); + p!(out, if_else("member-comp sep", multi_line, nl)(sonl)); + } + + if member_end_comments.should_start_with_newline { + p!(out, nl); + } + format_comments( + &member_end_comments.trivia, + CommentLocation::EndOfItems, + &mut out, + ); + + let mut compspecs = compspecs.into_iter().peekable(); + while let Some(mem) = compspecs.next() { + if mem.should_start_with_newline { + p!(out, nl); + } + format_comments( + &mem.before_trivia, + CommentLocation::AboveItem, + &mut out, + ); + p!(&mut out, { mem.value }); + format_comments( + &mem.inline_trivia, + CommentLocation::ItemInline, + &mut out, + ); + p!(out, if_else("comp spec sep", multi_line, nl)(sonl)); + } + + out + } + let (children, mut end_comments) = children_between::( l.syntax().clone(), l.l_brace_token().map(Into::into).as_ref(), @@ -464,23 +521,8 @@ None, ); let trailing_for_comp = end_comments.extract_trailing(); - p!(out, str("{") >i nl); - for mem in children { - if mem.should_start_with_newline { - p!(out, nl); - } - format_comments(&mem.before_trivia, CommentLocation::AboveItem, out); - p!(out, {mem.value} str(",")); - format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out); - p!(out, nl); - } - if end_comments.should_start_with_newline { - p!(out, nl); - } - format_comments(&end_comments.trivia, CommentLocation::EndOfItems, out); - - let (compspecs, end_comments) = children_between::( + let (compspecs, comp_end_comments) = children_between::( l.syntax().clone(), l.member_comps() .last() @@ -491,20 +533,35 @@ l.r_brace_token().map(Into::into).as_ref(), Some(trailing_for_comp), ); - for mem in compspecs { - if mem.should_start_with_newline { - p!(out, nl); - } - format_comments(&mem.before_trivia, CommentLocation::AboveItem, out); - p!(out, { mem.value }); - format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out); - } - if end_comments.should_start_with_newline { - p!(out, nl); - } - format_comments(&end_comments.trivia, CommentLocation::EndOfItems, out); - p!(out, nl { fn gen_members( --- a/crates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snap +++ b/crates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snap @@ -6,8 +6,5 @@ { arr: [x for x in [ 1, 2, 3 ]], filtered: [x for x in [ 1, 2, 3, 4, 5 ] if x > 2], - obj: { - [k]: v, - for k in [ 'a', 'b' ]for v in [ 1, 2 ] - }, + obj: { [k]: v for k in [ 'a', 'b' ] for v in [ 1, 2 ] }, }