diff --git a/CHANGELOG.md b/CHANGELOG.md index 837d1aa1..7009ae83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `` ## 2.9.0 diff --git a/package-lock.json b/package-lock.json index 0a18eee7..80b52f9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,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" @@ -3367,9 +3367,9 @@ } }, "node_modules/svelte": { - "version": "3.54.0", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.54.0.tgz", - "integrity": "sha512-tdrgeJU0hob0ZWAMoKXkhcxXA7dpTg6lZGxUeko5YqvPdJBiyRspGsCwV27kIrbrqPP2WUoSV9ca0gnLlw8YzQ==", + "version": "3.57.0", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.57.0.tgz", + "integrity": "sha512-WMXEvF+RtAaclw0t3bPDTUe19pplMlfyKDsixbHQYgCWi9+O9VN0kXU1OppzrB9gPAvz4NALuoca2LfW2bOjTQ==", "dev": true, "engines": { "node": ">= 8" @@ -6230,9 +6230,9 @@ } }, "svelte": { - "version": "3.54.0", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.54.0.tgz", - "integrity": "sha512-tdrgeJU0hob0ZWAMoKXkhcxXA7dpTg6lZGxUeko5YqvPdJBiyRspGsCwV27kIrbrqPP2WUoSV9ca0gnLlw8YzQ==", + "version": "3.57.0", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-3.57.0.tgz", + "integrity": "sha512-WMXEvF+RtAaclw0t3bPDTUe19pplMlfyKDsixbHQYgCWi9+O9VN0kXU1OppzrB9gPAvz4NALuoca2LfW2bOjTQ==", "dev": true }, "temp-dir": { diff --git a/package.json b/package.json index 08fd0a0c..f924b49e 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/print/helpers.ts b/src/print/helpers.ts index 904d03cf..ec5807a2 100644 --- a/src/print/helpers.ts +++ b/src/print/helpers.ts @@ -2,6 +2,7 @@ import { ASTNode, AttributeNode, BodyNode, + DocumentNode, ElementNode, HeadNode, InlineComponentNode, @@ -82,6 +83,7 @@ export function getAttributeLine( | StyleNode | ScriptNode | BodyNode + | DocumentNode | OptionsNode | SlotTemplateNode, options: ParserOptions, @@ -111,6 +113,7 @@ export function printWithPrependedAttributeLine( | StyleNode | ScriptNode | BodyNode + | DocumentNode | OptionsNode | SlotTemplateNode, options: ParserOptions, diff --git a/src/print/index.ts b/src/print/index.ts index 692d19da..603a2864 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -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': { diff --git a/src/print/nodes.ts b/src/print/nodes.ts index 13dcbb01..c9e00d50 100644 --- a/src/print/nodes.ts +++ b/src/print/nodes.ts @@ -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; @@ -318,6 +324,7 @@ export type Node = | InstanceScriptNode | ModuleScriptNode | BodyNode + | DocumentNode | OptionsNode | SlotTemplateNode | ConstTagNode; diff --git a/test/printer/samples/svelte-document-element.html b/test/printer/samples/svelte-document-element.html new file mode 100644 index 00000000..98463eea --- /dev/null +++ b/test/printer/samples/svelte-document-element.html @@ -0,0 +1 @@ +