Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Fix out of order printing for union/intersection type
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 2, 2022
1 parent 2ac2775 commit a464b8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ impl FormatNodeFields<JsSwitchStatement> for FormatNodeRule<JsSwitchStatement> {
r_curly_token,
} = node.as_fields();

let format_cases = format_once(|f| {
let format_cases = format_with(|f| {
if cases.is_empty() {
write!(f, [hard_line_break()])?;
} else {
let mut join = f.join_nodes_with_hardline();

for case in cases {
for case in &cases {
join.entry(case.syntax(), &case.format());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_formatter/src/ts/types/intersection_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl FormatNodeFields<TsIntersectionType> for FormatNodeRule<TsIntersectionType>
types,
} = node.as_fields();

let leading_separator_token = format_once(|f| {
match leading_separator_token {
let leading_separator_token = format_with(|f| {
match &leading_separator_token {
Some(token) => {
// The SyntaxToken is converted into a FormatElement using
// Token::from to strip the token's trivia pieces which are
Expand Down
11 changes: 5 additions & 6 deletions crates/rome_js_formatter/src/ts/types/union_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl FormatNodeFields<TsUnionType> for FormatNodeRule<TsUnionType> {
types,
} = node.as_fields();

let format_leading_separator_token = format_once(|f| {
match leading_separator_token {
let format_leading_separator_token = format_with(|f| {
match &leading_separator_token {
Some(token) => {
// The SyntaxToken is converted into a FormatElement using
// Token::from to strip the token's trivia pieces which are
Expand All @@ -22,9 +22,9 @@ impl FormatNodeFields<TsUnionType> for FormatNodeRule<TsUnionType> {
write!(
f,
[format_replaced(
&token,
token,
&if_group_breaks(format_args!(
format_trimmed_token(&token),
format_trimmed_token(token),
space_token()
))
)]
Expand All @@ -38,7 +38,7 @@ impl FormatNodeFields<TsUnionType> for FormatNodeRule<TsUnionType> {
});

let mut buffer = VecBuffer::new(f.state_mut());
write!(buffer, [types.format()])?;
write!(buffer, [format_leading_separator_token, types.format()])?;

let types = buffer.into_element();

Expand All @@ -51,7 +51,6 @@ impl FormatNodeFields<TsUnionType> for FormatNodeRule<TsUnionType> {
[
group_elements(indent(format_args![
soft_line_break(),
format_leading_separator_token,
format_once(|f| {
f.write_element(leading_comments)?;
f.write_element(types)
Expand Down

0 comments on commit a464b8d

Please sign in to comment.