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/happy-cats-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#8605](https://github.com/biomejs/biome/issues/8605): Text expressions in some template languages (`{{ expr }}` or `{ expr }`) at the top level of an HTML document no longer causes panicking.
28 changes: 28 additions & 0 deletions crates/biome_html_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions crates/biome_html_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions crates/biome_html_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttribute {
)
}
}
impl FormatRule < biome_html_syntax :: HtmlAttributeDoubleTextExpression > for crate :: html :: auxiliary :: attribute_double_text_expression :: FormatHtmlAttributeDoubleTextExpression { type Context = HtmlFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_html_syntax :: HtmlAttributeDoubleTextExpression , f : & mut HtmlFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_html_syntax :: HtmlAttributeDoubleTextExpression > :: fmt (self , node , f) } }
impl AsFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeDoubleTextExpression {
type Format < 'a > = FormatRefWithRule < 'a , biome_html_syntax :: HtmlAttributeDoubleTextExpression , crate :: html :: auxiliary :: attribute_double_text_expression :: FormatHtmlAttributeDoubleTextExpression > ;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule :: new (self , crate :: html :: auxiliary :: attribute_double_text_expression :: FormatHtmlAttributeDoubleTextExpression :: default ())
}
}
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeDoubleTextExpression {
type Format = FormatOwnedWithRule < biome_html_syntax :: HtmlAttributeDoubleTextExpression , crate :: html :: auxiliary :: attribute_double_text_expression :: FormatHtmlAttributeDoubleTextExpression > ;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule :: new (self , crate :: html :: auxiliary :: attribute_double_text_expression :: FormatHtmlAttributeDoubleTextExpression :: default ())
}
}
impl FormatRule<biome_html_syntax::HtmlAttributeInitializerClause>
for crate::html::auxiliary::attribute_initializer_clause::FormatHtmlAttributeInitializerClause
{
Expand Down Expand Up @@ -190,6 +203,19 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeName {
)
}
}
impl FormatRule < biome_html_syntax :: HtmlAttributeSingleTextExpression > for crate :: html :: auxiliary :: attribute_single_text_expression :: FormatHtmlAttributeSingleTextExpression { type Context = HtmlFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_html_syntax :: HtmlAttributeSingleTextExpression , f : & mut HtmlFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_html_syntax :: HtmlAttributeSingleTextExpression > :: fmt (self , node , f) } }
impl AsFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeSingleTextExpression {
type Format < 'a > = FormatRefWithRule < 'a , biome_html_syntax :: HtmlAttributeSingleTextExpression , crate :: html :: auxiliary :: attribute_single_text_expression :: FormatHtmlAttributeSingleTextExpression > ;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule :: new (self , crate :: html :: auxiliary :: attribute_single_text_expression :: FormatHtmlAttributeSingleTextExpression :: default ())
}
}
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeSingleTextExpression {
type Format = FormatOwnedWithRule < biome_html_syntax :: HtmlAttributeSingleTextExpression , crate :: html :: auxiliary :: attribute_single_text_expression :: FormatHtmlAttributeSingleTextExpression > ;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule :: new (self , crate :: html :: auxiliary :: attribute_single_text_expression :: FormatHtmlAttributeSingleTextExpression :: default ())
}
}
impl FormatRule<biome_html_syntax::HtmlCdataSection>
for crate::html::auxiliary::cdata_section::FormatHtmlCdataSection
{
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_html_formatter/src/html/any/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl FormatRule<AnyHtmlAttribute> for FormatAnyHtmlAttribute {
match node {
AnyHtmlAttribute::AnyVueDirective(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlAttribute(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlAttributeDoubleTextExpression(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlAttributeSingleTextExpression(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlBogusAttribute(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlDoubleTextExpression(node) => node.format().fmt(f),
AnyHtmlAttribute::HtmlSingleTextExpression(node) => node.format().fmt(f),
AnyHtmlAttribute::SvelteAttachAttribute(node) => node.format().fmt(f),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ impl FormatRule<AnyHtmlAttributeInitializer> for FormatAnyHtmlAttributeInitializ
type Context = HtmlFormatContext;
fn fmt(&self, node: &AnyHtmlAttributeInitializer, f: &mut HtmlFormatter) -> FormatResult<()> {
match node {
AnyHtmlAttributeInitializer::HtmlSingleTextExpression(node) => node.format().fmt(f),
AnyHtmlAttributeInitializer::HtmlAttributeSingleTextExpression(node) => {
node.format().fmt(f)
}
AnyHtmlAttributeInitializer::HtmlString(node) => node.format().fmt(f),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_html_syntax::{
HtmlAttributeDoubleTextExpression, HtmlAttributeDoubleTextExpressionFields,
};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatHtmlAttributeDoubleTextExpression;

impl FormatNodeRule<HtmlAttributeDoubleTextExpression> for FormatHtmlAttributeDoubleTextExpression {
fn fmt_fields(
&self,
node: &HtmlAttributeDoubleTextExpression,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
let HtmlAttributeDoubleTextExpressionFields {
l_double_curly_token,
expression,
r_double_curly_token,
} = node.as_fields();

write!(
f,
[
l_double_curly_token.format(),
space(),
expression.format(),
space(),
r_double_curly_token.format(),
]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_html_syntax::{
HtmlAttributeSingleTextExpression, HtmlAttributeSingleTextExpressionFields,
};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatHtmlAttributeSingleTextExpression;

impl FormatNodeRule<HtmlAttributeSingleTextExpression> for FormatHtmlAttributeSingleTextExpression {
fn fmt_fields(
&self,
node: &HtmlAttributeSingleTextExpression,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
let HtmlAttributeSingleTextExpressionFields {
l_curly_token,
expression,
r_curly_token,
} = node.as_fields();

write!(
f,
[
l_curly_token.format(),
expression.format(),
r_curly_token.format()
]
)
}
}
2 changes: 2 additions & 0 deletions crates/biome_html_formatter/src/html/auxiliary/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.

pub(crate) mod attribute;
pub(crate) mod attribute_double_text_expression;
pub(crate) mod attribute_initializer_clause;
pub(crate) mod attribute_name;
pub(crate) mod attribute_single_text_expression;
pub(crate) mod cdata_section;
pub(crate) mod closing_element;
pub(crate) mod content;
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_html_formatter/src/html/lists/attribute_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl FormatRule<HtmlAttributeList> for FormatHtmlAttributeList {
tag_name: self.tag_name.clone(),
})
.fmt(f),
AnyHtmlAttribute::HtmlDoubleTextExpression(attr) => {
AnyHtmlAttribute::HtmlAttributeDoubleTextExpression(attr) => {
attr.format().fmt(f)
}
AnyHtmlAttribute::HtmlSingleTextExpression(attr) => {
AnyHtmlAttribute::HtmlAttributeSingleTextExpression(attr) => {
attr.format().fmt(f)
}
AnyHtmlAttribute::HtmlBogusAttribute(attr) => {
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_html_formatter/src/html/lists/element_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ impl FormatHtmlElementList {
// Some(WordSeparator::Lines(2))
}

// Don't add a newline before a bogus element as it may break the layout
Some(HtmlChild::NonText(AnyHtmlElement::HtmlBogusElement(_))) => None,

// Last word or last word before an element without any whitespace in between
Some(HtmlChild::NonText(next_child)) => Some(WordSeparator::EndOfText {
is_soft_line_break: !matches!(
Expand Down
6 changes: 4 additions & 2 deletions crates/biome_html_formatter/src/utils/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,16 @@ where
}

// Check for trailing whitespace, and preserve it if
// - its embedded expression content
// - its an element
// - it's embedded expression content
// - it's an element
// - it's a bogus element
// This preserves spaces between expressions/elements and following text content.
if matches!(
&child,
AnyHtmlElement::AnyHtmlContent(_)
| AnyHtmlElement::HtmlElement(_)
| AnyHtmlElement::HtmlSelfClosingElement(_)
| AnyHtmlElement::HtmlBogusElement(_)
) && let Some(last_token) = child.syntax().last_token()
&& last_token.has_trailing_whitespace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ Self close void elements: never
-----

```html
<div>
{{ $interpolation }}
</div>
<div>{{ $interpolation }}</div>
```

## Output 1
Expand All @@ -51,7 +49,5 @@ Self close void elements: never
-----

```html
<div>
{{ $interpolation }}
</div>
<div>{{ $interpolation }}</div>
```
Loading
Loading