You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to our printing comments architecture is different from `Biome`, so it may incorrectly implement the comments checking parts. But fortunately, those will be caught as the port work gradually nears done.
let forward = self.comments[index].span.end < start;
48
-
// Skip comments that before start
49
-
if forward {
50
-
while index < self.comments.len() - 1{
51
-
ifself.comments[index + 1].span.end <= start {
52
-
index += 1;
53
-
continue;
54
-
}
55
-
break;
56
-
}
57
-
}else{
58
-
// Find comments that after start
59
-
while index > 0{
60
-
ifself.comments[index - 1].span.start > start {
61
-
index -= 1;
62
-
continue;
63
-
}
64
-
break;
65
-
}
57
+
// You may want to check comments after your are printing the node,
58
+
// so it may have a lot of comments that don't print yet.
59
+
//
60
+
// Skip comments that before pos
61
+
while index < self.comments.len() - 1 && self.comments[index].span.end < pos {
62
+
index += 1;
66
63
}
67
64
68
-
&self.comments[index..]
65
+
ifself.comments[index].span.end < pos {
66
+
&self.comments[index + 1..]
67
+
}else{
68
+
&self.comments[index..]
69
+
}
69
70
}
70
71
71
72
#[inline]
@@ -243,6 +244,100 @@ impl<'a> Comments<'a> {
243
244
pubfnincrement_printed_count(&mutself){
244
245
self.printed_count += 1;
245
246
}
247
+
248
+
pubfnget_trailing_comments(
249
+
&self,
250
+
enclosing_node:&SiblingNode<'a>,
251
+
preceding_node:&SiblingNode<'a>,
252
+
following_node:Option<&SiblingNode<'a>>,
253
+
) -> &'a[Comment]{
254
+
// The preceding_node is the callee of the call expression or new expression, let following node to print it.
255
+
// Based on https://github.com/prettier/prettier/blob/7584432401a47a26943dd7a9ca9a8e032ead7285/src/language-js/comments/handle-comments.js#L726-L741
// Based on https://github.com/prettier/prettier/blob/7584432401a47a26943dd7a9ca9a8e032ead7285/src/language-js/comments/handle-comments.js#L852-L883
299
+
ifmatches!(
300
+
enclosing_node,
301
+
SiblingNode::VariableDeclarator(_)
302
+
| SiblingNode::AssignmentExpression(_)
303
+
| SiblingNode::TSTypeAliasDeclaration(_)
304
+
) && (comment.is_block()
305
+
|| matches!(
306
+
following_node,
307
+
SiblingNode::ObjectExpression(_)
308
+
| SiblingNode::ArrayExpression(_)
309
+
| SiblingNode::TSTypeLiteral(_)
310
+
| SiblingNode::TemplateLiteral(_)
311
+
| SiblingNode::TaggedTemplateExpression(_)
312
+
))
313
+
{
314
+
return&[];
315
+
}
316
+
return&comments[..=comment_index];
317
+
}
318
+
319
+
comment_index += 1;
320
+
}
321
+
322
+
if comment_index == 0{
323
+
// No comments to print
324
+
return&[];
325
+
}
326
+
327
+
letmut gap_end = following_span.start;
328
+
for cur_index in(0..comment_index).rev(){
329
+
let comment = &comments[cur_index];
330
+
let gap_str = Span::new(comment.span.end, gap_end).source_text(source_text);
331
+
if gap_str.as_bytes().iter().all(|&b| matches!(b,b' ' | b'(')){
332
+
gap_end = comment.span.start;
333
+
}else{
334
+
// If there is a non-whitespace character, we stop here
0 commit comments