Skip to content

Commit 7abac5f

Browse files
authored
feat: support svelte:document (#355)
1 parent 2fbd812 commit 7abac5f

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## 2.10.0 (unreleased)
44

5-
- (feat) support `requirePragma` and `insertPragma` options
5+
- (feat) support `requirePragma` and `insertPragma` options ([#350](https://github.com/sveltejs/prettier-plugin-svelte/issues/350))
6+
- (feat) support `<svelte:document>`
67

78
## 2.9.0
89

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"prettier": "^2.7.1",
3838
"rollup": "2.36.0",
3939
"rollup-plugin-typescript": "1.0.1",
40-
"svelte": "^3.54.0",
40+
"svelte": "^3.57.0",
4141
"ts-node": "^9.1.1",
4242
"tslib": "^2.0.3",
4343
"typescript": "4.1.3"

src/print/helpers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ASTNode,
33
AttributeNode,
44
BodyNode,
5+
DocumentNode,
56
ElementNode,
67
HeadNode,
78
InlineComponentNode,
@@ -82,6 +83,7 @@ export function getAttributeLine(
8283
| StyleNode
8384
| ScriptNode
8485
| BodyNode
86+
| DocumentNode
8587
| OptionsNode
8688
| SlotTemplateNode,
8789
options: ParserOptions,
@@ -111,6 +113,7 @@ export function printWithPrependedAttributeLine(
111113
| StyleNode
112114
| ScriptNode
113115
| BodyNode
116+
| DocumentNode
114117
| OptionsNode
115118
| SlotTemplateNode,
116119
options: ParserOptions,

src/print/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,21 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
412412
),
413413
...[bracketSameLine ? ' ' : '', '/>'],
414414
]);
415+
case 'Document':
416+
return groupConcat([
417+
'<',
418+
node.name,
419+
indent(
420+
groupConcat([
421+
...path.map(
422+
printWithPrependedAttributeLine(node, options, print),
423+
'attributes',
424+
),
425+
bracketSameLine ? '' : dedent(line),
426+
]),
427+
),
428+
...[bracketSameLine ? ' ' : '', '/>'],
429+
]);
415430
case 'Identifier':
416431
return node.name;
417432
case 'AttributeShorthand': {

src/print/nodes.ts

+7
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ export interface BodyNode extends BaseNode {
259259
attributes: Node[];
260260
}
261261

262+
export interface DocumentNode extends BaseNode {
263+
type: 'Document';
264+
name: string;
265+
attributes: Node[];
266+
}
267+
262268
export interface OptionsNode extends BaseNode {
263269
type: 'Options';
264270
name: string;
@@ -318,6 +324,7 @@ export type Node =
318324
| InstanceScriptNode
319325
| ModuleScriptNode
320326
| BodyNode
327+
| DocumentNode
321328
| OptionsNode
322329
| SlotTemplateNode
323330
| ConstTagNode;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:document on:event={handler} />

0 commit comments

Comments
 (0)