Skip to content

Commit

Permalink
fix: fix incorrect non-strict Svelte attr (fix #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Oct 28, 2024
1 parent 07848be commit 2d6ea15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,11 @@ impl<'s> DocGen<'s> for NativeAttribute<'s> {
}
}
Language::Svelte if !ctx.options.strict_svelte_attr => {
if let Some(expr) = value.strip_prefix('{').and_then(|s| s.strip_suffix('}')) {
if let Some(expr) = value
.strip_prefix('{')
.and_then(|s| s.strip_suffix('}'))
.filter(|s| !s.contains('{'))
{
let formatted_expr = ctx.format_expr(expr, false, value_start);
return match self.name.split_once(':') {
Some((_, name))
Expand Down
7 changes: 7 additions & 0 deletions markup_fmt/tests/fmt/svelte/class-attr/fixture.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: markup_fmt/tests/fmt.rs
---
<div
class="{icon.name} rounded-full border {icon.borderColor} {icon.bgColor} p-3 text-3xl {icon.color}"
>
</div>
3 changes: 3 additions & 0 deletions markup_fmt/tests/fmt/svelte/class-attr/fixture.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div
class="{icon.name} rounded-full border {icon.borderColor} {icon.bgColor} p-3 text-3xl {icon.color}"
></div>

0 comments on commit 2d6ea15

Please sign in to comment.