Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-astro-frontmatter-fence-detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#8882](https://github.com/biomejs/biome/issues/8882) and [#9108](https://github.com/biomejs/biome/issues/9108): The Astro frontmatter lexer now correctly identifies the closing `---` fence when the frontmatter contains multi-line block comments with quote characters, strings that mix quote types (e.g. `"it's"`), or escaped quote characters (e.g. `"\"`).
374 changes: 303 additions & 71 deletions crates/biome_html_parser/src/lexer/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
/*
---
*/
const x = 1;
---

<h1>Hi</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```astro
---
/*
---
*/
const x = 1;
---

<h1>Hi</h1>

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: AstroFrontmatterElement {
l_fence_token: FENCE@0..3 "---" [] [],
content: AstroEmbeddedContent {
content_token: HTML_LITERAL@3..27 "/*\n---\n*/\nconst x = 1;\n" [Newline("\n")] [],
},
r_fence_token: FENCE@27..30 "---" [] [],
},
directive: missing (optional),
html: HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@30..33 "<" [Newline("\n"), Newline("\n")] [],
name: HtmlTagName {
value_token: HTML_LITERAL@33..35 "h1" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@35..36 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@36..38 "Hi" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@38..39 "<" [] [],
slash_token: SLASH@39..40 "/" [] [],
name: HtmlTagName {
value_token: HTML_LITERAL@40..42 "h1" [] [],
},
r_angle_token: R_ANGLE@42..43 ">" [] [],
},
},
],
eof_token: EOF@43..44 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..44
0: (empty)
1: ASTRO_FRONTMATTER_ELEMENT@0..30
0: FENCE@0..3 "---" [] []
1: ASTRO_EMBEDDED_CONTENT@3..27
0: HTML_LITERAL@3..27 "/*\n---\n*/\nconst x = 1;\n" [Newline("\n")] []
2: FENCE@27..30 "---" [] []
2: (empty)
3: HTML_ELEMENT_LIST@30..43
0: HTML_ELEMENT@30..43
0: HTML_OPENING_ELEMENT@30..36
0: L_ANGLE@30..33 "<" [Newline("\n"), Newline("\n")] []
1: HTML_TAG_NAME@33..35
0: HTML_LITERAL@33..35 "h1" [] []
2: HTML_ATTRIBUTE_LIST@35..35
3: R_ANGLE@35..36 ">" [] []
1: HTML_ELEMENT_LIST@36..38
0: HTML_CONTENT@36..38
0: HTML_LITERAL@36..38 "Hi" [] []
2: HTML_CLOSING_ELEMENT@38..43
0: L_ANGLE@38..39 "<" [] []
1: SLASH@39..40 "/" [] []
2: HTML_TAG_NAME@40..42
0: HTML_LITERAL@40..42 "h1" [] []
3: R_ANGLE@42..43 ">" [] []
4: EOF@43..44 "" [Newline("\n")] []

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
// ---
const x = 1;
---

<h1>Hi</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---

## Input

```astro
---
// ---
const x = 1;
---

<h1>Hi</h1>

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: AstroFrontmatterElement {
l_fence_token: FENCE@0..3 "---" [] [],
content: AstroEmbeddedContent {
content_token: HTML_LITERAL@3..24 "// ---\nconst x = 1;\n" [Newline("\n")] [],
},
r_fence_token: FENCE@24..27 "---" [] [],
},
directive: missing (optional),
html: HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@27..30 "<" [Newline("\n"), Newline("\n")] [],
name: HtmlTagName {
value_token: HTML_LITERAL@30..32 "h1" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@32..33 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@33..35 "Hi" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@35..36 "<" [] [],
slash_token: SLASH@36..37 "/" [] [],
name: HtmlTagName {
value_token: HTML_LITERAL@37..39 "h1" [] [],
},
r_angle_token: R_ANGLE@39..40 ">" [] [],
},
},
],
eof_token: EOF@40..41 "" [Newline("\n")] [],
}
```

## CST

```
0: HTML_ROOT@0..41
0: (empty)
1: ASTRO_FRONTMATTER_ELEMENT@0..27
0: FENCE@0..3 "---" [] []
1: ASTRO_EMBEDDED_CONTENT@3..24
0: HTML_LITERAL@3..24 "// ---\nconst x = 1;\n" [Newline("\n")] []
2: FENCE@24..27 "---" [] []
2: (empty)
3: HTML_ELEMENT_LIST@27..40
0: HTML_ELEMENT@27..40
0: HTML_OPENING_ELEMENT@27..33
0: L_ANGLE@27..30 "<" [Newline("\n"), Newline("\n")] []
1: HTML_TAG_NAME@30..32
0: HTML_LITERAL@30..32 "h1" [] []
2: HTML_ATTRIBUTE_LIST@32..32
3: R_ANGLE@32..33 ">" [] []
1: HTML_ELEMENT_LIST@33..35
0: HTML_CONTENT@33..35
0: HTML_LITERAL@33..35 "Hi" [] []
2: HTML_CLOSING_ELEMENT@35..40
0: L_ANGLE@35..36 "<" [] []
1: SLASH@36..37 "/" [] []
2: HTML_TAG_NAME@37..39
0: HTML_LITERAL@37..39 "h1" [] []
3: R_ANGLE@39..40 ">" [] []
4: EOF@40..41 "" [Newline("\n")] []

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
/**
* In this comment, if you add any string opening or closing, such as an apostrophe, the file will show
* a bunch of errors. Doesn't (remove the apostrophe in the previous word to fix) that stink?
*/
import type { HTMLAttributes } from "astro/types";
type Props = HTMLAttributes<"div">;
const { class: className, ...rest } = Astro.props;
---

<div
class="some-classes"
data-state="closed"
style="animation: none;"
data-slot="accordion-content"
{...rest}
>
<div class="pt-0 pb-4">
<slot />
</div>
</div>
Loading