Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 15 additions & 22 deletions crates/oxc_formatter/src/utils/member_chain/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'a, 'b> MemberChainGroup<'a, 'b> {
let interned = f.intern(&FormatMemberChainGroup { group: self })?;

if tail {
self.needs_empty_line.set(self.needs_empty_line_before(f));
self.set_needs_empty_line(self.needs_empty_line_before(f));
}

if let Some(interned) = interned {
Expand Down Expand Up @@ -199,28 +199,21 @@ impl<'a, 'b> MemberChainGroup<'a, 'b> {
// Check whether has more than 1 continuous new lines before the operator (`.`)
let start = expression.object().span().end;
let mut end = expression.property().span().start;
let mut comments = f.comments().comments_in_range(start, end).iter();
let mut last_comment_span = comments.next_back();

while start < end {
// Skip comments that are after the operator (`.`)
if let Some(last_comment) = last_comment_span
&& last_comment.span.end == end
{
end = last_comment.span.start - 1;
last_comment_span = comments.next_back();
continue;
} else if matches!(source.byte_at(end), Some(b'.')) {
// Found the operator, stop the loop
break;
}

end -= 1;
}

// Skip comments that are before the operator (`.`)
if let Some(comment) = comments.next() {
end = comment.span.start;
// We should found the real `end` position that is before comments and it is not after the operator `.`
if let Some(printed_comment) = f
.comments()
.printed_comments()
.iter()
.rev()
.take_while(|c| start <= c.span.start && c.span.end < end)
.last()
{
end = printed_comment.span.start;
} else if let Some(first_comment) =
f.comments().comments_before_character(start, b'.').first()
{
end = first_comment.span.start;
}

// Count the number of continuous new lines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Promise.all(writeIconFiles)
// TO DO -- END
.then(() => writeRegistry())

Promise.all(writeIconFiles)

// TO DO -- END
.then(() => writeRegistry())

Promise.all(writeIconFiles)
// TO DO -- END

.then(() => writeRegistry())
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
Promise.all(writeIconFiles)
// TO DO -- END
.then(() => writeRegistry())

Promise.all(writeIconFiles)

// TO DO -- END
.then(() => writeRegistry())

Promise.all(writeIconFiles)
// TO DO -- END

.then(() => writeRegistry())

==================== Output ====================
Promise.all(writeIconFiles)
// TO DO -- END
.then(() => writeRegistry());

Promise.all(writeIconFiles)

// TO DO -- END
.then(() => writeRegistry());

Promise.all(writeIconFiles)
// TO DO -- END

.then(() => writeRegistry());

===================== End =====================
Loading