Thanks to visit codestin.com
Credit goes to github.com

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
12 changes: 12 additions & 0 deletions .changeset/fix-astro-frontmatter-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@biomejs/biome": patch
---

Fixed a regression in Astro frontmatter parsing where comments inside quoted strings were incorrectly detected as actual comments. This caused the parser to prematurely terminate frontmatter parsing when encountering strings like `const test = "//";`.
For example, the following Astro frontmatter now parses correctly:

```astro
---
const test = "// not a real comment";
---
```
9 changes: 7 additions & 2 deletions crates/biome_html_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,13 @@ impl QuotesSeen {
return; // Don't track quotes inside comments
}

// Check for comment entry
if self.prev_byte == Some(b'/') && (byte == b'/' || byte == b'*') {
// Check for comment entry - but only if we're not inside quotes
if self.prev_byte == Some(b'/')
&& (byte == b'/' || byte == b'*')
&& self.single == 0
&& self.double == 0
&& self.template == 0
{
self.inside_comment = true;
self.prev_byte = Some(byte);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
const test = "//";
---

<div>{test}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```astro
---
const test = "//";
---

<div>{test}</div>

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
frontmatter: AstroFrontmatterElement {
l_fence_token: [email protected] "---" [] [],
content: AstroEmbeddedContent {
content_token: [email protected] "const test = \"//\";\n" [Newline("\n")] [],
},
r_fence_token: [email protected] "---" [] [],
},
directive: missing (optional),
html: HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: [email protected] "<" [Newline("\n"), Newline("\n")] [],
name: HtmlTagName {
value_token: [email protected] "div" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: [email protected] ">" [] [],
},
children: HtmlElementList [
HtmlSingleTextExpression {
l_curly_token: [email protected] "{" [] [],
expression: HtmlTextExpression {
html_literal_token: [email protected] "test" [] [],
},
r_curly_token: [email protected] "}" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: [email protected] "<" [] [],
slash_token: [email protected] "/" [] [],
name: HtmlTagName {
value_token: [email protected] "div" [] [],
},
r_angle_token: [email protected] ">" [] [],
},
},
],
eof_token: [email protected] "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: [email protected]
0: [email protected] "---" [] []
1: [email protected]
0: [email protected] "const test = \"//\";\n" [Newline("\n")] []
2: [email protected] "---" [] []
2: (empty)
3: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Newline("\n")] []
1: [email protected]
0: [email protected] "div" [] []
2: [email protected]
3: [email protected] ">" [] []
1: [email protected]
0: [email protected]
0: [email protected] "{" [] []
1: [email protected]
0: [email protected] "test" [] []
2: [email protected] "}" [] []
2: [email protected]
0: [email protected] "<" [] []
1: [email protected] "/" [] []
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
4: [email protected] "" [Newline("\n")] []

```