Skip to content

Commit a600bf5

Browse files
committed
fix(formatter): correct printing comments for TaggedTemplateExpression (#15241)
1 parent 880b259 commit a600bf5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

crates/oxc_formatter/src/write/template.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,22 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TemplateLiteral<'a>> {
3737
impl<'a> FormatWrite<'a> for AstNode<'a, TaggedTemplateExpression<'a>> {
3838
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
3939
// Format the tag and type arguments
40-
write!(f, [self.tag(), self.type_arguments(), line_suffix_boundary()])?;
40+
write!(f, [self.tag(), self.type_arguments()])?;
4141

4242
let quasi = self.quasi();
4343

44-
quasi.format_leading_comments(f);
44+
let comments = f.context().comments().comments_before(quasi.span.start);
45+
if !comments.is_empty() {
46+
write!(
47+
f,
48+
[group(&format_args!(
49+
soft_line_break_or_space(),
50+
FormatLeadingComments::Comments(comments)
51+
))]
52+
)?;
53+
}
54+
55+
write!(f, [line_suffix_boundary()])?;
4556

4657
if let Some(result) = try_format_embedded_template(self, f) {
4758
result

tasks/prettier_conformance/snapshots/prettier.js.snap.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 693/749 (92.52%)
1+
js compatibility: 695/749 (92.79%)
22

33
# Failed
44

@@ -16,8 +16,6 @@ js compatibility: 693/749 (92.52%)
1616
| js/comments/function-declaration.js | 💥💥 | 92.80% |
1717
| js/comments/if.js | 💥💥 | 74.83% |
1818
| js/comments/return-statement.js | 💥💥 | 98.28% |
19-
| js/comments/tagged-template-literal.js | 💥💥 | 92.86% |
20-
| js/comments/tagged-template-literal/11662.js | 💥 | 80.00% |
2119
| js/conditional/comments.js | 💥✨ | 23.69% |
2220
| js/conditional/new-ternary-examples.js | 💥✨ | 20.14% |
2321
| js/conditional/new-ternary-spec.js | 💥✨ | 24.35% |

tasks/prettier_conformance/snapshots/prettier.ts.snap.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 542/598 (90.64%)
1+
ts compatibility: 543/598 (90.80%)
22

33
# Failed
44

@@ -23,7 +23,6 @@ ts compatibility: 542/598 (90.64%)
2323
| typescript/class-comment/class-implements.ts | 💥 | 98.89% |
2424
| typescript/class-comment/declare.ts | 💥 | 84.62% |
2525
| typescript/class-comment/generic.ts | 💥 | 92.00% |
26-
| typescript/comments/11662.ts | 💥 | 80.00% |
2726
| typescript/comments/16121.ts | 💥 | 72.46% |
2827
| typescript/comments/mapped_types.ts | 💥 | 96.77% |
2928
| typescript/comments/method_types.ts | 💥 | 82.05% |

0 commit comments

Comments
 (0)