Skip to content

Commit 31c0b15

Browse files
committed
fix: minor regression
1 parent 95e5e8f commit 31c0b15

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

crates/biome_html_formatter/src/html/auxiliary/opening_element.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ impl FormatNodeRule<HtmlOpeningElement> for FormatHtmlOpeningElement {
4545
r_angle_token,
4646
} = node.as_fields();
4747

48+
let l_angle_token = l_angle_token?;
4849
let name = name?;
4950
let is_whitespace_sensitive = is_element_whitespace_sensitive(f, &name);
5051
let is_canonical_html_tag = is_canonical_html_tag(&name);
5152

5253
let bracket_same_line = f.options().bracket_same_line().value();
54+
55+
// if this isn't whitespace sensitive, and there is a comment trivia
56+
// we must add a newline right after the comment.
57+
if !is_whitespace_sensitive && l_angle_token.has_leading_comments() {
58+
write!(f, [hard_line_break()])?;
59+
}
60+
5361
write!(f, [l_angle_token.format(), name.format()])?;
5462

5563
write!(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- comment --><div>
2+
<div></div>
3+
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
info: comments/inline-with-block-element.html
4+
---
5+
# Input
6+
7+
```html
8+
<!-- comment --><div>
9+
<div></div>
10+
</div>
11+
```
12+
13+
14+
=============================
15+
16+
# Outputs
17+
18+
## Output 1
19+
20+
-----
21+
Indent style: Tab
22+
Indent width: 2
23+
Line ending: LF
24+
Line width: 80
25+
Attribute Position: Auto
26+
Bracket same line: false
27+
Whitespace sensitivity: css
28+
Indent script and style: false
29+
Self close void elements: never
30+
-----
31+
32+
```html
33+
<!-- comment -->
34+
<div>
35+
<div></div>
36+
</div>
37+
```

crates/biome_html_formatter/tests/specs/prettier/html/interpolation/example.html.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ x => {
4040
```diff
4141
--- Prettier
4242
+++ Biome
43-
@@ -1,8 +1,7 @@
44-
-<!--interpolations in html should be treated as normal text-->
45-
-<div>
46-
+<!--interpolations in html should be treated as normal text--><div>
47-
Fuga magnam facilis. Voluptatem quaerat porro.{{ x => { const hello = 'world'
43+
@@ -4,5 +4,5 @@
4844
return hello; } }} Magni consectetur in et molestias neque esse voluptatibus
4945
voluptas. {{ some_variable }} Eum quia nihil nulla esse. Dolorem asperiores
5046
vero est error {{ preserve invalid interpolation }} reprehenderit voluptates
@@ -56,7 +52,8 @@ x => {
5652
# Output
5753

5854
```html
59-
<!--interpolations in html should be treated as normal text--><div>
55+
<!--interpolations in html should be treated as normal text-->
56+
<div>
6057
Fuga magnam facilis. Voluptatem quaerat porro.{{ x => { const hello = 'world'
6158
return hello; } }} Magni consectetur in et molestias neque esse voluptatibus
6259
voluptas. {{ some_variable }} Eum quia nihil nulla esse. Dolorem asperiores

0 commit comments

Comments
 (0)