Skip to content

Commit

Permalink
feat: support svelte:document (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Mar 21, 2023
1 parent 2fbd812 commit 7abac5f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 2.10.0 (unreleased)

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

## 2.9.0

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"prettier": "^2.7.1",
"rollup": "2.36.0",
"rollup-plugin-typescript": "1.0.1",
"svelte": "^3.54.0",
"svelte": "^3.57.0",
"ts-node": "^9.1.1",
"tslib": "^2.0.3",
"typescript": "4.1.3"
Expand Down
3 changes: 3 additions & 0 deletions src/print/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ASTNode,
AttributeNode,
BodyNode,
DocumentNode,
ElementNode,
HeadNode,
InlineComponentNode,
Expand Down Expand Up @@ -82,6 +83,7 @@ export function getAttributeLine(
| StyleNode
| ScriptNode
| BodyNode
| DocumentNode
| OptionsNode
| SlotTemplateNode,
options: ParserOptions,
Expand Down Expand Up @@ -111,6 +113,7 @@ export function printWithPrependedAttributeLine(
| StyleNode
| ScriptNode
| BodyNode
| DocumentNode
| OptionsNode
| SlotTemplateNode,
options: ParserOptions,
Expand Down
15 changes: 15 additions & 0 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,21 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
),
...[bracketSameLine ? ' ' : '', '/>'],
]);
case 'Document':
return groupConcat([
'<',
node.name,
indent(
groupConcat([
...path.map(
printWithPrependedAttributeLine(node, options, print),
'attributes',
),
bracketSameLine ? '' : dedent(line),
]),
),
...[bracketSameLine ? ' ' : '', '/>'],
]);
case 'Identifier':
return node.name;
case 'AttributeShorthand': {
Expand Down
7 changes: 7 additions & 0 deletions src/print/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ export interface BodyNode extends BaseNode {
attributes: Node[];
}

export interface DocumentNode extends BaseNode {
type: 'Document';
name: string;
attributes: Node[];
}

export interface OptionsNode extends BaseNode {
type: 'Options';
name: string;
Expand Down Expand Up @@ -318,6 +324,7 @@ export type Node =
| InstanceScriptNode
| ModuleScriptNode
| BodyNode
| DocumentNode
| OptionsNode
| SlotTemplateNode
| ConstTagNode;
Expand Down
1 change: 1 addition & 0 deletions test/printer/samples/svelte-document-element.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svelte:document on:event={handler} />

0 comments on commit 7abac5f

Please sign in to comment.