diff --git a/.changeset/polite-elephants-call.md b/.changeset/polite-elephants-call.md
new file mode 100644
index 0000000..12b399f
--- /dev/null
+++ b/.changeset/polite-elephants-call.md
@@ -0,0 +1,5 @@
+---
+'prettier-plugin-astro': patch
+---
+
+Format spread operator
diff --git a/src/nodes.ts b/src/nodes.ts
index f244623..824777f 100644
--- a/src/nodes.ts
+++ b/src/nodes.ts
@@ -54,6 +54,11 @@ export interface CodeSpanNode extends BaseNode {
raw: string;
}
+export interface SpreadNode extends BaseNode {
+ type: 'Spread';
+ expression: ExpressionNode;
+}
+
export interface ExpressionNode {
type: 'Expression';
start: number;
@@ -256,5 +261,6 @@ export type anyNode =
| MustacheTagNode
| ScriptNode
| SlotNode
+ | SpreadNode
| StyleNode
| TextNode;
diff --git a/src/printer.ts b/src/printer.ts
index efd37cc..0bbe7f8 100644
--- a/src/printer.ts
+++ b/src/printer.ts
@@ -399,17 +399,16 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc {
}),
'}',
];
- // TODO: ADD TEST OR REMOVE
- // case 'Spread':
- // return [
- // line,
- // '{...',
- // printJS(path, print, 'expression', {
- // forceSingleQuote: true,
- // forceSingleLine: false,
- // }),
- // '}',
- // ];
+ case 'Spread':
+ return [
+ line,
+ '{...',
+ printJS(path, print, 'expression', {
+ forceSingleQuote: true,
+ forceSingleLine: false,
+ }),
+ '}',
+ ];
case 'Comment':
return [''];
case 'CodeSpan':
diff --git a/test/astro-prettier.test.ts b/test/astro-prettier.test.ts
index 2ad63dc..48399ed 100644
--- a/test/astro-prettier.test.ts
+++ b/test/astro-prettier.test.ts
@@ -150,3 +150,5 @@ test('Can format an Astro file with prettier "astroAllowShorthand: false" option
test('Format nested style tag content', Prettier, 'format-nested-style-tag-content');
test('Format nested sass style tag content', Prettier, 'format-nested-sass-style-tag-content');
+
+test('Format spread operator', Prettier, 'spread-operator');
diff --git a/test/fixtures/spread-operator/input.astro b/test/fixtures/spread-operator/input.astro
new file mode 100644
index 0000000..1c4f329
--- /dev/null
+++ b/test/fixtures/spread-operator/input.astro
@@ -0,0 +1,4 @@
+---
+const meta = { title: "My Title", lang: "en" }
+---
+Foo
\ No newline at end of file
diff --git a/test/fixtures/spread-operator/output.astro b/test/fixtures/spread-operator/output.astro
new file mode 100644
index 0000000..47694b2
--- /dev/null
+++ b/test/fixtures/spread-operator/output.astro
@@ -0,0 +1,5 @@
+---
+const meta = { title: "My Title", lang: "en" };
+---
+
+Foo