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

fix(rome_js_parser): TsPropertySignatureClassMember with initializer #3003

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions crates/rome_js_formatter/src/utils/assignment_like.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::js::auxiliary::initializer_clause::FormatJsInitializerClauseOptions;
use crate::js::expressions::arrow_function_expression::FormatJsArrowFunctionExpressionOptions;
use crate::prelude::*;
use crate::utils::member_chain::is_member_call_chain;
use crate::utils::object::write_member_name;
Expand Down Expand Up @@ -439,7 +438,7 @@ impl JsAnyAssignmentLike {
let width = write_member_name(&name.into(), f)?;
let text_width_for_break =
(u8::from(f.options().tab_width()) + MIN_OVERLAP_FOR_BREAK) as usize;
width < text_width_for_break && property_annotation.is_none()
width < text_width_for_break
};

write!(f, [property_annotation.format()])?;
Expand Down Expand Up @@ -918,7 +917,7 @@ impl Format<JsFormatContext> for JsAnyAssignmentLike {
self.write_operator(f)?;
}

match layout {
match &layout {
AssignmentLikeLayout::OnlyLeft => Ok(()),
AssignmentLikeLayout::Fluid => {
let group_id = f.group_id("assignment_like");
Expand Down Expand Up @@ -993,7 +992,7 @@ impl Format<JsFormatContext> for JsAnyAssignmentLike {
/// [Prettier applies]: https://github.com/prettier/prettier/blob/a043ac0d733c4d53f980aa73807a63fc914f23bd/src/language-js/print/assignment.js#L329
fn is_poorly_breakable_member_or_call_chain(
expression: &JsAnyExpression,
f: &Formatter<JsFormatContext>,
f: &mut Formatter<JsFormatContext>,
) -> SyntaxResult<bool> {
let threshold = f.options().line_width().value() / 4;

Expand Down Expand Up @@ -1042,11 +1041,7 @@ fn is_poorly_breakable_member_or_call_chain(
}

for call_expression in call_expressions {
if is_member_call_chain(
call_expression.clone(),
f.comments(),
f.options().tab_width(),
)? {
if is_member_call_chain(&call_expression, f)? {
return Ok(false);
}

Expand Down Expand Up @@ -1190,13 +1185,9 @@ pub(crate) fn with_assignment_layout(
impl Format<JsFormatContext> for WithAssignmentLayout<'_> {
fn fmt(&self, f: &mut Formatter<JsFormatContext>) -> FormatResult<()> {
match self.expression {
JsAnyExpression::JsArrowFunctionExpression(arrow) => arrow
.format()
.with_options(FormatJsArrowFunctionExpressionOptions {
assignment_layout: self.layout,
..FormatJsArrowFunctionExpressionOptions::default()
})
.fmt(f),
JsAnyExpression::JsArrowFunctionExpression(arrow) => {
arrow.format().with_options(self.layout).fmt(f)
}
expression => expression.format().fmt(f),
}
}
Expand Down