Skip to content

Commit 7d68c92

Browse files
authored
feat: support attachments (#495)
sveltejs/svelte#15000
1 parent 259922f commit 7d68c92

File tree

10 files changed

+39
-7
lines changed

10 files changed

+39
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# prettier-plugin-svelte changelog
22

3+
## 3.4.0
4+
5+
- (feat) Svelte 5: support attachments (`{@attach ...}`)
6+
37
## 3.3.3
48

59
- (fix) Svelte 5: ensure bind get/set is broken up correctly when too long

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-svelte",
3-
"version": "3.3.3",
3+
"version": "3.4.0",
44
"description": "Svelte plugin for prettier",
55
"main": "plugin.js",
66
"files": [

src/embed.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export function embed(path: FastPath, _options: Options) {
127127
case 'Spread':
128128
printJS(parent, 'expression', {});
129129
break;
130+
case 'AttachTag':
131+
printJS(parent, 'expression', {});
132+
break;
130133
case 'ConstTag':
131134
printJS(parent, 'expression', { removeParentheses: true });
132135
break;

src/print/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,11 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
711711
case 'RawMustacheTag':
712712
return ['{@html ', printJS(path, print, 'expression'), '}'];
713713
// Svelte 5 only
714-
case 'RenderTag': {
715-
const render = ['{@render ', printJS(path, print, 'expression'), '}'];
716-
return render;
717-
}
714+
case 'RenderTag':
715+
return ['{@render ', printJS(path, print, 'expression'), '}'];
716+
// Svelte 5 only
717+
case 'AttachTag':
718+
return ['{@attach ', printJS(path, print, 'expression'), '}'];
718719
case 'Spread':
719720
return ['{...', printJS(path, print, 'expression'), '}'];
720721
case 'ConstTag':

src/print/nodes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ export interface RenderTag extends BaseNode {
327327
arguments: BaseNode[] | null;
328328
}
329329

330+
export interface AttachTag extends BaseNode {
331+
type: 'AttachTag';
332+
expression: IdentifierNode;
333+
}
334+
330335
export type Node =
331336
| FragmentNode
332337
| ElementNode
@@ -375,6 +380,7 @@ export type Node =
375380
| SvelteBoundary
376381
| SvelteHTML
377382
| RenderTag
383+
| AttachTag
378384
| SnippetBlock;
379385

380386
/**

test/formatting/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ if (process.env.CI && hasOnly) {
1919
}
2020

2121
for (const dir of dirs) {
22+
if (dir.endsWith('.skip')) continue;
23+
2224
const input = readFileSync(`test/formatting/samples/${dir}/input.html`, 'utf-8').replace(
2325
/\r?\n/g,
2426
'\n',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<input {@attach x} />
2+
3+
<input {@attach (node) => { foo; bar; }} />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<input {@attach x} />
2+
3+
<input
4+
{@attach (node) => {
5+
foo;
6+
bar;
7+
}}
8+
/>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<input {@attach x} />
2+
<input {@attach () => {}} />
3+
4+
<Component {@attach x} />
5+
<Component {@attach () => {}} />

0 commit comments

Comments
 (0)