Skip to content

Commit

Permalink
challenge(formatter): assignment with await/yield do not break
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-teles committed Nov 20, 2023
1 parent 69a097f commit 286ea91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
6 changes: 4 additions & 2 deletions crates/biome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl CommentStyle for JsCommentStyle {
.or_else(handle_method_comment)
.or_else(handle_for_comment)
.or_else(handle_root_comments)
.or_else(handle_array_hole_comment)
.or_else(handle_variable_declarator_comment)
.or_else(handle_parameter_comment)
.or_else(handle_labelled_statement_comment)
Expand All @@ -127,7 +126,6 @@ impl CommentStyle for JsCommentStyle {
.or_else(handle_for_comment)
.or_else(handle_root_comments)
.or_else(handle_parameter_comment)
.or_else(handle_array_hole_comment)
.or_else(handle_labelled_statement_comment)
.or_else(handle_call_expression_comment)
.or_else(handle_mapped_type_comment)
Expand Down Expand Up @@ -181,6 +179,10 @@ fn handle_array_hole_comment(
comment: DecoratedComment<JsLanguage>,
) -> CommentPlacement<JsLanguage> {
if let Some(array_hole) = comment.preceding_node().and_then(JsArrayHole::cast_ref) {
if comment.kind().is_line() {
return CommentPlacement::Default(comment);
}

CommentPlacement::leading(array_hole.into_syntax(), comment)
} else {
CommentPlacement::Default(comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,19 @@ const numberWithHoles2 = [
```diff
--- Prettier
+++ Biome
@@ -2,13 +2,13 @@
7234932941,
7234932722,
7234932312,
+ // comment before a hole 1
,
- // comment before a hole 1
7234932841,
,
7234932843,
- ,
// comment after a hole 1
+ ,
7234932436,
];

@@ -16,13 +16,13 @@
0x234932941,
0x234932722,
0x234932312,
-
+ // comment before a hole 2
,
- // comment before a hole 2
// comment before a hole 2
0x234932841,
,
0x234932843,
- ,
// comment after a hole 2
+ ,
,
+
// comment after a hole 2
0x234932436,
];
```
Expand All @@ -86,28 +68,28 @@ const numberWithHoles1 = [
7234932941,
7234932722,
7234932312,
// comment before a hole 1
,
// comment before a hole 1
7234932841,
,
7234932843,
// comment after a hole 1
,
// comment after a hole 1
7234932436,
];

const numberWithHoles2 = [
0x234932941,
0x234932722,
0x234932312,
// comment before a hole 2
,
// comment before a hole 2
0x234932841,
,
0x234932843,
// comment after a hole 2
,

// comment after a hole 2
0x234932436,
];
```
Expand Down

0 comments on commit 286ea91

Please sign in to comment.