Skip to content

Commit 3d50f45

Browse files
committed
fix: fix Astro spread attr with shorthand disabled (fix #175)
1 parent f81a3aa commit 3d50f45

File tree

5 files changed

+8
-2
lines changed

5 files changed

+8
-2
lines changed

markup_fmt/src/printer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,14 @@ impl<'s> DocGen<'s> for AstroAttribute<'s> {
258258
.concat(reflow_with_indent(&expr_code, true))
259259
.append(Doc::text("}"));
260260
if let Some(name) = self.name {
261-
if (matches!(ctx.options.astro_attr_shorthand, Some(true))) && name == expr_code {
261+
if matches!(ctx.options.astro_attr_shorthand, Some(true)) && name == expr_code {
262262
expr
263263
} else {
264264
Doc::text(name).append(Doc::text("=")).append(expr)
265265
}
266-
} else if matches!(ctx.options.astro_attr_shorthand, Some(false)) {
266+
} else if matches!(ctx.options.astro_attr_shorthand, Some(false))
267+
&& !expr_code.starts_with("...")
268+
{
267269
Doc::text(expr_code.clone())
268270
.append(Doc::text("="))
269271
.append(expr)

markup_fmt/tests/fmt/astro/attr-shorthand/fixture.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import Comp from "./comp.astro"
44
<Comp options={options} />
55
<Comp {options} />
66
<Comp options={ options } />
7+
<div {...rest}></div>

markup_fmt/tests/fmt/astro/attr-shorthand/fixture.default.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ import Comp from "./comp.astro"
77
<Comp options={options} />
88
<Comp {options} />
99
<Comp options={options} />
10+
<div {...rest}></div>

markup_fmt/tests/fmt/astro/attr-shorthand/fixture.disabled.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ import Comp from "./comp.astro"
77
<Comp options={options} />
88
<Comp options={options} />
99
<Comp options={options} />
10+
<div {...rest}></div>

markup_fmt/tests/fmt/astro/attr-shorthand/fixture.enabled.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ import Comp from "./comp.astro"
77
<Comp {options} />
88
<Comp {options} />
99
<Comp {options} />
10+
<div {...rest}></div>

0 commit comments

Comments
 (0)