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

fix(rome_js_formatter): restrict export line break for single specifier #3726

Merged
merged 11 commits into from
Nov 16, 2022
Merged
30 changes: 22 additions & 8 deletions crates/rome_js_formatter/src/js/module/export_named_from_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@ impl FormatNodeRule<JsExportNamedFromClause> for FormatJsExportNamedFromClause {

write!(f, [l_curly_token.format(),])?;

if node_has_leading_newline(specifiers.syntax()) {
write!(f, [block_indent(&specifiers.format()),])?;
} else {
write!(
f,
[group(&soft_space_or_block_indent(&specifiers.format())),]
)?;
};
match specifiers.len() {
1 => {
if let Some(sep) = specifiers.trailing_separator() {
write!(
f,
[space(), &specifiers.format(), format_removed(&sep), space()]
)?;
} else {
write!(f, [space(), &specifiers.format(), space()])?;
}
}
_ => {
if node_has_leading_newline(specifiers.syntax()) {
write!(f, [block_indent(&specifiers.format()),])?;
} else {
write!(
f,
[group(&soft_space_or_block_indent(&specifiers.format())),]
)?;
};
}
}

write![
f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export {a,
export {
lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem,
lorem_lorem_lorem_lorem_lorem_ as ipsum_ipsum_ipsum_ipsum_ipsum_ipsum_
} from "fancy" assert { type: "json", "type2": "json", type23: "json", "type24": "json"}
} from "fancy" assert { type: "json", "type2": "json", type23: "json", "type24": "json"}

export { loooooooooooooooooooooooooooooooooooooooooooooooooong } from "loooooooooooooooooooooooooooooooooooooooooooooong";