From 736113fb84cf270370ea9286576b964ef437a81e Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 22 Jan 2026 17:24:21 -0500 Subject: [PATCH] fix(parse/html/astro): accept astro files with empty frontmatter --- .changeset/fix-astro-empty-frontmatter.md | 5 ++ crates/biome_html_parser/src/syntax/astro.rs | 5 +- .../ok/astro/empty_frontmatter.astro | 5 ++ .../ok/astro/empty_frontmatter.astro.snap | 84 +++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .changeset/fix-astro-empty-frontmatter.md create mode 100644 crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro create mode 100644 crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro.snap diff --git a/.changeset/fix-astro-empty-frontmatter.md b/.changeset/fix-astro-empty-frontmatter.md new file mode 100644 index 000000000000..164e7f032a36 --- /dev/null +++ b/.changeset/fix-astro-empty-frontmatter.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fixed [#7858](https://github.com/biomejs/biome/issues/7858): Biome now parses Astro files with empty frontmatter blocks. diff --git a/crates/biome_html_parser/src/syntax/astro.rs b/crates/biome_html_parser/src/syntax/astro.rs index 26673a0818ab..458a111fbdee 100644 --- a/crates/biome_html_parser/src/syntax/astro.rs +++ b/crates/biome_html_parser/src/syntax/astro.rs @@ -20,7 +20,10 @@ pub(crate) fn parse_astro_fence(p: &mut HtmlParser) -> ParsedSyntax { let c = m.complete(p, ASTRO_FRONTMATTER_ELEMENT); return ParsedSyntax::Present(c); } - parse_astro_embedded(p).ok(); + if let Absent = parse_astro_embedded(p) { + let content = p.start(); + content.complete(p, ASTRO_EMBEDDED_CONTENT); + } p.expect(T![---]); let c = m.complete(p, ASTRO_FRONTMATTER_ELEMENT); diff --git a/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro b/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro new file mode 100644 index 000000000000..a26b247c616e --- /dev/null +++ b/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro @@ -0,0 +1,5 @@ +--- +--- + +
+
diff --git a/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro.snap b/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro.snap new file mode 100644 index 000000000000..0721e8f5b6b2 --- /dev/null +++ b/crates/biome_html_parser/tests/html_specs/ok/astro/empty_frontmatter.astro.snap @@ -0,0 +1,84 @@ +--- +source: crates/biome_html_parser/tests/spec_test.rs +assertion_line: 138 +expression: snapshot +--- +## Input + +```astro +--- +--- + +
+
+ +``` + + +## AST + +``` +HtmlRoot { + bom_token: missing (optional), + frontmatter: AstroFrontmatterElement { + l_fence_token: FENCE@0..3 "---" [] [], + content: AstroEmbeddedContent { + content_token: missing (optional), + }, + r_fence_token: FENCE@3..7 "---" [Newline("\n")] [], + }, + directive: missing (optional), + html: HtmlElementList [ + HtmlElement { + opening_element: HtmlOpeningElement { + l_angle_token: L_ANGLE@7..10 "<" [Newline("\n"), Newline("\n")] [], + name: HtmlTagName { + value_token: HTML_LITERAL@10..13 "div" [] [], + }, + attributes: HtmlAttributeList [], + r_angle_token: R_ANGLE@13..14 ">" [] [], + }, + children: HtmlElementList [], + closing_element: HtmlClosingElement { + l_angle_token: L_ANGLE@14..16 "<" [Newline("\n")] [], + slash_token: SLASH@16..17 "/" [] [], + name: HtmlTagName { + value_token: HTML_LITERAL@17..20 "div" [] [], + }, + r_angle_token: R_ANGLE@20..21 ">" [] [], + }, + }, + ], + eof_token: EOF@21..22 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: HTML_ROOT@0..22 + 0: (empty) + 1: ASTRO_FRONTMATTER_ELEMENT@0..7 + 0: FENCE@0..3 "---" [] [] + 1: ASTRO_EMBEDDED_CONTENT@3..3 + 0: (empty) + 2: FENCE@3..7 "---" [Newline("\n")] [] + 2: (empty) + 3: HTML_ELEMENT_LIST@7..21 + 0: HTML_ELEMENT@7..21 + 0: HTML_OPENING_ELEMENT@7..14 + 0: L_ANGLE@7..10 "<" [Newline("\n"), Newline("\n")] [] + 1: HTML_TAG_NAME@10..13 + 0: HTML_LITERAL@10..13 "div" [] [] + 2: HTML_ATTRIBUTE_LIST@13..13 + 3: R_ANGLE@13..14 ">" [] [] + 1: HTML_ELEMENT_LIST@14..14 + 2: HTML_CLOSING_ELEMENT@14..21 + 0: L_ANGLE@14..16 "<" [Newline("\n")] [] + 1: SLASH@16..17 "/" [] [] + 2: HTML_TAG_NAME@17..20 + 0: HTML_LITERAL@17..20 "div" [] [] + 3: R_ANGLE@20..21 ">" [] [] + 4: EOF@21..22 "" [Newline("\n")] [] + +```