diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b0204c5f57..3b65e50a3f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom #### Bug fixes +- Fix placement of comments before `*` token in generator methods with decorators. [#1537](https://github.com/biomejs/biome/pull/1537) Contributed by @ah-yu + - Fix [#1406](https://github.com/biomejs/biome/issues/1406). Ensure comments before the `async` keyword are placed before it. Contributed by @ah-yu - Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep diff --git a/crates/biome_js_formatter/src/comments.rs b/crates/biome_js_formatter/src/comments.rs index 4c4dbde0d427..db7429917799 100644 --- a/crates/biome_js_formatter/src/comments.rs +++ b/crates/biome_js_formatter/src/comments.rs @@ -1256,7 +1256,8 @@ fn handle_import_export_specifier_comment( } } -/// Ensure that comments before the `async`` keyword are placed just before it. +/// Attach comments before the `async` keyword or `*` token to the preceding node if it exists +/// to ensure these comments are placed before the `async` keyword or `*` token. /// ```javascript /// class Foo { /// @decorator() @@ -1270,7 +1271,10 @@ fn handle_class_method_comment( match enclosing_node.kind() { JsSyntaxKind::JS_METHOD_CLASS_MEMBER => { if let Some(following_token) = comment.following_token() { - if following_token.kind() == JsSyntaxKind::ASYNC_KW { + if matches!( + following_token.kind(), + JsSyntaxKind::ASYNC_KW | JsSyntaxKind::STAR + ) { if let Some(preceding) = comment.preceding_node() { return CommentPlacement::trailing(preceding.clone(), comment); } diff --git a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap index 2835f912cad5..a8e5c6441430 100644 --- a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap +++ b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap @@ -214,7 +214,8 @@ class Foo { /*after*/ async method() {} @decorator.method(value) /*before*/ - */*after*/ method() {} + /*after*/ + *method() {} @decorator.method(value) /*before*/ get /*after*/ getter() {} @decorator.method(value) /*before*/ diff --git a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap index dc650d8ceef0..61f7045c113f 100644 --- a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap +++ b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap @@ -212,7 +212,8 @@ class Foo { /*after*/ async method() {} @decorator /*before*/ - */*after*/ method() {} + /*after*/ + *method() {} @decorator.method(value) /*before*/ get /*after*/ getter() {} @decorator /*before*/ diff --git a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap index 303665e1278e..a9ee180e6193 100644 --- a/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap +++ b/crates/biome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap @@ -202,7 +202,8 @@ class Foo { /*after*/ async method() {} @dec /*before*/ - */*after*/ method() {} + /*after*/ + *method() {} @dec /*before*/ get /*after*/ getter() {} @dec /*before*/ diff --git a/crates/biome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap b/crates/biome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap index 2bc85fd6d26d..542e7943057d 100644 --- a/crates/biome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap +++ b/crates/biome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap @@ -51,17 +51,6 @@ class Something2 { ```diff --- Prettier +++ Biome -@@ -12,8 +12,8 @@ - - class Foo3 { - @foo -- // comment -- *method() {} -+ *// comment -+ method() {} - } - - class Foo4 { @@ -30,6 +30,6 @@ class Something2 { @@ -90,8 +79,8 @@ class Foo2 { class Foo3 { @foo - *// comment - method() {} + // comment + *method() {} } class Foo4 { diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 979993c68923..4e6082891bef 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -32,6 +32,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom #### Bug fixes +- Fix placement of comments before `*` token in generator methods with decorators. [#1537](https://github.com/biomejs/biome/pull/1537) Contributed by @ah-yu + - Fix [#1406](https://github.com/biomejs/biome/issues/1406). Ensure comments before the `async` keyword are placed before it. Contributed by @ah-yu - Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep