Skip to content

Commit 425963d

Browse files
authored
feat(html): implement {@debug} parsing (#7969)
1 parent 547c2da commit 425963d

File tree

42 files changed

+1752
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1752
-40
lines changed

.changeset/nine-bottles-float.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added support for the Svelte syntax `{@debug}`. The Biome HTML parser is now able to parse and format the blocks:
6+
7+
```diff
8+
-{@debug foo,bar, something}
9+
+{@debug foo, bar, something}
10+
```
File renamed without changes.

crates/biome_html_factory/src/generated/node_factory.rs

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_html_factory/src/generated/syntax_factory.rs

Lines changed: 68 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_html_formatter/src/generated.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,78 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlTextExpression {
716716
)
717717
}
718718
}
719+
impl FormatRule<biome_html_syntax::SvelteDebugBlock>
720+
for crate::svelte::auxiliary::debug_block::FormatSvelteDebugBlock
721+
{
722+
type Context = HtmlFormatContext;
723+
#[inline(always)]
724+
fn fmt(
725+
&self,
726+
node: &biome_html_syntax::SvelteDebugBlock,
727+
f: &mut HtmlFormatter,
728+
) -> FormatResult<()> {
729+
FormatNodeRule::<biome_html_syntax::SvelteDebugBlock>::fmt(self, node, f)
730+
}
731+
}
732+
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteDebugBlock {
733+
type Format<'a> = FormatRefWithRule<
734+
'a,
735+
biome_html_syntax::SvelteDebugBlock,
736+
crate::svelte::auxiliary::debug_block::FormatSvelteDebugBlock,
737+
>;
738+
fn format(&self) -> Self::Format<'_> {
739+
FormatRefWithRule::new(
740+
self,
741+
crate::svelte::auxiliary::debug_block::FormatSvelteDebugBlock::default(),
742+
)
743+
}
744+
}
745+
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::SvelteDebugBlock {
746+
type Format = FormatOwnedWithRule<
747+
biome_html_syntax::SvelteDebugBlock,
748+
crate::svelte::auxiliary::debug_block::FormatSvelteDebugBlock,
749+
>;
750+
fn into_format(self) -> Self::Format {
751+
FormatOwnedWithRule::new(
752+
self,
753+
crate::svelte::auxiliary::debug_block::FormatSvelteDebugBlock::default(),
754+
)
755+
}
756+
}
757+
impl FormatRule<biome_html_syntax::SvelteName>
758+
for crate::svelte::auxiliary::name::FormatSvelteName
759+
{
760+
type Context = HtmlFormatContext;
761+
#[inline(always)]
762+
fn fmt(&self, node: &biome_html_syntax::SvelteName, f: &mut HtmlFormatter) -> FormatResult<()> {
763+
FormatNodeRule::<biome_html_syntax::SvelteName>::fmt(self, node, f)
764+
}
765+
}
766+
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteName {
767+
type Format<'a> = FormatRefWithRule<
768+
'a,
769+
biome_html_syntax::SvelteName,
770+
crate::svelte::auxiliary::name::FormatSvelteName,
771+
>;
772+
fn format(&self) -> Self::Format<'_> {
773+
FormatRefWithRule::new(
774+
self,
775+
crate::svelte::auxiliary::name::FormatSvelteName::default(),
776+
)
777+
}
778+
}
779+
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::SvelteName {
780+
type Format = FormatOwnedWithRule<
781+
biome_html_syntax::SvelteName,
782+
crate::svelte::auxiliary::name::FormatSvelteName,
783+
>;
784+
fn into_format(self) -> Self::Format {
785+
FormatOwnedWithRule::new(
786+
self,
787+
crate::svelte::auxiliary::name::FormatSvelteName::default(),
788+
)
789+
}
790+
}
719791
impl AsFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeList {
720792
type Format<'a> = FormatRefWithRule<
721793
'a,
@@ -766,6 +838,31 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlElementList {
766838
)
767839
}
768840
}
841+
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteBindingList {
842+
type Format<'a> = FormatRefWithRule<
843+
'a,
844+
biome_html_syntax::SvelteBindingList,
845+
crate::svelte::lists::binding_list::FormatSvelteBindingList,
846+
>;
847+
fn format(&self) -> Self::Format<'_> {
848+
FormatRefWithRule::new(
849+
self,
850+
crate::svelte::lists::binding_list::FormatSvelteBindingList::default(),
851+
)
852+
}
853+
}
854+
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::SvelteBindingList {
855+
type Format = FormatOwnedWithRule<
856+
biome_html_syntax::SvelteBindingList,
857+
crate::svelte::lists::binding_list::FormatSvelteBindingList,
858+
>;
859+
fn into_format(self) -> Self::Format {
860+
FormatOwnedWithRule::new(
861+
self,
862+
crate::svelte::lists::binding_list::FormatSvelteBindingList::default(),
863+
)
864+
}
865+
}
769866
impl FormatRule<biome_html_syntax::AstroBogusFrontmatter>
770867
for crate::astro::bogus::bogus_frontmatter::FormatAstroBogusFrontmatter
771868
{
@@ -944,6 +1041,44 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlBogusTextExpressio
9441041
)
9451042
}
9461043
}
1044+
impl FormatRule<biome_html_syntax::SvelteBogusBlock>
1045+
for crate::svelte::bogus::bogus_block::FormatSvelteBogusBlock
1046+
{
1047+
type Context = HtmlFormatContext;
1048+
#[inline(always)]
1049+
fn fmt(
1050+
&self,
1051+
node: &biome_html_syntax::SvelteBogusBlock,
1052+
f: &mut HtmlFormatter,
1053+
) -> FormatResult<()> {
1054+
FormatBogusNodeRule::<biome_html_syntax::SvelteBogusBlock>::fmt(self, node, f)
1055+
}
1056+
}
1057+
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteBogusBlock {
1058+
type Format<'a> = FormatRefWithRule<
1059+
'a,
1060+
biome_html_syntax::SvelteBogusBlock,
1061+
crate::svelte::bogus::bogus_block::FormatSvelteBogusBlock,
1062+
>;
1063+
fn format(&self) -> Self::Format<'_> {
1064+
FormatRefWithRule::new(
1065+
self,
1066+
crate::svelte::bogus::bogus_block::FormatSvelteBogusBlock::default(),
1067+
)
1068+
}
1069+
}
1070+
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::SvelteBogusBlock {
1071+
type Format = FormatOwnedWithRule<
1072+
biome_html_syntax::SvelteBogusBlock,
1073+
crate::svelte::bogus::bogus_block::FormatSvelteBogusBlock,
1074+
>;
1075+
fn into_format(self) -> Self::Format {
1076+
FormatOwnedWithRule::new(
1077+
self,
1078+
crate::svelte::bogus::bogus_block::FormatSvelteBogusBlock::default(),
1079+
)
1080+
}
1081+
}
9471082
impl AsFormat<HtmlFormatContext> for biome_html_syntax::AnyAstroFrontmatterElement {
9481083
type Format<'a> = FormatRefWithRule<
9491084
'a,
@@ -1094,3 +1229,28 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::AnyHtmlTextExpression
10941229
)
10951230
}
10961231
}
1232+
impl AsFormat<HtmlFormatContext> for biome_html_syntax::AnySvelteBlock {
1233+
type Format<'a> = FormatRefWithRule<
1234+
'a,
1235+
biome_html_syntax::AnySvelteBlock,
1236+
crate::svelte::any::block::FormatAnySvelteBlock,
1237+
>;
1238+
fn format(&self) -> Self::Format<'_> {
1239+
FormatRefWithRule::new(
1240+
self,
1241+
crate::svelte::any::block::FormatAnySvelteBlock::default(),
1242+
)
1243+
}
1244+
}
1245+
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::AnySvelteBlock {
1246+
type Format = FormatOwnedWithRule<
1247+
biome_html_syntax::AnySvelteBlock,
1248+
crate::svelte::any::block::FormatAnySvelteBlock,
1249+
>;
1250+
fn into_format(self) -> Self::Format {
1251+
FormatOwnedWithRule::new(
1252+
self,
1253+
crate::svelte::any::block::FormatAnySvelteBlock::default(),
1254+
)
1255+
}
1256+
}

crates/biome_html_formatter/src/html/any/text_expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl FormatRule<AnyHtmlTextExpression> for FormatAnyHtmlTextExpression {
88
type Context = HtmlFormatContext;
99
fn fmt(&self, node: &AnyHtmlTextExpression, f: &mut HtmlFormatter) -> FormatResult<()> {
1010
match node {
11+
AnyHtmlTextExpression::AnySvelteBlock(node) => node.format().fmt(f),
1112
AnyHtmlTextExpression::HtmlBogusTextExpression(node) => node.format().fmt(f),
1213
AnyHtmlTextExpression::HtmlDoubleTextExpression(node) => node.format().fmt(f),
1314
AnyHtmlTextExpression::HtmlSingleTextExpression(node) => node.format().fmt(f),

crates/biome_html_formatter/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ mod cst;
2020
mod generated;
2121
mod html;
2222
pub(crate) mod prelude;
23+
pub(crate) mod separated;
24+
mod svelte;
2325
mod trivia;
2426
pub mod utils;
2527
mod verbatim;
2628

27-
/// Formats a Html file based on its features.
29+
/// Formats a HTML file based on its features.
2830
///
2931
/// It returns a [Formatted] result, which the user can use to override a file.
3032
pub fn format_node(

0 commit comments

Comments
 (0)