├── .prettierignore
├── src
├── modules.d.ts
├── lib
│ ├── getText.ts
│ ├── elements.ts
│ ├── extractAttributes.ts
│ └── snipTagContent.ts
├── base64-string.ts
├── print
│ ├── helpers.ts
│ ├── doc-helpers.ts
│ └── nodes.ts
├── index.ts
└── options.ts
├── test
├── printer
│ ├── samples
│ │ ├── debug-tag.html
│ │ ├── doctype.html
│ │ ├── comment.html
│ │ ├── if-inline.html
│ │ ├── action.html
│ │ ├── attribute.html
│ │ ├── debug-tag-with-var.html
│ │ ├── element.html
│ │ ├── spread.html
│ │ ├── unicode-element.html
│ │ ├── attribute-shorthand.html
│ │ ├── binding-shorthand.html
│ │ ├── binding.html
│ │ ├── class-shorthand.html
│ │ ├── debug-tag-with-vars.html
│ │ ├── pre-element.html
│ │ ├── unicode-mustache.html
│ │ ├── class.html
│ │ ├── component.html
│ │ ├── element-with-text.html
│ │ ├── if-inline-else.html
│ │ ├── transition-in.html
│ │ ├── attribute-multiple.html
│ │ ├── element-with-mustache.html
│ │ ├── event-handler.html
│ │ ├── if-block.html
│ │ ├── transition-out.html
│ │ ├── attribute-bracket-new-line.html
│ │ ├── attribute-bracket-no-new-line.html
│ │ ├── attribute-bracket-same-line.html
│ │ ├── each-inline.html
│ │ ├── element-with-mustache-no-space.html
│ │ ├── if-inline-elseif.html
│ │ ├── require-pragma-missing.html
│ │ ├── self-closing-tags-lenient.html
│ │ ├── text-html-entities.html
│ │ ├── transition-in-local.html
│ │ ├── transition.html
│ │ ├── action-with-expression.html
│ │ ├── attribute-static-boolean.html
│ │ ├── element-siblings.html
│ │ ├── element-with-multi-mustache.html
│ │ ├── s-after-style-tag.html
│ │ ├── script-inside-comment.html
│ │ ├── single-quote.options.json
│ │ ├── svelte-body-element.html
│ │ ├── svelte-options-element.html
│ │ ├── svelte-window-element.html
│ │ ├── transition-out-local.html
│ │ ├── attribute-dynamic.html
│ │ ├── each-inline-keyed.html
│ │ ├── element-with-multi-mustache-no-space.html
│ │ ├── style-inside-comment.html
│ │ ├── svelte-document-element.html
│ │ ├── transition-local.html
│ │ ├── each-inline-indexed.html
│ │ ├── element-with-children-bracket-new-line.html
│ │ ├── event-with-modifier.html
│ │ ├── insert-pragma-present.html
│ │ ├── insert-pragma-present.options.json
│ │ ├── raw-mustaches.html
│ │ ├── require-pragma-missing.options.json
│ │ ├── script-only.html
│ │ ├── sort-order-none.options.json
│ │ ├── sort-order-none2.options.json
│ │ ├── svelte-component-element.html
│ │ ├── allow-shorthand-true.options.json
│ │ ├── each-block.html
│ │ ├── element-with-children-bracket-no-new-line.html
│ │ ├── element-with-element.html
│ │ ├── if-inline-elseif-else.html
│ │ ├── svelte-element-static-tag.html
│ │ ├── template-empty-with-url.html
│ │ ├── allow-shorthand-false.options.json
│ │ ├── attribute-bracket-same-line.options.json
│ │ ├── each-inline-else.html
│ │ ├── element-siblings-spaced.html
│ │ ├── event-with-modifiers.html
│ │ ├── attribute-bracket-no-new-line.options.json
│ │ ├── each-block-keyed.html
│ │ ├── element-with-attributes-and-mustache.html
│ │ ├── element-with-element-mustache.html
│ │ ├── empty-elements-no-newline.options.json
│ │ ├── indent-script-and-style.options.json
│ │ ├── single-attribute-per-line.options.json
│ │ ├── await-block-with-only-pending.html
│ │ ├── await-inline-without-catch.html
│ │ ├── each-block-indexed.html
│ │ ├── element-with-class-and-comment-inside.html
│ │ ├── event-handler-with-expression.html
│ │ ├── if-block-else.html
│ │ ├── let-shorthand.html
│ │ ├── let.html
│ │ ├── svelte-self-element.html
│ │ ├── animation.html
│ │ ├── attribute-several-bracket-no-new-line.options.json
│ │ ├── await-catch-without-pending.html
│ │ ├── await-inline-without-pending.html
│ │ ├── s-after-style-tag.options.json
│ │ ├── script.html
│ │ ├── unicode-script.html
│ │ ├── allow-shorthand-true.html
│ │ ├── element-many-attributes-bracket-no-new-line.options.json
│ │ ├── element-with-children-bracket-no-new-line.options.json
│ │ ├── script-inside-element.html
│ │ ├── style-unclosed-inside-script.html
│ │ ├── style.html
│ │ ├── typescript-call-generic-function.html
│ │ ├── await-inline-no-args.html
│ │ ├── element-with-element-text-mustache.html
│ │ ├── script-style-script-snipping.options.json
│ │ ├── style-scripts-snipping-spans.options.json
│ │ ├── comment-at-end.html
│ │ ├── comments-above-html-block.html
│ │ ├── style-inside-script.html
│ │ ├── transition-with-expression.html
│ │ ├── await-block-without-pending.html
│ │ ├── await-inline-with-catch-without-pending.html
│ │ ├── each-block-else.html
│ │ ├── sort-order-markup-options-scripts-styles.options.json
│ │ ├── sort-order-markup-options-styles-scripts.options.json
│ │ ├── sort-order-markup-scripts-options-styles.options.json
│ │ ├── sort-order-markup-scripts-styles-options.options.json
│ │ ├── sort-order-markup-styles-options-scripts.options.json
│ │ ├── sort-order-markup-styles-scripts-options.options.json
│ │ ├── sort-order-options-markup-scripts-styles.options.json
│ │ ├── sort-order-options-markup-styles-scripts.options.json
│ │ ├── sort-order-options-scripts-styles-markup.options.json
│ │ ├── sort-order-options-styles-markup-scripts.options.json
│ │ ├── sort-order-options-styles-scripts-markup.options.json
│ │ ├── sort-order-scripts-options-styles-markup.options.json
│ │ ├── sort-order-scripts-styles-markup-options.options.json
│ │ ├── sort-order-scripts-styles-options-markup.options.json
│ │ ├── sort-order-styles-markup-options-scripts.options.json
│ │ ├── sort-order-styles-markup-scripts-options.options.json
│ │ ├── sort-order-styles-options-markup-scripts.options.json
│ │ ├── sort-order-styles-options-scripts-markup.options.json
│ │ ├── sort-order-styles-scripts-markup-options.options.json
│ │ ├── sort-order-styles-scripts-options-markup.options.json
│ │ ├── svelte-head-element.html
│ │ ├── unicode-style.html
│ │ ├── prettier-ignore-script.html
│ │ ├── if-block-elseif.html
│ │ ├── style-with-attributes.html
│ │ ├── script-type-typescript.html
│ │ ├── single-attribute-per-line-bracket-no-new-line.options.json
│ │ ├── style-inside-element.html
│ │ ├── transition-with-expression-local.html
│ │ ├── animation-with-expression.html
│ │ ├── if-block-without-whitespace.html
│ │ ├── script-lang-typescript.html
│ │ ├── jsdoc-parens-in-script.html
│ │ ├── prettier-ignore-nested.html
│ │ ├── toplevel-blocks.html
│ │ ├── toplevel-blocks2.html
│ │ ├── await-block-without-catch.html
│ │ ├── each-block-else-with-nested-if-inline.html
│ │ ├── element-with-several-attributes-and-mustache.html
│ │ ├── event-handler-comments.html
│ │ ├── await-inline.html
│ │ ├── style-lang-less.html
│ │ ├── style-lang-scss.html
│ │ ├── const.html
│ │ ├── style-type-less.html
│ │ ├── style-type-scss.html
│ │ ├── each-block-destructured.html
│ │ ├── prettier-ignore-style.html
│ │ ├── await-block-with-catch-without-pending.html
│ │ ├── each-block-destructured-default-value.html
│ │ ├── each-block-else-with-nested-if-inline-else.html
│ │ ├── indent-script-and-style.html
│ │ ├── await-block-no-args.html
│ │ ├── each-block-else-with-nested-if-block.html
│ │ ├── if-block-elseif-else.html
│ │ ├── script-with-html-comment-and-style.html
│ │ ├── key-block.html
│ │ ├── await-block.html
│ │ ├── each-block-else-with-nested-if-inline-elseif.html
│ │ ├── script-and-style.html
│ │ ├── inline-element-single-text.html
│ │ ├── script-and-module.html
│ │ ├── pre-element-inside-other-element.html
│ │ ├── pre-element-with-code-element.html
│ │ ├── attribute-several.html
│ │ ├── attributes-nested-quotes.html
│ │ ├── component-style-script-tagname.html
│ │ ├── svelte-fragment-element.html
│ │ ├── comments-multiple-above-blocks.html
│ │ ├── svelte-head-script-content.html
│ │ ├── script-tag-generics.html
│ │ ├── attribute-several-bracket-new-line.html
│ │ ├── attribute-several-bracket-no-new-line.html
│ │ ├── hug-content-edge-cases.html
│ │ ├── script-style-inside-element-comment.html
│ │ ├── unsupported-language.html
│ │ ├── each-block-else-with-nested-if-inline-elseif-else.html
│ │ ├── nested-destructuring.html
│ │ ├── typescript-template.html.skip
│ │ ├── await-then-destruct-array.html
│ │ ├── each-block-else-with-nested-if-block-else.html
│ │ ├── sort-order-markup-options-scripts-styles.html
│ │ ├── sort-order-markup-options-styles-scripts.html
│ │ ├── sort-order-markup-scripts-options-styles.html
│ │ ├── sort-order-markup-scripts-styles-options.html
│ │ ├── sort-order-markup-styles-options-scripts.html
│ │ ├── sort-order-markup-styles-scripts-options.html
│ │ ├── sort-order-options-markup-scripts-styles.html
│ │ ├── sort-order-options-markup-styles-scripts.html
│ │ ├── sort-order-options-scripts-styles-markup.html
│ │ ├── sort-order-options-styles-markup-scripts.html
│ │ ├── sort-order-options-styles-scripts-markup.html
│ │ ├── sort-order-scripts-options-styles-markup.html
│ │ ├── sort-order-scripts-styles-markup-options.html
│ │ ├── sort-order-scripts-styles-options-markup.html
│ │ ├── sort-order-styles-markup-options-scripts.html
│ │ ├── sort-order-styles-markup-scripts-options.html
│ │ ├── sort-order-styles-options-markup-scripts.html
│ │ ├── sort-order-styles-options-scripts-markup.html
│ │ ├── sort-order-styles-scripts-markup-options.html
│ │ ├── sort-order-styles-scripts-options-markup.html
│ │ ├── element-with-text-and-inline-element.html
│ │ ├── each-block-else-with-nested-if-block-elseif.html
│ │ ├── allow-shorthand-false.html
│ │ ├── style-script-commented-out.html
│ │ ├── each-block-else-with-nested-if-block-elseif-else.html
│ │ ├── inline-blocks-nested.html
│ │ ├── snippet-ts.html.skip
│ │ ├── template-pug.html
│ │ ├── await-then-destruct-object.html
│ │ ├── prettier-ignore-range.html
│ │ ├── await-then-destruct-object-reassignment.html
│ │ ├── script-style-script-snipping.html
│ │ ├── script-attributes-multiline.html
│ │ ├── svelte-element.html
│ │ ├── sort-order-none.html
│ │ ├── style-scripts-snipping-spans.html
│ │ ├── sort-order-none2.html
│ │ ├── single-quote.html
│ │ ├── attributes-long-text-with-mustache.html
│ │ ├── self-closing-tags.html
│ │ ├── element-many-attributes-bracket-no-new-line.html
│ │ ├── no-tag-snippings.html
│ │ ├── typescript.html
│ │ ├── element-many-attributes-bracket-new-line.html
│ │ ├── typescript-without-lang-attr.html
│ │ ├── empty-elements.html
│ │ ├── empty-elements-no-newline.html
│ │ ├── long-control-blocks-dont-break.html
│ │ ├── snippet.html.skip
│ │ ├── style-directive.html
│ │ ├── await-then-destruct-default.html
│ │ ├── markdown.md
│ │ ├── await-then-destruct-rest.html
│ │ ├── single-attribute-per-line-bracket-no-new-line.html
│ │ └── single-attribute-per-line.html
│ └── index.ts
└── formatting
│ ├── samples
│ ├── empty-element
│ │ ├── input.html
│ │ └── output.html
│ ├── empty-element-whitespace
│ │ ├── input.html
│ │ └── output.html
│ ├── trim-leading-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── trim-line-breaks-text
│ │ ├── output.html
│ │ └── input.html
│ ├── trim-tailing-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── collapse-attribute-shortand
│ │ ├── input.html
│ │ └── output.html
│ ├── collapse-bind-shorthand
│ │ ├── output.html
│ │ └── input.html
│ ├── collapse-class-shorthand
│ │ ├── output.html
│ │ └── input.html
│ ├── insert-pragma
│ │ ├── input.html
│ │ ├── options.json
│ │ └── output.html
│ ├── child-text-leading-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── child-text-tailing-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── collapse-intra-text-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── syntax-error
│ │ ├── options.json
│ │ ├── output.html
│ │ └── input.html
│ ├── attribute-add-quotes
│ │ ├── input.html
│ │ └── output.html
│ ├── collapse-intra-mustache-whitespace
│ │ ├── input.html
│ │ └── output.html
│ ├── require-pragma-present
│ │ ├── options.json
│ │ ├── output.html
│ │ └── input.html
│ ├── allow-shorthand-false
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── attributes-no-newline
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── attributes-bracket-same-line
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── block-element-with-children-no-ws
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-with-children-no-ws
│ │ ├── input.html
│ │ └── output.html
│ ├── single-attribute-per-line
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── attribute-convert-single-quotes
│ │ ├── input.html
│ │ └── output.html
│ ├── collapse-let-shorthand
│ │ ├── output.html
│ │ └── input.html
│ ├── no-html-whitespace-outside-inline-element
│ │ ├── input.html
│ │ └── output.html
│ ├── component-ignore-whitespace
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-break-long-nonewline
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── script-only-extra-whitespace
│ │ ├── output.html
│ │ └── input.html
│ ├── trim-line-breaks-elements
│ │ ├── output.html
│ │ └── input.html
│ ├── all-elements-ignore-whitespace
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── all-elements-strict-whitespace
│ │ ├── options.json
│ │ ├── input.html
│ │ └── output.html
│ ├── trim-whitespace-after-script
│ │ ├── output.html
│ │ └── input.html
│ ├── trim-whitespace-after-style
│ │ ├── options.json
│ │ ├── output.html
│ │ └── input.html
│ ├── block-element-break-subblocks
│ │ ├── input.html
│ │ └── output.html
│ ├── inlineblock-element-break-subblocks
│ │ ├── input.html
│ │ └── output.html
│ ├── scripts-styles-empty-handling
│ │ ├── input.html
│ │ └── output.html
│ ├── wrap-element-attributes-and-children
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-with-hardline
│ │ ├── output.html
│ │ └── input.html
│ ├── no-html-whitespace-inside-inline-element
│ │ ├── input.html
│ │ └── output.html
│ ├── attribute-wrap-several
│ │ ├── input.html
│ │ └── output.html
│ ├── block-element-break-long
│ │ ├── input.html
│ │ └── output.html
│ ├── move-options-to-top
│ │ ├── input.html
│ │ └── output.html
│ ├── block-element-with-children-ws
│ │ ├── output.html
│ │ └── input.html
│ ├── block-element-break-long-whitespace
│ │ ├── input.html
│ │ └── output.html
│ ├── style-directive
│ │ ├── output.html
│ │ └── input.html
│ ├── whitespace-between-tags-and-text
│ │ ├── output.html
│ │ └── input.html
│ ├── block-element-break-children
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-break-children
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-break-long-whitespace
│ │ ├── input.html
│ │ └── output.html
│ ├── const
│ │ ├── input.html
│ │ └── output.html
│ ├── top-level-comments
│ │ ├── input.html
│ │ └── output.html
│ ├── attributes-without-quotes
│ │ ├── input.html
│ │ └── output.html
│ ├── prettier-ignore-range-wrong
│ │ ├── output.html
│ │ └── input.html
│ ├── inline-element-with-children-ws
│ │ ├── input.html
│ │ └── output.html
│ ├── each-await-block-destructuring
│ │ ├── input.html
│ │ └── output.html
│ ├── component-treated-as-inline-element
│ │ ├── input.html
│ │ └── output.html
│ ├── prettier-ignore-range-2
│ │ ├── output.html
│ │ └── input.html
│ ├── prettier-ignore
│ │ ├── input.html
│ │ └── output.html
│ ├── do-not-add-whitespace-between-inline-elements
│ │ ├── input.html
│ │ └── output.html
│ ├── prettier-ignore-range-1
│ │ ├── output.html
│ │ └── input.html
│ ├── attribute-shorthand
│ │ ├── output.html
│ │ └── input.html
│ ├── attribute-with-linebreaks
│ │ ├── input.html
│ │ └── output.html
│ ├── svelte-if-block-break
│ │ ├── input.html
│ │ └── output.html
│ ├── svelte-each-block-break
│ │ ├── input.html
│ │ └── output.html
│ ├── pre-mustache
│ │ ├── input.html
│ │ └── output.html
│ ├── svelte-key-block-break
│ │ ├── input.html
│ │ └── output.html
│ ├── attributes-newline
│ │ ├── input.html
│ │ └── output.html
│ ├── script-style-tags-multiple-nested
│ │ ├── input.html
│ │ └── output.html
│ ├── prettier-ignore-ranges-and-lines
│ │ ├── output.html
│ │ └── input.html
│ ├── long-mustache-value
│ │ ├── input.html
│ │ └── output.html
│ ├── svelte-await-block-break
│ │ ├── input.html
│ │ └── output.html
│ ├── inline-element-break-long
│ │ ├── input.html
│ │ └── output.html
│ ├── attributes-class
│ │ ├── output.html
│ │ └── input.html
│ ├── attribute-remove-quotes
│ │ ├── output.html
│ │ └── input.html
│ └── long-attribute-value
│ │ ├── input.html
│ │ └── output.html
│ └── index.ts
├── .gitignore
├── ava.config.js
├── .prettierrc
├── tsconfig.json
├── wallaby.js
├── .github
└── workflows
│ └── ci.yml
├── LICENSE
├── index.d.ts
├── rollup.config.js
├── package.json
└── README.md
/.prettierignore:
--------------------------------------------------------------------------------
1 | test/**/*.html
--------------------------------------------------------------------------------
/src/modules.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'svelte';
2 |
--------------------------------------------------------------------------------
/test/printer/samples/debug-tag.html:
--------------------------------------------------------------------------------
1 | {@debug}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/doctype.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/comment.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/if-inline.html:
--------------------------------------------------------------------------------
1 | {#if foo}bar{/if}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/action.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/debug-tag-with-var.html:
--------------------------------------------------------------------------------
1 | {@debug a}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/printer/samples/spread.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/unicode-element.html:
--------------------------------------------------------------------------------
1 | Lønn
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/empty-element/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/empty-element/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-shorthand.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/binding-shorthand.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/binding.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/class-shorthand.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/debug-tag-with-vars.html:
--------------------------------------------------------------------------------
1 | {@debug a, b, c}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/pre-element.html:
--------------------------------------------------------------------------------
1 | foo
2 | bar baz
3 |
--------------------------------------------------------------------------------
/test/printer/samples/unicode-mustache.html:
--------------------------------------------------------------------------------
1 | {"Lønn"}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/class.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-text.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
--------------------------------------------------------------------------------
/test/printer/samples/if-inline-else.html:
--------------------------------------------------------------------------------
1 | {#if foo}bar{:else}baz{/if}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-in.html:
--------------------------------------------------------------------------------
1 | fades in
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/empty-element-whitespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/empty-element-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-leading-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-line-breaks-text/output.html:
--------------------------------------------------------------------------------
1 | Hello, world !
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-tailing-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-multiple.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-mustache.html:
--------------------------------------------------------------------------------
1 | hello {name}!
2 |
--------------------------------------------------------------------------------
/test/printer/samples/event-handler.html:
--------------------------------------------------------------------------------
1 | toggle
2 |
--------------------------------------------------------------------------------
/test/printer/samples/if-block.html:
--------------------------------------------------------------------------------
1 | {#if foo}
2 | foo
3 | {/if}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-out.html:
--------------------------------------------------------------------------------
1 | fades out
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-bracket-new-line.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-bracket-no-new-line.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-bracket-same-line.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/each-inline.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}{animal}{/each}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-mustache-no-space.html:
--------------------------------------------------------------------------------
1 | hello_{name}!
2 |
--------------------------------------------------------------------------------
/test/printer/samples/if-inline-elseif.html:
--------------------------------------------------------------------------------
1 | {#if foo}bar{:else if baz}qux{/if}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/require-pragma-missing.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | nope
5 |
--------------------------------------------------------------------------------
/test/printer/samples/self-closing-tags-lenient.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/printer/samples/text-html-entities.html:
--------------------------------------------------------------------------------
1 | &
2 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-in-local.html:
--------------------------------------------------------------------------------
1 | fades in
2 |
--------------------------------------------------------------------------------
/test/printer/samples/transition.html:
--------------------------------------------------------------------------------
1 | fades in and out
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-attribute-shortand/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-attribute-shortand/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-bind-shorthand/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-class-shorthand/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/insert-pragma/input.html:
--------------------------------------------------------------------------------
1 |
2 | format
3 | me
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-leading-whitespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-tailing-whitespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/action-with-expression.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-static-boolean.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-siblings.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-multi-mustache.html:
--------------------------------------------------------------------------------
1 | {greeting} {name}!
2 |
--------------------------------------------------------------------------------
/test/printer/samples/s-after-style-tag.html:
--------------------------------------------------------------------------------
1 |
3 |
4 | sssssweet
5 |
--------------------------------------------------------------------------------
/test/printer/samples/script-inside-comment.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/single-quote.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-body-element.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-options-element.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-window-element.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-out-local.html:
--------------------------------------------------------------------------------
1 | fades out
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/child-text-leading-whitespace/output.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/child-text-tailing-whitespace/output.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-bind-shorthand/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-intra-text-whitespace/output.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/insert-pragma/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "insertPragma": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/insert-pragma/output.html:
--------------------------------------------------------------------------------
1 |
2 | format me
3 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-dynamic.html:
--------------------------------------------------------------------------------
1 | {color}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/each-inline-keyed.html:
--------------------------------------------------------------------------------
1 | {#each todos as todo (todo.id)}{todo}{/each}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-multi-mustache-no-space.html:
--------------------------------------------------------------------------------
1 | {greeting}{name}!
2 |
--------------------------------------------------------------------------------
/test/printer/samples/style-inside-comment.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-document-element.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-local.html:
--------------------------------------------------------------------------------
1 | fades in and out
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .vscode
3 | .history
4 | plugin.js
5 | plugin.js.map
6 | browser.js
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-class-shorthand/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-intra-text-whitespace/input.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/syntax-error/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "expectSyntaxErrors": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-inline-indexed.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal, i}{i}: {animal}{/each}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-children-bracket-new-line.html:
--------------------------------------------------------------------------------
1 | Test
2 |
--------------------------------------------------------------------------------
/test/printer/samples/event-with-modifier.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/insert-pragma-present.html:
--------------------------------------------------------------------------------
1 |
2 | already formatted
3 |
--------------------------------------------------------------------------------
/test/printer/samples/insert-pragma-present.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "insertPragma": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/raw-mustaches.html:
--------------------------------------------------------------------------------
1 |
2 | {@html raw1}
3 | {@html raw2}
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/require-pragma-missing.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "requirePragma": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/script-only.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-none.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "none"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-none2.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "none"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-component-element.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-add-quotes/input.html:
--------------------------------------------------------------------------------
1 | Google
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/child-text-leading-whitespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello, world!
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/child-text-tailing-whitespace/input.html:
--------------------------------------------------------------------------------
1 | Hello, world!
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-intra-mustache-whitespace/input.html:
--------------------------------------------------------------------------------
1 | {greeting} {name}!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-intra-mustache-whitespace/output.html:
--------------------------------------------------------------------------------
1 | {greeting} {name}!
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/require-pragma-present/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "requirePragma": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/require-pragma-present/output.html:
--------------------------------------------------------------------------------
1 |
2 | format me
3 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-line-breaks-text/input.html:
--------------------------------------------------------------------------------
1 | Hello,
2 |
3 |
4 | world
5 |
6 |
7 | !
8 |
--------------------------------------------------------------------------------
/test/printer/samples/allow-shorthand-true.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteAllowShorthand": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-children-bracket-no-new-line.html:
--------------------------------------------------------------------------------
1 | Test
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-element.html:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/if-inline-elseif-else.html:
--------------------------------------------------------------------------------
1 | {#if foo}bar{:else if baz}qux{:else}foobar{/if}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-element-static-tag.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/printer/samples/template-empty-with-url.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/allow-shorthand-false/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteAllowShorthand": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-add-quotes/output.html:
--------------------------------------------------------------------------------
1 | Google
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-no-newline/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/allow-shorthand-false.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteAllowShorthand": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-bracket-same-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "bracketSameLine": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-inline-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}{animal}{:else}no animals{/each}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-siblings-spaced.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/printer/samples/event-with-modifiers.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-bracket-same-line/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "bracketSameLine": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-with-children-no-ws/input.html:
--------------------------------------------------------------------------------
1 | Foo
2 |
3 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-children-no-ws/input.html:
--------------------------------------------------------------------------------
1 | Foo
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/single-attribute-per-line/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleAttributePerLine": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-bracket-no-new-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-keyed.html:
--------------------------------------------------------------------------------
1 | {#each todos as todo (todo.id)}
2 | {todo}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-attributes-and-mustache.html:
--------------------------------------------------------------------------------
1 | {linkText}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-element-mustache.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {score}
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/empty-elements-no-newline.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/indent-script-and-style.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteIndentScriptAndStyle": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/single-attribute-per-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleAttributePerLine": true
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-convert-single-quotes/input.html:
--------------------------------------------------------------------------------
1 | Google
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-convert-single-quotes/output.html:
--------------------------------------------------------------------------------
1 | Google
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-let-shorthand/output.html:
--------------------------------------------------------------------------------
1 |
2 | {foo}
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/no-html-whitespace-outside-inline-element/input.html:
--------------------------------------------------------------------------------
1 | "Bold Italic "
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/no-html-whitespace-outside-inline-element/output.html:
--------------------------------------------------------------------------------
1 | "Bold Italic "
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/require-pragma-present/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | format
4 | me
5 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block-with-only-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {/await}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/await-inline-without-catch.html:
--------------------------------------------------------------------------------
1 | {#await promise}loading{:then}the value is {value}{/await}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-indexed.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal, i}
2 | {i}: {animal}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-class-and-comment-inside.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/event-handler-with-expression.html:
--------------------------------------------------------------------------------
1 | toggle
2 |
--------------------------------------------------------------------------------
/test/printer/samples/if-block-else.html:
--------------------------------------------------------------------------------
1 | {#if foo}
2 | foo
3 | {:else}
4 | not foo
5 | {/if}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/let-shorthand.html:
--------------------------------------------------------------------------------
1 |
2 | Thing #{foo.id}: {foo.title}
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/let.html:
--------------------------------------------------------------------------------
1 |
2 | Thing #{id}: {title}
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-self-element.html:
--------------------------------------------------------------------------------
1 | {#if depth > 1}
2 |
3 | {/if}
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/collapse-let-shorthand/input.html:
--------------------------------------------------------------------------------
1 |
2 | {foo}
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/component-ignore-whitespace/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "htmlWhitespaceSensitivity": "ignore"
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long-nonewline/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/script-only-extra-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-line-breaks-elements/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/printer/samples/animation.html:
--------------------------------------------------------------------------------
1 | {#each things as thing (thing)}
2 | flips
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-several-bracket-no-new-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/await-catch-without-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise catch theCatch}the value is {theCatch}{/await}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/await-inline-without-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise then theValue}the value is {theValue}{/await}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/s-after-style-tag.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-scripts-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/script.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | Hello {name}!
6 |
--------------------------------------------------------------------------------
/test/printer/samples/unicode-script.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | {word}
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-ignore-whitespace/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "htmlWhitespaceSensitivity": "ignore"
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-strict-whitespace/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "htmlWhitespaceSensitivity": "strict"
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-children-no-ws/output.html:
--------------------------------------------------------------------------------
1 | Foo
3 |
4 |
6 |
--------------------------------------------------------------------------------
/test/printer/samples/allow-shorthand-true.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-many-attributes-bracket-no-new-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-children-bracket-no-new-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteBracketNewLine": false
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/script-inside-element.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/test/printer/samples/style-unclosed-inside-script.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/printer/samples/style.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/printer/samples/typescript-call-generic-function.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-with-children-no-ws/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-line-breaks-elements/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test/printer/samples/await-inline-no-args.html:
--------------------------------------------------------------------------------
1 | {#await promise}loading{:then}the value is {value}{:catch}oops {error}{/await}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-element-text-mustache.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Current score: [{score}]
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/script-style-script-snipping.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-scripts-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/style-scripts-snipping-spans.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-scripts-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-whitespace-after-script/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-whitespace-after-style/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-scripts-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/comment-at-end.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/printer/samples/comments-above-html-block.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/printer/samples/style-inside-script.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-with-expression.html:
--------------------------------------------------------------------------------
1 | flies 200 pixels up, slowly
2 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block-without-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise then theValue}
2 | the value is {theValue}
3 | {/await}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/await-inline-with-catch-without-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise then theValue}{theValue}{:catch error}{error}{/await}
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-subblocks/input.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-whitespace-after-script/input.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | no animals
5 | {/each}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-options-scripts-styles.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-options-scripts-styles"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-options-styles-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-options-styles-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-scripts-options-styles.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-scripts-options-styles"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-scripts-styles-options.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-scripts-styles-options"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-styles-options-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-styles-options-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-styles-scripts-options.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "markup-styles-scripts-options"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-markup-scripts-styles.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-markup-scripts-styles"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-markup-styles-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-markup-styles-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-scripts-styles-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-scripts-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-styles-markup-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-styles-markup-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-styles-scripts-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "options-styles-scripts-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-options-styles-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "scripts-options-styles-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-styles-markup-options.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "scripts-styles-markup-options"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-styles-options-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "scripts-styles-options-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-markup-options-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-markup-options-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-markup-scripts-options.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-markup-scripts-options"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-options-markup-scripts.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-options-markup-scripts"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-options-scripts-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-options-scripts-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-scripts-markup-options.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-scripts-markup-options"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-scripts-options-markup.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "svelteSortOrder": "styles-scripts-options-markup"
3 | }
4 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-head-element.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/unicode-style.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/printer/samples/prettier-ignore-script.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Title
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/inlineblock-element-break-subblocks/input.html:
--------------------------------------------------------------------------------
1 | hi
hi hihi
hi hihi
--------------------------------------------------------------------------------
/test/printer/samples/if-block-elseif.html:
--------------------------------------------------------------------------------
1 | {#if x > 10}
2 | x is greater than 10
3 | {:else if x < 5}
4 | x is less than 5
5 | {/if}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/style-with-attributes.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
8 |
--------------------------------------------------------------------------------
/ava.config.js:
--------------------------------------------------------------------------------
1 | process.env.TS_NODE_TRANSPILE_ONLY = true;
2 |
3 | export default {
4 | extensions: ['ts'],
5 | require: ['ts-node/register'],
6 | };
7 |
--------------------------------------------------------------------------------
/test/printer/samples/script-type-typescript.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | Hello {name}!
6 |
--------------------------------------------------------------------------------
/test/printer/samples/single-attribute-per-line-bracket-no-new-line.options.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleAttributePerLine": true,
3 | "bracketSameLine": true
4 | }
5 |
--------------------------------------------------------------------------------
/test/printer/samples/style-inside-element.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/test/printer/samples/transition-with-expression-local.html:
--------------------------------------------------------------------------------
1 |
2 | flies 200 pixels up, slowly
3 |
4 |
--------------------------------------------------------------------------------
/test/formatting/samples/scripts-styles-empty-handling/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/scripts-styles-empty-handling/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/wrap-element-attributes-and-children/input.html:
--------------------------------------------------------------------------------
1 | {linkText}
2 |
--------------------------------------------------------------------------------
/test/printer/samples/animation-with-expression.html:
--------------------------------------------------------------------------------
1 | {#each things as thing (thing)}
2 | {thing.name}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/if-block-without-whitespace.html:
--------------------------------------------------------------------------------
1 | {#each items as item}
2 | {item.name} {#if item.isNew}*{/if}{#if item.isUpdated}!{/if}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/script-lang-typescript.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | Hello {name}!
6 |
--------------------------------------------------------------------------------
/test/printer/samples/jsdoc-parens-in-script.html:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/prettier-ignore-nested.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | .doNotFormatMe
5 | d
6 | d
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test/printer/samples/toplevel-blocks.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
--------------------------------------------------------------------------------
/test/printer/samples/toplevel-blocks2.html:
--------------------------------------------------------------------------------
1 |
3 |
4 | bla
5 |
6 | bla
7 |
8 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-hardline/output.html:
--------------------------------------------------------------------------------
1 | asd
2 |
3 | asdasd
4 |
5 | asd
6 |
7 | asdasd
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/no-html-whitespace-inside-inline-element/input.html:
--------------------------------------------------------------------------------
1 | Apples , Orange , Bananas , Pineapples , Grapefruit , Kiwi
--------------------------------------------------------------------------------
/test/formatting/samples/syntax-error/output.html:
--------------------------------------------------------------------------------
1 |
6 |
7 | This should be formatted anyway.
8 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block-without-catch.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {:then theValue}
4 | the value is {theValue}
5 | {/await}
6 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "useTabs": false,
3 | "printWidth": 100,
4 | "tabWidth": 4,
5 | "semi": true,
6 | "trailingComma": "all",
7 | "singleQuote": true
8 | }
9 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-wrap-several/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/wrap-element-attributes-and-children/output.html:
--------------------------------------------------------------------------------
1 | {linkText}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-inline.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}no dogs{/if}
5 | {/each}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-several-attributes-and-mustache.html:
--------------------------------------------------------------------------------
1 | {linkText}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/event-handler-comments.html:
--------------------------------------------------------------------------------
1 | {
4 | /* another comment */
5 | fn();
6 | }}
7 | >
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/allow-shorthand-false/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/allow-shorthand-false/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-subblocks/output.html:
--------------------------------------------------------------------------------
1 |
2 |
hi
3 |
hi hi
4 |
hi
5 |
hi hi
hi
6 |
7 |
--------------------------------------------------------------------------------
/test/formatting/samples/script-only-extra-whitespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/printer/samples/await-inline.html:
--------------------------------------------------------------------------------
1 | {#await promise}loading{:then value}{value}{:catch error}{error.message}{/await}
2 |
3 | {#await p} l {:then v} {v}
{:catch e} {e.m} {/await}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/style-lang-less.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/style-lang-scss.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/const.html:
--------------------------------------------------------------------------------
1 | {#each [1, 2] as foo}
2 | {@const bar = foo}
3 | {foo}{bar}
4 | {/each}
5 |
6 | {#await aPromise then result}
7 | {@const bar = result}
8 | {/await}
9 |
--------------------------------------------------------------------------------
/test/printer/samples/style-type-less.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/style-type-scss.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-long/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong
looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/inlineblock-element-break-subblocks/output.html:
--------------------------------------------------------------------------------
1 | hi
3 | hi hi
4 | hi
5 | hi hihi
7 |
--------------------------------------------------------------------------------
/test/formatting/samples/move-options-to-top/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | hi
4 |
5 |
6 |
7 | some stuff
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/move-options-to-top/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | hi
6 |
7 | some stuff
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-destructured.html:
--------------------------------------------------------------------------------
1 | {#each animals as [key, value]}
2 | {key}: {value}
3 | {/each}
4 |
5 | {#each animals as [, value]}
6 | {value}
7 | {/each}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/prettier-ignore-style.html:
--------------------------------------------------------------------------------
1 |
3 |
4 | Title
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-strict-whitespace/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong
looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/no-html-whitespace-inside-inline-element/output.html:
--------------------------------------------------------------------------------
1 |
2 | Apples , Orange , Bananas , Pineapples ,
3 | Grapefruit , Kiwi
4 |
5 |
--------------------------------------------------------------------------------
/test/formatting/samples/syntax-error/input.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | This should be formatted anyway.
10 |
11 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block-with-catch-without-pending.html:
--------------------------------------------------------------------------------
1 | {#await thePromise then theValue}
2 | the value is {theValue}
3 | {:catch}
4 | oh no! {theError.message}
5 | {/await}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-destructured-default-value.html:
--------------------------------------------------------------------------------
1 | {#each animals as { key, value = 1, arrayExpr = [{ a: true }], objectExpr = { a: true, b: [1] } }}
2 | {key}: {value}
3 | {/each}
4 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-inline-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}no dogs{:else}no animals{/if}
5 | {/each}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/indent-script-and-style.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block-no-args.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {:then}
4 | the value is {theValue}
5 | {:catch}
6 | oh no! {theError.message}
7 | {/await}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-block.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}
5 | no dogs
6 | {/if}
7 | {/each}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/if-block-elseif-else.html:
--------------------------------------------------------------------------------
1 | {#if x > 10}
2 | x is greater than 10
3 | {:else if x < 5}
4 | x is less than 5
5 | {:else}
6 | x is between 5 and 10
7 | {/if}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/script-with-html-comment-and-style.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-with-children-ws/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 |
4 |
5 |
6 |
7 |
8 | Foo
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-hardline/input.html:
--------------------------------------------------------------------------------
1 |
2 | asd
4 |
5 |
6 | asdasd
8 |
9 | asd
10 |
11 |
12 | asdasd
13 |
--------------------------------------------------------------------------------
/test/printer/samples/key-block.html:
--------------------------------------------------------------------------------
1 | {#key value}
2 | hello
3 | hello
4 | {/key}
5 | {#key $store}
6 | hello
7 | {/key}
8 | {#key expr.obj}
9 | hello
10 | {/key}
11 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-ignore-whitespace/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-long-whitespace/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong
looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
2 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-with-children-ws/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Foo
4 |
5 |
6 |
7 |
8 |
9 |
10 | Foo
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/formatting/samples/style-directive/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/await-block.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {:then theValue}
4 | the value is {theValue}
5 | {:catch theError}
6 | oh no! {theError.message}
7 | {/await}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-inline-elseif.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}no dogs{:else if type === "cat"}no cats{/if}
5 | {/each}
6 |
--------------------------------------------------------------------------------
/test/printer/samples/script-and-style.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | Hello {name}!
6 |
7 |
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-whitespace-after-style/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/whitespace-between-tags-and-text/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Text
4 |
5 |
6 | Text
7 |
8 |
9 |
10 | Text
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/inline-element-single-text.html:
--------------------------------------------------------------------------------
1 | hi
2 | hi
3 | hi
4 | hi
5 | {hi}
6 | {hi}
7 | {hi}
8 | {hi}
9 |
--------------------------------------------------------------------------------
/test/printer/samples/script-and-module.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 | Hello {name}!
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/style-directive/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/pre-element-inside-other-element.html:
--------------------------------------------------------------------------------
1 |
2 |
foo
3 | bar
4 |
5 | bold d
6 |
7 |
8 |
9 | bold d
10 |
11 | baz
12 |
13 |
--------------------------------------------------------------------------------
/test/printer/samples/pre-element-with-code-element.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | const greeting = "Hello",
4 | name = "World",
5 | text = greeting + ", " + name + "!";
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/trim-whitespace-after-style/input.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-several.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/attributes-nested-quotes.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/printer/samples/component-style-script-tagname.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-fragment-element.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | hi
4 |
5 | hi
6 |
--------------------------------------------------------------------------------
/test/printer/samples/comments-multiple-above-blocks.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-head-script-content.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es6",
4 | "module": "commonjs",
5 | "strict": true,
6 | "esModuleInterop": true
7 | },
8 | "include": ["src/**/*", "index.d.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-strict-whitespace/output.html:
--------------------------------------------------------------------------------
1 | looooooooooong
looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
7 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-wrap-several/output.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/whitespace-between-tags-and-text/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Text
5 |
6 |
7 | Text
8 |
9 |
10 |
11 |
12 | Text
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/test/printer/samples/script-tag-generics.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | d
6 |
7 |
12 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-several-bracket-new-line.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/attribute-several-bracket-no-new-line.html:
--------------------------------------------------------------------------------
1 |
9 |
10 |
--------------------------------------------------------------------------------
/test/printer/samples/hug-content-edge-cases.html:
--------------------------------------------------------------------------------
1 | hi
3 |
4 |
5 |
6 | hithere
8 |
--------------------------------------------------------------------------------
/test/printer/samples/script-style-inside-element-comment.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/test/printer/samples/unsupported-language.html:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-children/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-long/output.html:
--------------------------------------------------------------------------------
1 |
2 |
looooooooooong
3 | looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
4 |
8 |
9 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-inline-elseif-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}
5 | no dogs
6 | {:else if type === "cat"}no cats{:else}no animals{/if}
7 | {/each}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/nested-destructuring.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {:then { data: [theValue] }}
4 | the value is {theValue}
5 | {:catch { data: [{ data: [theError] }] }}
6 | oh no! {theError.message}
7 | {/await}
8 |
--------------------------------------------------------------------------------
/test/printer/samples/typescript-template.html.skip:
--------------------------------------------------------------------------------
1 |
2 |
3 | {
5 | e as any;
6 | }}>foo
8 |
9 | e.detail}>{bar as any}
10 |
--------------------------------------------------------------------------------
/test/printer/samples/await-then-destruct-array.html:
--------------------------------------------------------------------------------
1 | {#await thePromise}
2 | loading...
3 | {:then [a, b]}
4 | a: {a}
5 | b: {b}
6 | {:catch [c, [d, e]]}
7 | c: {c}
8 | d: {d}
9 | e: {e}
10 | {/await}
11 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-block-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}
5 | no dogs
6 | {:else}
7 | no animals
8 | {/if}
9 | {/each}
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-long-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 |
looooooooooong
3 | looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
4 |
8 |
9 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-children/input.html:
--------------------------------------------------------------------------------
1 | asd
asd
2 |
3 | asd asd
4 |
5 | asd
asd
6 |
7 | asd asd
8 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-options-scripts-styles.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
4 |
5 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-options-styles-scripts.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
4 |
5 |
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-scripts-options-styles.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
6 |
7 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-scripts-styles-options.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-styles-options-scripts.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
8 |
9 |
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-markup-styles-scripts-options.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-markup-scripts-styles.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello {name}!
4 |
5 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-markup-styles-scripts.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello {name}!
4 |
5 |
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-scripts-styles-markup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-styles-markup-scripts.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 | Hello {name}!
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-options-styles-scripts-markup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-options-styles-markup.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-styles-markup-options.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 | Hello {name}!
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-scripts-styles-options-markup.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-markup-options-scripts.html:
--------------------------------------------------------------------------------
1 |
6 |
7 | Hello {name}!
8 |
9 |
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-markup-scripts-options.html:
--------------------------------------------------------------------------------
1 |
6 |
7 | Hello {name}!
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-options-markup-scripts.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | Hello {name}!
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-options-scripts-markup.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-scripts-markup-options.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
10 |
11 | Hello {name}!
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-styles-scripts-options-markup.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
10 |
11 |
12 |
13 | Hello {name}!
14 |
--------------------------------------------------------------------------------
/test/printer/samples/element-with-text-and-inline-element.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | This is line A.
4 | This is B. len(A + B) > 80+ chars. len(b) lt; 80.
5 |
6 |
This is line A. This is B. len(A + B) < 80 chars.
7 |
8 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-block-elseif.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}
5 | no dogs
6 | {:else if type === "cat"}
7 | no cats
8 | {/if}
9 | {/each}
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/all-elements-ignore-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 | looooooooooong
3 | looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
4 |
5 | hi
6 | hi
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test/printer/samples/allow-shorthand-false.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long-whitespace/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong hi hi looooooooooonglooooooooooonglooooooooooonglooooooooooong
--------------------------------------------------------------------------------
/test/formatting/samples/const/input.html:
--------------------------------------------------------------------------------
1 | {#each [1, 2] as foo}
2 | {@const bar =
3 | foo}
4 | {foo}{bar}
5 | {/each}
6 |
7 | {#await aPromise then result}
8 | {@const bar = result ? 'some super long text which will force the ternary to break' : 'etc etc'}
9 | {/await}
10 |
--------------------------------------------------------------------------------
/test/formatting/samples/top-level-comments/input.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | Title
7 |
8 |
9 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/formatting/samples/top-level-comments/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 | Title
10 |
11 |
12 |
14 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-without-quotes/input.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | asd
7 |
8 |
9 |
10 |
11 |
14 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-wrong/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
no format madness here
5 |
6 |
no toplevel
7 |
8 |
9 |
10 |
11 | We all need to adhere sadly
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/const/output.html:
--------------------------------------------------------------------------------
1 | {#each [1, 2] as foo}
2 | {@const bar = foo}
3 | {foo}{bar}
4 | {/each}
5 |
6 | {#await aPromise then result}
7 | {@const bar = result
8 | ? "some super long text which will force the ternary to break"
9 | : "etc etc"}
10 | {/await}
11 |
--------------------------------------------------------------------------------
/test/printer/samples/style-script-commented-out.html:
--------------------------------------------------------------------------------
1 |
4 |
7 |
8 |
11 |
16 |
--------------------------------------------------------------------------------
/wallaby.js:
--------------------------------------------------------------------------------
1 | module.exports = function (w) {
2 | return {
3 | files: ['src/**/*.ts', 'test/**/*.html'],
4 | tests: ['test/**/*.ts'],
5 | env: {
6 | type: 'node',
7 | runner: 'node',
8 | },
9 | testFramework: 'ava',
10 | };
11 | };
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-children-ws/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Foo
4 |
5 |
6 |
7 |
8 |
9 |
10 | Foo
11 |
12 |
13 |
14 |
15 |
16 |
17 | Text
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-wrong/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
no format madness here
5 |
6 |
7 | no
8 | toplevel
9 |
10 |
11 |
12 |
13 |
14 | We all need to adhere sadly
15 |
--------------------------------------------------------------------------------
/test/formatting/samples/component-ignore-whitespace/input.html:
--------------------------------------------------------------------------------
1 | buy !
2 |
3 | buy me a !
4 |
5 | buy me a coffee !
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/each-await-block-destructuring/input.html:
--------------------------------------------------------------------------------
1 | {#each arr as { a,b =''}}
2 | {a}
3 | {b}
4 | {/each}
5 |
6 | {#await promise then { a,b =''}}
7 | {a}
8 | {b}
9 | {/await}
10 |
11 | {#await promise}
12 | Loading
13 | {:then { a,b =''}}
14 | {a}
15 | {b}
16 | {/await}
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-with-children-ws/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 |
4 |
5 |
6 |
7 |
8 | Foo
9 |
10 |
11 |
12 |
13 |
14 |
15 | Text
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/component-treated-as-inline-element/input.html:
--------------------------------------------------------------------------------
1 | buy !
2 |
3 | buy me a !
4 |
5 | buy me a coffee !
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/each-await-block-destructuring/output.html:
--------------------------------------------------------------------------------
1 | {#each arr as { a, b = '' }}
2 | {a}
3 | {b}
4 | {/each}
5 |
6 | {#await promise then { a, b = '' }}
7 | {a}
8 | {b}
9 | {/await}
10 |
11 | {#await promise}
12 | Loading
13 | {:then { a, b = '' }}
14 | {a}
15 | {b}
16 | {/await}
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long-whitespace/output.html:
--------------------------------------------------------------------------------
1 |
2 | looooooooooong
3 | looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooong
4 | hi hi
5 | looooooooooonglooooooooooonglooooooooooonglooooooooooong
6 |
7 |
--------------------------------------------------------------------------------
/test/printer/samples/each-block-else-with-nested-if-block-elseif-else.html:
--------------------------------------------------------------------------------
1 | {#each animals as animal}
2 | {animal}
3 | {:else}
4 | {#if type === "dog"}
5 | no dogs
6 | {:else if type === "cat"}
7 | no cats
8 | {:else}
9 | no animals
10 | {/if}
11 | {/each}
12 |
--------------------------------------------------------------------------------
/test/printer/samples/inline-blocks-nested.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | asd1
4 |
5 | asd2
6 |
7 |
8 |
9 |
10 | asd1
11 |
12 | asd2
13 | asd3
14 | asd4
15 | asd5
16 |
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-without-quotes/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | asd
6 |
7 |
10 |
11 |
12 |
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-2/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | I need to adhere sadly
6 |
7 |
8 |
9 | format madness here
10 |
11 |
12 | I'm
13 | freeeee!
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/printer/samples/snippet-ts.html.skip:
--------------------------------------------------------------------------------
1 |
3 |
4 | {#snippet test1(arg: string)}
5 | foo
6 | {/snippet}
7 |
8 | {#snippet test2(arg: (typeof obj)["key"])}
9 | foo
10 | {/snippet}
11 |
12 | {#snippet test3({ onselect }: { onselect: (value: string) => void })}
13 | foo
14 | {/snippet}
15 |
--------------------------------------------------------------------------------
/test/printer/samples/template-pug.html:
--------------------------------------------------------------------------------
1 |
2 | h1 My Title
3 |
4 | div
5 | p Hey
6 | +if('foo')
7 | bar
8 |
9 |
10 |
11 | h1 My Title
12 |
13 | div
14 | p Hey
15 | +if('foo')
16 | bar
17 |
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/do-not-add-whitespace-between-inline-elements/input.html:
--------------------------------------------------------------------------------
1 | Orange Bananas Pineapples Grapefruit Kiwi
2 |
3 | asdOrange Bananas Pineapples Grapefruit Kiwi
4 |
5 | Apples Orange Bananas Pineapples Grapefruit Kiwi
6 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-2/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | I need to adhere sadly
4 |
5 |
6 |
7 | format madness here
8 |
9 |
10 | I'm
11 | freeeee!
12 |
13 |
14 |
15 |
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/block-element-break-children/output.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
15 |
16 |
20 |
--------------------------------------------------------------------------------
/test/printer/samples/await-then-destruct-object.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | {#await thePromise}
6 | loading...
7 | {:then { result, error }}
8 | error: {error}
9 | result: {result}
10 | {:catch { error: { message, code } }}
11 | message: {message}
12 | code: {code}
13 | {/await}
14 |
--------------------------------------------------------------------------------
/test/printer/samples/prettier-ignore-range.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | I need to adhere sadly
6 |
7 |
8 |
9 | format madness here
10 |
11 |
12 | I'm
13 | freeeee!
14 |
15 |
16 |
17 |
18 | I need to adhere sadly
19 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-children/output.html:
--------------------------------------------------------------------------------
1 | asd
3 | asd
5 |
6 | asd
8 | asd
10 |
11 |
12 | asd
13 | asd
14 |
15 |
16 |
17 | asd
18 | asd
19 |
20 |
--------------------------------------------------------------------------------
/test/printer/samples/await-then-destruct-object-reassignment.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | {#await thePromise}
6 | loading...
7 | {:then { result: r, error: e }}
8 | error: {e}
9 | result: {r}
10 | {:catch { error: { message: m, code: c } }}
11 | message: {m}
12 | code: {c}
13 | {/await}
14 |
--------------------------------------------------------------------------------
/test/printer/samples/script-style-script-snipping.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-1/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | I need to adhere sadly
6 |
7 |
8 |
9 | format madness here
10 |
11 |
12 | I'm
13 | freeeee!
14 |
15 |
16 |
17 |
18 | I need to adhere sadly
19 |
--------------------------------------------------------------------------------
/test/formatting/samples/component-ignore-whitespace/output.html:
--------------------------------------------------------------------------------
1 | buy !
2 |
3 |
4 | buy me a !
5 |
6 |
7 |
8 |
9 | buy me a coffee
10 | !
11 |
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/component-treated-as-inline-element/output.html:
--------------------------------------------------------------------------------
1 | buy !
2 |
3 |
4 | buy me a !
5 |
6 |
7 |
8 | buy me a coffee !
11 |
12 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-shorthand/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
--------------------------------------------------------------------------------
/test/formatting/samples/do-not-add-whitespace-between-inline-elements/output.html:
--------------------------------------------------------------------------------
1 | Orange Bananas Pineapples Grapefruit Kiwi
2 |
3 |
4 | asdOrange Bananas Pineapples Grapefruit Kiwi
5 |
6 |
7 |
8 | Apples Orange Bananas Pineapples Grapefruit Kiwi
11 |
12 |
--------------------------------------------------------------------------------
/test/printer/samples/script-attributes-multiline.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/test/printer/samples/svelte-element.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-with-linebreaks/input.html:
--------------------------------------------------------------------------------
1 | {
6 | return item + 1
7 | })}
8 | >
9 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-with-linebreaks/output.html:
--------------------------------------------------------------------------------
1 | {
6 | return item + 1;
7 | })}
8 | >
9 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-range-1/input.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 | I need to adhere sadly
8 |
9 |
10 |
11 | format madness here
12 |
13 |
14 | I'm
15 | freeeee!
16 |
17 |
18 |
19 |
20 | I need to adhere sadly
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-none.html:
--------------------------------------------------------------------------------
1 | Hello {name}!
2 |
3 |
4 |
5 | yeah why not
6 |
7 |
10 |
11 |
14 |
15 | I hope noone orders them like this
16 |
17 |
22 |
23 | I really do
24 |
--------------------------------------------------------------------------------
/test/printer/samples/style-scripts-snipping-spans.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-shorthand/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/printer/samples/sort-order-none2.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | Hello {name}!
6 |
7 |
8 |
9 |
10 | yeah why not
11 |
12 |
13 |
16 |
17 | I hope noone orders them like this
18 |
19 |
24 |
25 | I really do
26 |
--------------------------------------------------------------------------------
/test/printer/samples/single-quote.html:
--------------------------------------------------------------------------------
1 | asd
2 |
3 | {#if 'foo'}a{:else if 'bar'}b{/if}
4 |
5 | {#await Promise.resolve('hi')}a{/await}
6 |
7 | {#each ['a'] as b}a{/each}
8 |
9 | "{'hello'}" world
10 |
11 | console.log('hi')}>hi
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-if-block-break/input.html:
--------------------------------------------------------------------------------
1 | {#if bla}loooooooooooooooooooooooooooooong
{:else if blubb}loooooooooooooooooooooooooooooong
{/if}
2 |
3 | {#if bla} loooooooooooooooooooooooooooooong
{:else if blubb} loooooooooooooooooooooooooooooong
{/if}
4 |
5 | {#if bla}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{:else if blubb}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{/if}
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-each-block-break/input.html:
--------------------------------------------------------------------------------
1 | {#each bla as blubb}loooooooooooooooooooooooooooooong
{:else}loooooooooooooooooooooooooooooong
{/each}
2 |
3 | {#each bla as blubb} loooooooooooooooooooooooooooooong
{:else} loooooooooooooooooooooooooooooong
{/each}
4 |
5 | {#each bla as blubb}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{:else}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{/each}
--------------------------------------------------------------------------------
/test/printer/samples/attributes-long-text-with-mustache.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/test/formatting/samples/pre-mustache/input.html:
--------------------------------------------------------------------------------
1 | Hello,
2 | world! {JSON.stringify({ foo:'bar'},null,
3 | 2)}Goodbye.
4 | this text goes waaaaaaaaaaaaaaaaaaaaaaaaaaaaaayyyyyyyyyyyyyyyyyyyyyyyyyyy above the print width {{a: true}} and the mustache should split it
5 | const asd = {
6 | variable };
7 | nested
8 |
9 | should
10 |
11 | stay
12 |
13 | as is
14 |
15 | this line is intended using tabs which should be preserved
16 |
17 |
--------------------------------------------------------------------------------
/test/printer/samples/self-closing-tags.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/test/formatting/samples/pre-mustache/output.html:
--------------------------------------------------------------------------------
1 | Hello,
2 | world! {JSON.stringify({ foo: "bar" }, null, 2)}Goodbye.
3 | this text goes waaaaaaaaaaaaaaaaaaaaaaaaaaaaaayyyyyyyyyyyyyyyyyyyyyyyyyyy above the print width {{
4 | a: true,
5 | }} and the mustache should split it
6 | const asd = {variable};
7 | nested
9 |
10 | should
11 |
12 | stay
13 |
14 | as is
15 |
16 | this line is intended using tabs which should be preserved
17 |
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-key-block-break/input.html:
--------------------------------------------------------------------------------
1 | {#key bla}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{/key}
2 |
3 | {#key bla} loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{/key}
4 |
5 | {#key bla} loooooooooooooooooooooooooooooong loooooooooooooooooooooooooooooong {/key}
6 |
7 | {#key bla}loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
loooooooooooooooooooooooooooooong
{/key}
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-newline/input.html:
--------------------------------------------------------------------------------
1 | Copy
2 | Copy
3 | Copy
4 | Copy
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-no-newline/input.html:
--------------------------------------------------------------------------------
1 | Copy
2 | Copy
3 | Copy
4 | Copy
--------------------------------------------------------------------------------
/test/formatting/samples/script-style-tags-multiple-nested/input.html:
--------------------------------------------------------------------------------
1 | above
2 |
5 | below
6 |
7 |
8 |
above
9 |
12 |
below
13 |
14 |
15 |
16 |
above
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
--------------------------------------------------------------------------------
/test/formatting/samples/script-style-tags-multiple-nested/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 | above
6 | below
7 |
8 |
9 |
above
10 |
13 |
below
14 |
15 |
16 |
17 |
above
18 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
--------------------------------------------------------------------------------
/test/printer/samples/element-many-attributes-bracket-no-new-line.html:
--------------------------------------------------------------------------------
1 |
25 |
--------------------------------------------------------------------------------
/test/printer/samples/no-tag-snippings.html:
--------------------------------------------------------------------------------
1 |
2 |
8 | {@html ``}
9 |
10 |
11 |
12 | {`
13 | Hello
14 | World
15 |
16 |
17 | `}
22 |
23 |
--------------------------------------------------------------------------------
/test/printer/samples/typescript.html:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-bracket-same-line/input.html:
--------------------------------------------------------------------------------
1 | Copy
2 | Copy
3 | Copy
4 | Copy
--------------------------------------------------------------------------------
/test/printer/samples/element-many-attributes-bracket-new-line.html:
--------------------------------------------------------------------------------
1 |
26 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-if-block-break/output.html:
--------------------------------------------------------------------------------
1 | {#if bla}loooooooooooooooooooooooooooooong
{:else if blubb}
2 | loooooooooooooooooooooooooooooong
3 |
{/if}
4 |
5 | {#if bla}
6 | loooooooooooooooooooooooooooooong
7 | {:else if blubb}
8 | loooooooooooooooooooooooooooooong
9 | {/if}
10 |
11 | {#if bla}loooooooooooooooooooooooooooooong
12 | loooooooooooooooooooooooooooooong
{:else if blubb}
13 | loooooooooooooooooooooooooooooong
14 |
15 | loooooooooooooooooooooooooooooong
{/if}
16 |
--------------------------------------------------------------------------------
/test/printer/samples/typescript-without-lang-attr.html:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-each-block-break/output.html:
--------------------------------------------------------------------------------
1 | {#each bla as blubb}loooooooooooooooooooooooooooooong
{:else}
2 | loooooooooooooooooooooooooooooong
3 |
{/each}
4 |
5 | {#each bla as blubb}
6 | loooooooooooooooooooooooooooooong
7 | {:else}
8 | loooooooooooooooooooooooooooooong
9 | {/each}
10 |
11 | {#each bla as blubb}loooooooooooooooooooooooooooooong
12 | loooooooooooooooooooooooooooooong
{:else}
13 | loooooooooooooooooooooooooooooong
14 |
15 | loooooooooooooooooooooooooooooong
{/each}
16 |
--------------------------------------------------------------------------------
/test/printer/samples/empty-elements.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
12 |
13 |
14 |
17 |
--------------------------------------------------------------------------------
/test/printer/samples/empty-elements-no-newline.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
11 |
12 |
13 |
15 |
16 |
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-ranges-and-lines/output.html:
--------------------------------------------------------------------------------
1 | I need to adhere sadly
2 |
3 |
4 |
5 | format madness here
6 |
7 |
8 | I'm
9 | freeeee!
10 |
11 |
12 |
13 |
14 | I need to adhere sadly
15 |
16 |
17 |
18 | format madness here
19 |
20 |
21 | I'm
22 | freeeee!
23 |
24 |
25 |
26 |
27 |
28 |
29 | I'm
30 | freeeee!
31 |
32 | I need to adhere sadly
33 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-key-block-break/output.html:
--------------------------------------------------------------------------------
1 | {#key bla}loooooooooooooooooooooooooooooong
2 | loooooooooooooooooooooooooooooong
{/key}
3 |
4 | {#key bla}
5 | loooooooooooooooooooooooooooooong
6 | loooooooooooooooooooooooooooooong
7 | {/key}
8 |
9 | {#key bla}
10 | loooooooooooooooooooooooooooooong
11 | loooooooooooooooooooooooooooooong
12 | {/key}
13 |
14 | {#key bla}loooooooooooooooooooooooooooooong
15 | loooooooooooooooooooooooooooooong
16 | loooooooooooooooooooooooooooooong
17 | loooooooooooooooooooooooooooooong
{/key}
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/long-mustache-value/input.html:
--------------------------------------------------------------------------------
1 |
5 |
6 | Text with spaces inbetween should break at the most fitting point and not wait for a {'breakable' + 'mustache tags'} to be broken up. {'If the mustache tag itself is very long, however' + 'it should be broken uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuup'} {andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaakaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
7 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-no-newline/output.html:
--------------------------------------------------------------------------------
1 |
3 | Copy
4 |
5 |
7 | Copy
8 |
9 |
11 | Copy
12 |
13 |
15 | Copy
16 |
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-bracket-same-line/output.html:
--------------------------------------------------------------------------------
1 |
3 | Copy
4 |
5 |
7 | Copy
8 |
9 |
11 | Copy
12 |
13 |
15 | Copy
16 |
17 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-newline/output.html:
--------------------------------------------------------------------------------
1 |
4 | Copy
5 |
6 |
9 | Copy
10 |
11 |
14 | Copy
15 |
16 |
19 | Copy
20 |
21 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-await-block-break/input.html:
--------------------------------------------------------------------------------
1 | {#await bla}loooooooooooooooooooooong
{:then blubb}loooooooooooooooooooooong
{:catch}loooooooooooooooooooooong
{/await}
2 |
3 | {#await bla} loooooooooooooooooooooong
{:then blubb} loooooooooooooooooooooong
{:catch} loooooooooooooooooooooong
{/await}
4 |
5 | {#await bla}loooooooooooooooooooooong
loooooooooooooooooooooong
{:then blubb}loooooooooooooooooooooong
loooooooooooooooooooooong
{:catch}loooooooooooooooooooooong
loooooooooooooooooooooong
{/await}
6 |
7 | {#await bla then blubb} loooooooooooooooooooooong
{:catch} loooooooooooooooooooooong
{/await}
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
--------------------------------------------------------------------------------
/test/formatting/samples/prettier-ignore-ranges-and-lines/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | I need to adhere sadly
4 |
5 |
6 |
7 | format madness here
8 |
9 |
10 | I'm
11 | freeeee!
12 |
13 |
14 |
15 |
16 | I need to adhere sadly
17 |
18 |
19 |
20 |
21 |
22 |
23 | format madness here
24 |
25 |
26 | I'm
27 | freeeee!
28 |
29 |
30 |
31 |
32 |
33 |
34 | I'm
35 | freeeee!
36 |
37 | I need to adhere sadly
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long-nonewline/input.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
--------------------------------------------------------------------------------
/test/printer/samples/long-control-blocks-dont-break.html:
--------------------------------------------------------------------------------
1 | {#if andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak === true && cool}
2 | a
3 | {:else if andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak === true && cool}
4 | b
5 | {/if}
6 |
7 | {#each [1, andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak] as { cool, veryCool }}
8 | a
9 | {/each}
10 |
11 | {#key andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak.no.no.no}
12 | a
13 | {/key}
14 |
15 | {#await Promise.resolve(andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak) then cool}
16 | a
17 | {/await}
18 |
--------------------------------------------------------------------------------
/test/formatting/samples/long-mustache-value/output.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 | Text with spaces inbetween should break at the most fitting point and not
9 | wait for a {"breakable" + "mustache tags"} to be broken up. {"If the mustache tag itself is very long, however" +
10 | "it should be broken uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuup"}
11 | {andIiiiiiiiiiiiiiiiiiiiiiiiiiiWillNeverBreaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaakaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
12 |
13 |
--------------------------------------------------------------------------------
/test/printer/samples/snippet.html.skip:
--------------------------------------------------------------------------------
1 | {#snippet foo()}
2 | foo
3 | {/snippet}
4 |
5 | {#snippet bar({ a, b })}
6 | bar
7 | {/snippet}
8 |
9 | {#snippet baz(a, b, c = 1)}
10 | baz
11 | {/snippet}
12 |
13 |
14 | {#snippet loooongFunction(
15 | a,
16 | lot,
17 | _of,
18 | parameters,
19 | that,
20 | make,
21 | the,
22 | lines,
23 | _break,
24 | )}
25 |
baz
26 | {/snippet}
27 |
28 |
29 | {@render foo()}
30 | {@render foo?.()}
31 | {@render bar(x)}
32 | {@render bar.baz[buzz](x)}
33 | {@render (why ? not : like ?? thiss)(x)}
34 | {@render test((() => "a")())}
35 | {@render test(t())}
36 |
--------------------------------------------------------------------------------
/test/printer/samples/style-directive.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-class/output.html:
--------------------------------------------------------------------------------
1 |
4 | Copy
5 |
6 |
9 | Copy
10 |
11 |
16 | Copy
17 |
18 |
23 | Copy
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/test/formatting/samples/attributes-class/input.html:
--------------------------------------------------------------------------------
1 |
4 | Copy
5 |
6 |
9 | Copy
10 |
11 |
16 | Copy
17 |
18 |
23 | Copy
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/lib/getText.ts:
--------------------------------------------------------------------------------
1 | import { ParserOptions } from '../options';
2 | import { Node } from '../print/nodes';
3 | import { hasSnippedContent, unsnipContent } from './snipTagContent';
4 |
5 | export function getText(node: Node, options: ParserOptions, unsnip = false) {
6 | const leadingComments: Node[] = (node as any).leadingComments;
7 | const text = options.originalText.slice(
8 | options.locStart(
9 | // if there are comments before the node they are not included
10 | // in the `start` of the node itself
11 | (leadingComments && leadingComments[0]) || node,
12 | ),
13 | options.locEnd(node),
14 | );
15 |
16 | if (!unsnip || !hasSnippedContent(text)) {
17 | return text;
18 | }
19 |
20 | return unsnipContent(text);
21 | }
22 |
--------------------------------------------------------------------------------
/test/formatting/samples/svelte-await-block-break/output.html:
--------------------------------------------------------------------------------
1 | {#await bla}loooooooooooooooooooooong
{:then blubb}
2 | loooooooooooooooooooooong
3 |
{:catch}loooooooooooooooooooooong
{/await}
4 |
5 | {#await bla}
6 | loooooooooooooooooooooong
7 | {:then blubb}
8 | loooooooooooooooooooooong
9 | {:catch}
10 | loooooooooooooooooooooong
11 | {/await}
12 |
13 | {#await bla}loooooooooooooooooooooong
14 | loooooooooooooooooooooong
{:then blubb}
15 | loooooooooooooooooooooong
16 |
17 | loooooooooooooooooooooong
{:catch}loooooooooooooooooooooong
18 | loooooooooooooooooooooong
{/await}
19 |
20 | {#await bla then blubb}
21 | loooooooooooooooooooooong
22 | {:catch}
23 | loooooooooooooooooooooong
24 | {/await}
25 |
--------------------------------------------------------------------------------
/test/printer/samples/await-then-destruct-default.html:
--------------------------------------------------------------------------------
1 |
7 |
8 | {#await object then { a = 3, b = 4, c }}
9 | a: {a}
10 | b: {b}
11 | c: {c}
12 | {/await}
13 |
14 | {#await array then [a, b, c = 3]}
15 | a: {a}
16 | b: {b}
17 | c: {c}
18 | {/await}
19 |
20 | {#await objectReject then value}
21 | resolved
22 | {:catch { a = 3, b = 4, c }}
23 | a: {a}
24 | b: {b}
25 | c: {c}
26 | {/await}
27 |
28 | {#await arrayReject then value}
29 | resolved
30 | {:catch [a, b, c = 3]}
31 | a: {a}
32 | b: {b}
33 | c: {c}
34 | {/await}
35 |
--------------------------------------------------------------------------------
/test/formatting/samples/attribute-remove-quotes/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Link
16 | Link
17 | console.log("hi")}>hi
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/test/printer/samples/markdown.md:
--------------------------------------------------------------------------------
1 | This is a markdown file with embedded Svelte content. Prettier can format this
2 | by offloading the formatting of the fenced code block to prettier-plugin-svelte.
3 |
4 | ```svelte
5 |
8 |
9 |
12 |
13 | {greeting}, {name}!
14 |
15 |
20 | ```
21 |
22 | ```svelte
23 |
26 | ```
27 |
28 | ```svelte
29 | {greeting}, {name}!
30 |
31 |
36 | ```
37 |
38 | ```svelte
39 |
42 |
43 | {greeting}, {name}!
44 | ```
45 |
46 | ```svelte
47 | {greeting}, {name}!
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Link
16 | Link
17 | hi
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/base64-string.ts:
--------------------------------------------------------------------------------
1 | // Base64 string encoding and decoding module.
2 | // Uses Buffer for Node.js and btoa/atob for browser environments.
3 | // We use TextEncoder/TextDecoder for browser environments because
4 | // they can handle non-ASCII characters, unlike btoa/atob.
5 |
6 | export const stringToBase64 =
7 | typeof Buffer !== 'undefined'
8 | ? (str: string) => Buffer.from(str).toString('base64')
9 | : (str: string) =>
10 | btoa(
11 | new TextEncoder()
12 | .encode(str)
13 | .reduce((acc, byte) => acc + String.fromCharCode(byte), ''),
14 | );
15 |
16 | export const base64ToString =
17 | typeof Buffer !== 'undefined'
18 | ? (str: string) => Buffer.from(str, 'base64').toString()
19 | : (str: string) =>
20 | new TextDecoder().decode(Uint8Array.from(atob(str), (c) => c.charCodeAt(0)));
21 |
--------------------------------------------------------------------------------
/test/printer/samples/await-then-destruct-rest.html:
--------------------------------------------------------------------------------
1 |
7 |
8 | {#await object then { a, ...rest }}
9 | a: {a}
10 | rest: {JSON.stringify(rest)}
11 | {/await}
12 |
13 | {#await array then [a, b, ...rest]}
14 | a: {a}
15 | b: {b}
16 | rest: {JSON.stringify(rest)}
17 | {/await}
18 |
19 | {#await objectReject then value}
20 | resolved
21 | {:catch { a, ...rest }}
22 | a: {a}
23 | rest: {JSON.stringify(rest)}
24 | {/await}
25 |
26 | {#await arrayReject then value}
27 | resolved
28 | {:catch [a, b, ...rest]}
29 | a: {a}
30 | b: {b}
31 | rest: {JSON.stringify(rest)}
32 | {/await}
33 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long-nonewline/output.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi
6 |
7 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi
13 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
18 |
19 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
24 |
--------------------------------------------------------------------------------
/test/formatting/samples/inline-element-break-long/output.html:
--------------------------------------------------------------------------------
1 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi
7 |
8 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi hi
14 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
20 |
21 | looooooooooong looooooooooonglooooooooooonglooooooooooonglooooooooooonglooooooooooonghi hi
27 |
--------------------------------------------------------------------------------
/test/formatting/samples/single-attribute-per-line/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 | Copy
14 |
15 | Copy
17 |
18 | Copy
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 | Foo
32 |
33 |
34 |
35 | hi
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: pull_request
4 |
5 | jobs:
6 | test:
7 | name: Test
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - name: Checkout code
12 | uses: actions/checkout@v3
13 | - name: Setup Node
14 | uses: actions/setup-node@v3
15 | with:
16 | cache: npm
17 | - name: Install dependencies
18 | run: npm ci
19 | - name: Run tests
20 | run: npm test
21 |
22 | lint:
23 | name: Lint
24 | runs-on: ubuntu-latest
25 |
26 | steps:
27 | - name: Checkout code
28 | uses: actions/checkout@v3
29 | - name: Setup Node
30 | uses: actions/setup-node@v3
31 | with:
32 | cache: npm
33 | - name: Install dependencies
34 | run: npm ci
35 | - name: Type check
36 | run: npm run check
37 | - name: Lint
38 | run: npm run lint
39 |
--------------------------------------------------------------------------------
/test/printer/samples/single-attribute-per-line-bracket-no-new-line.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
14 |
15 |
21 | Copy
22 |
23 |
24 | Copy
25 |
26 | Copy
29 |
30 |
35 |
36 |
37 |
40 |
41 |
44 |
45 |
46 |
47 |
50 | Foo
51 |
52 |
53 | hi
56 |
57 |
60 |
--------------------------------------------------------------------------------
/test/formatting/samples/long-attribute-value/input.html:
--------------------------------------------------------------------------------
1 | ''}
6 | on:breaks={() => { const a = ''; a.toLowerCase(); }}
7 | in:fits={{ store: passwordStore, clean: [ensureString] }}
8 | in:breaks={{ store: passwordStore, clean: [ensureString], validate: [minLength(6), maxLength(25)] }}
9 | out:fits={{ store: passwordStore, clean: [ensureString] }}
10 | out:breaks={{ store: passwordStore, clean: [ensureString], validate: [minLength(6), maxLength(25)] }}
11 | transition:fits={{ store: passwordStore, clean: [ensureString] }}
12 | transition:breaks={{ store: passwordStore, clean: [ensureString], validate: [minLength(6), maxLength(25)] }}
13 | animate:fits={{ store: passwordStore, clean: [ensureString] }}
14 | animate:breaks={{ store: passwordStore, clean: [ensureString], validate: [minLength(6), maxLength(25)] }}
15 | class:fits={'short check that fits in one line' ? true : false}
16 | class:breaks={'some really long condition check happening here' ? true : false}
17 | />
18 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 [Contributors](https://github.com/sveltejs/prettier-plugin-svelte/graphs/contributors)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/test/printer/samples/single-attribute-per-line.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
16 |
17 |
24 | Copy
25 |
26 |
27 | Copy
28 |
29 | Copy
33 |
34 |
40 |
41 |
45 |
46 |
50 |
51 |
52 |
53 |
57 | Foo
58 |
59 |
60 | hi
64 |
65 |
69 |
--------------------------------------------------------------------------------
/test/formatting/samples/single-attribute-per-line/output.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
16 |
17 |
24 | Copy
25 |
26 |
27 | Copy
28 |
29 | Copy
33 |
34 |
40 |
41 |
45 |
46 |
50 |
51 |
52 |
53 |
57 | Foo
58 |
59 |
60 |
64 | hi
65 |
66 |
67 |
71 |
--------------------------------------------------------------------------------
/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Config } from 'prettier';
2 |
3 | export interface PluginConfig {
4 | svelteSortOrder?: SortOrder;
5 | svelteBracketNewLine?: boolean;
6 | svelteAllowShorthand?: boolean;
7 | svelteIndentScriptAndStyle?: boolean;
8 | }
9 |
10 | export type PrettierConfig = PluginConfig & Config;
11 |
12 | type SortOrder =
13 | | 'options-scripts-markup-styles'
14 | | 'options-scripts-styles-markup'
15 | | 'options-markup-styles-scripts'
16 | | 'options-markup-scripts-styles'
17 | | 'options-styles-markup-scripts'
18 | | 'options-styles-scripts-markup'
19 | | 'scripts-options-markup-styles'
20 | | 'scripts-options-styles-markup'
21 | | 'markup-options-styles-scripts'
22 | | 'markup-options-scripts-styles'
23 | | 'styles-options-markup-scripts'
24 | | 'styles-options-scripts-markup'
25 | | 'scripts-markup-options-styles'
26 | | 'scripts-styles-options-markup'
27 | | 'markup-styles-options-scripts'
28 | | 'markup-scripts-options-styles'
29 | | 'styles-markup-options-scripts'
30 | | 'styles-scripts-options-markup'
31 | | 'scripts-markup-styles-options'
32 | | 'scripts-styles-markup-options'
33 | | 'markup-styles-scripts-options'
34 | | 'markup-scripts-styles-options'
35 | | 'styles-markup-scripts-options'
36 | | 'styles-scripts-markup-options'
37 | | 'none';
38 |
--------------------------------------------------------------------------------
/src/lib/elements.ts:
--------------------------------------------------------------------------------
1 | export type TagName = keyof HTMLElementTagNameMap | 'svg';
2 |
3 | // @see http://xahlee.info/js/html5_non-closing_tag.html
4 | export const selfClosingTags = [
5 | 'area',
6 | 'base',
7 | 'br',
8 | 'col',
9 | 'embed',
10 | 'hr',
11 | 'img',
12 | 'input',
13 | 'link',
14 | 'meta',
15 | 'param',
16 | 'source',
17 | 'track',
18 | 'wbr',
19 | ];
20 |
21 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements
22 | export const blockElements: TagName[] = [
23 | 'address',
24 | 'article',
25 | 'aside',
26 | 'blockquote',
27 | 'details',
28 | 'dialog',
29 | 'dd',
30 | 'div',
31 | 'dl',
32 | 'dt',
33 | 'fieldset',
34 | 'figcaption',
35 | 'figure',
36 | 'footer',
37 | 'form',
38 | 'h1',
39 | 'h2',
40 | 'h3',
41 | 'h4',
42 | 'h5',
43 | 'h6',
44 | 'header',
45 | 'hgroup',
46 | 'hr',
47 | 'li',
48 | 'main',
49 | 'nav',
50 | 'ol',
51 | 'p',
52 | 'pre',
53 | 'section',
54 | 'table',
55 | 'ul',
56 | ];
57 |
58 | /**
59 | * HTML attributes that we may safely reformat (trim whitespace, add or remove newlines)
60 | */
61 | export const formattableAttributes: string[] = [
62 | // None at the moment
63 | // Prettier HTML does not format attributes at all
64 | // and to be consistent we leave this array empty for now
65 | ];
66 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import alias from '@rollup/plugin-alias';
2 | import resolve from '@rollup/plugin-node-resolve';
3 | import commonjs from '@rollup/plugin-commonjs';
4 | import typescript from 'rollup-plugin-typescript';
5 |
6 | export default [
7 | // CommonJS build
8 | {
9 | input: 'src/index.ts',
10 | plugins: [resolve(), commonjs(), typescript()],
11 | external: ['prettier', 'svelte/compiler'],
12 | output: {
13 | file: 'plugin.js',
14 | format: 'cjs',
15 | sourcemap: true,
16 | },
17 | },
18 | // Browser build
19 | // Supported use case: importing the plugin from a bundler like Vite or Webpack
20 | // Semi-supported use case: importing the plugin directly in the browser through using import maps.
21 | // (semi-supported because it requires a svelte/compiler.cjs import map and the .cjs ending has the wrong mime type on CDNs)
22 | {
23 | input: 'src/index.ts',
24 | plugins: [
25 | alias({
26 | entries: [{ find: 'prettier', replacement: 'prettier/standalone' }],
27 | }),
28 | resolve(),
29 | commonjs(),
30 | typescript(),
31 | ],
32 | external: ['prettier/standalone', 'prettier/plugins/babel', 'svelte/compiler'],
33 | output: {
34 | file: 'browser.js',
35 | format: 'esm',
36 | },
37 | },
38 | ];
39 |
--------------------------------------------------------------------------------
/test/formatting/samples/long-attribute-value/output.html:
--------------------------------------------------------------------------------
1 | ""}
10 | on:breaks={() => {
11 | const a = "";
12 | a.toLowerCase();
13 | }}
14 | in:fits={{ store: passwordStore, clean: [ensureString] }}
15 | in:breaks={{
16 | store: passwordStore,
17 | clean: [ensureString],
18 | validate: [minLength(6), maxLength(25)],
19 | }}
20 | out:fits={{ store: passwordStore, clean: [ensureString] }}
21 | out:breaks={{
22 | store: passwordStore,
23 | clean: [ensureString],
24 | validate: [minLength(6), maxLength(25)],
25 | }}
26 | transition:fits={{ store: passwordStore, clean: [ensureString] }}
27 | transition:breaks={{
28 | store: passwordStore,
29 | clean: [ensureString],
30 | validate: [minLength(6), maxLength(25)],
31 | }}
32 | animate:fits={{ store: passwordStore, clean: [ensureString] }}
33 | animate:breaks={{
34 | store: passwordStore,
35 | clean: [ensureString],
36 | validate: [minLength(6), maxLength(25)],
37 | }}
38 | class:fits={"short check that fits in one line" ? true : false}
39 | class:breaks={"some really long condition check happening here"
40 | ? true
41 | : false}
42 | />
43 |
--------------------------------------------------------------------------------
/src/lib/extractAttributes.ts:
--------------------------------------------------------------------------------
1 | import { AttributeNode, TextNode } from '../print/nodes';
2 |
3 | const extractAttributesRegex =
4 | /<[a-z]+((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>/im;
5 | const attributeRegex = /([^\s=]+)(?:=(?:(?:("|')([\s\S]*?)\2)|(?:([^>\s]+?)(?:\s|>|$))))?/gim;
6 |
7 | export function extractAttributes(html: string): AttributeNode[] {
8 | const [, attributesString] = html.match(extractAttributesRegex)!;
9 |
10 | const attrs: AttributeNode[] = [];
11 |
12 | let match: RegExpMatchArray | null;
13 | while ((match = attributeRegex.exec(attributesString))) {
14 | const [all, name, quotes, valueQuoted, valueUnquoted] = match;
15 | const value = valueQuoted || valueUnquoted;
16 | const attrStart = match.index!;
17 |
18 | let valueNode: AttributeNode['value'];
19 | if (!value) {
20 | valueNode = true;
21 | } else {
22 | let valueStart = attrStart + name.length;
23 | if (quotes) {
24 | valueStart += 2;
25 | }
26 |
27 | valueNode = [
28 | {
29 | type: 'Text',
30 | data: value,
31 | start: valueStart,
32 | end: valueStart + value.length,
33 | } as TextNode,
34 | ];
35 | }
36 |
37 | attrs.push({
38 | type: 'Attribute',
39 | name,
40 | value: valueNode,
41 | start: attrStart,
42 | end: attrStart + all.length,
43 | });
44 | }
45 |
46 | return attrs;
47 | }
48 |
--------------------------------------------------------------------------------
/test/printer/index.ts:
--------------------------------------------------------------------------------
1 | import test from 'ava';
2 | import { readdirSync, readFileSync, existsSync } from 'fs';
3 | import { format } from 'prettier';
4 | import { VERSION } from 'svelte/compiler';
5 | import * as SveltePlugin from '../../src';
6 |
7 | let files = readdirSync('test/printer/samples').filter(
8 | (name) => name.endsWith('.html') || name.endsWith('.md'),
9 | );
10 | const formattingDirsHaveOnly = readdirSync('test/formatting/samples').some((d) =>
11 | d.endsWith('.only'),
12 | );
13 | const endsWithOnly = (f: string): boolean => f.endsWith('.only.html') || f.endsWith('.only.md');
14 | const hasOnly = formattingDirsHaveOnly || files.some(endsWithOnly);
15 | files = !hasOnly ? files : files.filter(endsWithOnly);
16 |
17 | if (process.env.CI && hasOnly) {
18 | throw new Error('.only tests present');
19 | }
20 |
21 | for (const file of files) {
22 | const ending = file.split('.').pop();
23 | const input = readFileSync(`test/printer/samples/${file}`, 'utf-8').replace(/\r?\n/g, '\n');
24 | const options = readOptions(
25 | `test/printer/samples/${file.replace('.only', '').replace(`.${ending}`, '.options.json')}`,
26 | );
27 |
28 | test(`printer: ${file.slice(0, file.length - `.${ending}`.length)}`, async (t) => {
29 | const actualOutput = await format(input, {
30 | parser: ending === 'html' ? 'svelte' : 'markdown',
31 | plugins: [SveltePlugin],
32 | tabWidth: 4,
33 | ...options,
34 | });
35 |
36 | t.is(input, actualOutput, `Expected:\n${input}\n\nActual:\n${actualOutput}`);
37 | });
38 | }
39 |
40 | function readOptions(fileName: string) {
41 | if (!existsSync(fileName)) {
42 | return {};
43 | }
44 |
45 | const fileContents = readFileSync(fileName, 'utf-8');
46 | return JSON.parse(fileContents);
47 | }
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "prettier-plugin-svelte",
3 | "version": "3.2.6",
4 | "description": "Svelte plugin for prettier",
5 | "main": "plugin.js",
6 | "files": [
7 | "plugin.js",
8 | "plugin.js.map",
9 | "browser.js",
10 | "index.d.ts"
11 | ],
12 | "types": "./index.d.ts",
13 | "exports": {
14 | ".": {
15 | "types": "./index.d.ts",
16 | "default": "./plugin.js"
17 | },
18 | "./browser": "./browser.js",
19 | "./package.json": "./package.json"
20 | },
21 | "scripts": {
22 | "build": "rollup -c",
23 | "check": "tsc --noEmit",
24 | "check:watch": "tsc --noEmit --watch",
25 | "lint": "prettier --check .",
26 | "format": "prettier --write .",
27 | "test": "ava",
28 | "prepare": "npm run build",
29 | "prepublishOnly": "npm test"
30 | },
31 | "repository": {
32 | "type": "git",
33 | "url": "git+https://github.com/sveltejs/prettier-plugin-svelte.git"
34 | },
35 | "keywords": [
36 | "prettier",
37 | "svelte"
38 | ],
39 | "author": "James Birtles ",
40 | "license": "MIT",
41 | "bugs": {
42 | "url": "https://github.com/sveltejs/prettier-plugin-svelte/issues"
43 | },
44 | "homepage": "https://github.com/sveltejs/prettier-plugin-svelte#readme",
45 | "devDependencies": {
46 | "@rollup/plugin-alias": "^5.1.0",
47 | "@rollup/plugin-commonjs": "14.0.0",
48 | "@rollup/plugin-node-resolve": "11.0.1",
49 | "@types/node": "^14.0.0",
50 | "ava": "3.15.0",
51 | "prettier": "^3.0.0",
52 | "rollup": "2.36.0",
53 | "rollup-plugin-typescript": "1.0.1",
54 | "svelte": "^5.0.0-next.243",
55 | "ts-node": "^10.1.1",
56 | "tslib": "^2.6.0",
57 | "typescript": "5.1.3"
58 | },
59 | "peerDependencies": {
60 | "prettier": "^3.0.0",
61 | "svelte": "^5.0.0-next.243"
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/test/formatting/index.ts:
--------------------------------------------------------------------------------
1 | import test from 'ava';
2 | import { readdirSync, readFileSync, existsSync } from 'fs';
3 | import { format } from 'prettier';
4 | import { VERSION } from 'svelte/compiler';
5 | import * as SveltePlugin from '../../src';
6 |
7 | let dirs = readdirSync('test/formatting/samples');
8 | const printerFilesHaveOnly = readdirSync('test/printer/samples').some(
9 | (f) => f.endsWith('.only.html') || f.endsWith('.only.md'),
10 | );
11 | const endsWithOnly = (f: string): boolean => f.endsWith('.only');
12 | const hasOnly = printerFilesHaveOnly || dirs.some(endsWithOnly);
13 | dirs = !hasOnly ? dirs : dirs.filter(endsWithOnly);
14 |
15 | if (process.env.CI && hasOnly) {
16 | throw new Error('.only tests present');
17 | }
18 |
19 | for (const dir of dirs) {
20 | const input = readFileSync(`test/formatting/samples/${dir}/input.html`, 'utf-8').replace(
21 | /\r?\n/g,
22 | '\n',
23 | );
24 | const expectedOutput = readFileSync(
25 | `test/formatting/samples/${dir}/output.html`,
26 | 'utf-8',
27 | ).replace(/\r?\n/g, '\n');
28 | const options = readOptions(`test/formatting/samples/${dir}/options.json`);
29 |
30 | test(`formatting: ${dir}`, async (t) => {
31 | let onTestCompleted;
32 |
33 | if (options.expectSyntaxErrors) {
34 | onTestCompleted = doNotLogSyntaxErrors();
35 | }
36 |
37 | try {
38 | const actualOutput = await format(input, {
39 | parser: 'svelte',
40 | plugins: [SveltePlugin],
41 | tabWidth: 4,
42 | ...options,
43 | });
44 |
45 | t.is(
46 | expectedOutput,
47 | actualOutput,
48 | `Expected:\n${expectedOutput}\n\nActual:\n${actualOutput}`,
49 | );
50 |
51 | // Reprint to check that another format outputs the same code
52 | const actualOutput2 = await format(actualOutput, {
53 | parser: 'svelte',
54 | plugins: [SveltePlugin],
55 | tabWidth: 4,
56 | ...options,
57 | });
58 |
59 | t.is(
60 | expectedOutput,
61 | actualOutput2,
62 | `Reprint failed. Expected:\n${expectedOutput}\n\nActual:\n${actualOutput2}`,
63 | );
64 | } finally {
65 | if (onTestCompleted) {
66 | onTestCompleted();
67 | }
68 | }
69 | });
70 | }
71 |
72 | /**
73 | * Overwrite `console.error` so as to not report any syntax errors
74 | * (there are tests that intentionally produce them).
75 | * Returns a function that restores the original `console.error`.
76 | */
77 | function doNotLogSyntaxErrors(): () => {} {
78 | const delegate = console.error;
79 |
80 | console.error = (...args: any[]) => {
81 | const e = args[0];
82 |
83 | if (e instanceof SyntaxError) {
84 | // swallow
85 | } else {
86 | delegate(...args);
87 | }
88 | };
89 |
90 | return () => (console.error = delegate);
91 | }
92 |
93 | function readOptions(fileName: string) {
94 | if (!existsSync(fileName)) {
95 | return {};
96 | }
97 |
98 | const fileContents = readFileSync(fileName, 'utf-8');
99 | return JSON.parse(fileContents);
100 | }
101 |
--------------------------------------------------------------------------------
/src/print/helpers.ts:
--------------------------------------------------------------------------------
1 | import { Doc, doc, AstPath } from 'prettier';
2 | import { PrintFn } from '.';
3 | import { formattableAttributes } from '../lib/elements';
4 | import { snippedTagContentAttribute } from '../lib/snipTagContent';
5 | import {
6 | ASTNode,
7 | AttributeNode,
8 | BodyNode,
9 | DocumentNode,
10 | ElementNode,
11 | HeadNode,
12 | InlineComponentNode,
13 | Node,
14 | OptionsNode,
15 | ScriptNode,
16 | SlotNode,
17 | SlotTemplateNode,
18 | StyleNode,
19 | TitleNode,
20 | WindowNode,
21 | } from './nodes';
22 | import { ParserOptions } from '../options';
23 |
24 | /**
25 | * Determines whether or not given node
26 | * is the root of the Svelte AST.
27 | */
28 | export function isASTNode(n: any): n is ASTNode {
29 | return n && n.__isRoot;
30 | }
31 |
32 | export function isPreTagContent(path: AstPath): boolean {
33 | const stack = path.stack as Node[];
34 |
35 | return stack.some(
36 | (node) =>
37 | (node.type === 'Element' && node.name.toLowerCase() === 'pre') ||
38 | (node.type === 'Attribute' && !formattableAttributes.includes(node.name)),
39 | );
40 | }
41 |
42 | export function flatten(arrays: T[][]): T[] {
43 | return ([] as T[]).concat.apply([], arrays);
44 | }
45 |
46 | export function findLastIndex(isMatch: (item: T, idx: number) => boolean, items: T[]) {
47 | for (let i = items.length - 1; i >= 0; i--) {
48 | if (isMatch(items[i], i)) {
49 | return i;
50 | }
51 | }
52 |
53 | return -1;
54 | }
55 |
56 | export function replaceEndOfLineWith(text: string, replacement: Doc) {
57 | const parts: Doc[] = [];
58 | for (const part of text.split('\n')) {
59 | if (parts.length > 0) {
60 | parts.push(replacement);
61 | }
62 | if (part.endsWith('\r')) {
63 | parts.push(part.slice(0, -1));
64 | } else {
65 | parts.push(part);
66 | }
67 | }
68 | return parts;
69 | }
70 |
71 | export function getAttributeLine(
72 | node:
73 | | ElementNode
74 | | InlineComponentNode
75 | | SlotNode
76 | | WindowNode
77 | | HeadNode
78 | | TitleNode
79 | | StyleNode
80 | | ScriptNode
81 | | BodyNode
82 | | DocumentNode
83 | | OptionsNode
84 | | SlotTemplateNode,
85 | options: ParserOptions,
86 | ) {
87 | const { hardline, line } = doc.builders;
88 | const hasThisBinding =
89 | (node.type === 'InlineComponent' && !!node.expression) ||
90 | (node.type === 'Element' && !!node.tag);
91 |
92 | const attributes = (node.attributes as Array).filter(
93 | (attribute) => attribute.name !== snippedTagContentAttribute,
94 | );
95 | return options.singleAttributePerLine &&
96 | (attributes.length > 1 || (attributes.length && hasThisBinding))
97 | ? hardline
98 | : line;
99 | }
100 |
101 | export function printWithPrependedAttributeLine(
102 | node:
103 | | ElementNode
104 | | InlineComponentNode
105 | | SlotNode
106 | | WindowNode
107 | | HeadNode
108 | | TitleNode
109 | | StyleNode
110 | | ScriptNode
111 | | BodyNode
112 | | DocumentNode
113 | | OptionsNode
114 | | SlotTemplateNode,
115 | options: ParserOptions,
116 | print: PrintFn,
117 | ): PrintFn {
118 | return (path) =>
119 | path.getNode().name !== snippedTagContentAttribute
120 | ? [getAttributeLine(node, options), path.call(print)]
121 | : '';
122 | }
123 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import { SupportLanguage, Parser, Printer } from 'prettier';
2 | import * as prettierPluginBabel from 'prettier/plugins/babel';
3 | import { hasPragma, print } from './print';
4 | import { ASTNode } from './print/nodes';
5 | import { embed, getVisitorKeys } from './embed';
6 | import { snipScriptAndStyleTagContent } from './lib/snipTagContent';
7 | import { parse, VERSION } from 'svelte/compiler';
8 | import { ParserOptions } from './options';
9 |
10 | const babelParser = prettierPluginBabel.parsers.babel;
11 | const typescriptParser = prettierPluginBabel.parsers['babel-ts']; // TODO use TypeScript parser in next major?
12 |
13 | function locStart(node: any) {
14 | return node.start;
15 | }
16 |
17 | function locEnd(node: any) {
18 | return node.end;
19 | }
20 |
21 | export const languages: Partial[] = [
22 | {
23 | name: 'svelte',
24 | parsers: ['svelte'],
25 | extensions: ['.svelte'],
26 | vscodeLanguageIds: ['svelte'],
27 | },
28 | ];
29 |
30 | export const parsers: Record = {
31 | svelte: {
32 | hasPragma,
33 | parse: (text) => {
34 | try {
35 | return { ...parse(text), __isRoot: true };
36 | } catch (err: any) {
37 | if (err.start != null && err.end != null) {
38 | // Prettier expects error objects to have loc.start and loc.end fields.
39 | // Svelte uses start and end directly on the error.
40 | err.loc = {
41 | start: err.start,
42 | end: err.end,
43 | };
44 | }
45 |
46 | throw err;
47 | }
48 | },
49 | preprocess: (text, options: ParserOptions) => {
50 | const result = snipScriptAndStyleTagContent(text);
51 | text = result.text.trim();
52 | // Prettier sets the preprocessed text as the originalText in case
53 | // the Svelte formatter is called directly. In case it's called
54 | // as an embedded parser (for example when there's a Svelte code block
55 | // inside markdown), the originalText is not updated after preprocessing.
56 | // Therefore we do it ourselves here.
57 | options.originalText = text;
58 | options._svelte_ts = result.isTypescript;
59 | return text;
60 | },
61 | locStart,
62 | locEnd,
63 | astFormat: 'svelte-ast',
64 | },
65 | svelteExpressionParser: {
66 | ...babelParser,
67 | parse: (text: string, options: any) => {
68 | const ast = babelParser.parse(text, options);
69 |
70 | let program = ast.program.body[0];
71 | if (!options._svelte_asFunction) {
72 | program = program.expression;
73 | }
74 |
75 | return { ...ast, program };
76 | },
77 | },
78 | svelteTSExpressionParser: {
79 | ...typescriptParser,
80 | parse: (text: string, options: any) => {
81 | const ast = typescriptParser.parse(text, options);
82 |
83 | let program = ast.program.body[0];
84 | if (!options._svelte_asFunction) {
85 | program = program.expression;
86 | }
87 |
88 | return { ...ast, program };
89 | },
90 | },
91 | };
92 |
93 | export const printers: Record = {
94 | 'svelte-ast': {
95 | print,
96 | embed,
97 | // @ts-expect-error Prettier's type definitions are wrong
98 | getVisitorKeys,
99 | },
100 | };
101 |
102 | export { options } from './options';
103 |
--------------------------------------------------------------------------------
/src/options.ts:
--------------------------------------------------------------------------------
1 | import { ParserOptions as PrettierParserOptions, SupportOption } from 'prettier';
2 | import { SortOrder, PluginConfig } from '..';
3 |
4 | export interface ParserOptions extends PrettierParserOptions, Partial {
5 | _svelte_ts?: boolean;
6 | _svelte_asFunction?: boolean;
7 | }
8 |
9 | function makeChoice(choice: string) {
10 | return { value: choice, description: choice };
11 | }
12 |
13 | export const options: Record = {
14 | svelteSortOrder: {
15 | category: 'Svelte',
16 | type: 'choice',
17 | default: 'options-scripts-markup-styles',
18 | description: 'Sort order for scripts, markup, and styles',
19 | choices: [
20 | makeChoice('options-scripts-markup-styles'),
21 | makeChoice('options-scripts-styles-markup'),
22 | makeChoice('options-markup-styles-scripts'),
23 | makeChoice('options-markup-scripts-styles'),
24 | makeChoice('options-styles-markup-scripts'),
25 | makeChoice('options-styles-scripts-markup'),
26 | makeChoice('scripts-options-markup-styles'),
27 | makeChoice('scripts-options-styles-markup'),
28 | makeChoice('markup-options-styles-scripts'),
29 | makeChoice('markup-options-scripts-styles'),
30 | makeChoice('styles-options-markup-scripts'),
31 | makeChoice('styles-options-scripts-markup'),
32 | makeChoice('scripts-markup-options-styles'),
33 | makeChoice('scripts-styles-options-markup'),
34 | makeChoice('markup-styles-options-scripts'),
35 | makeChoice('markup-scripts-options-styles'),
36 | makeChoice('styles-markup-options-scripts'),
37 | makeChoice('styles-scripts-options-markup'),
38 | makeChoice('scripts-markup-styles-options'),
39 | makeChoice('scripts-styles-markup-options'),
40 | makeChoice('markup-styles-scripts-options'),
41 | makeChoice('markup-scripts-styles-options'),
42 | makeChoice('styles-markup-scripts-options'),
43 | makeChoice('styles-scripts-markup-options'),
44 | makeChoice('none'),
45 | ],
46 | },
47 | // todo: remove in v4
48 | svelteBracketNewLine: {
49 | category: 'Svelte',
50 | type: 'boolean',
51 | description: 'Put the `>` of a multiline element on a new line',
52 | deprecated: '2.5.0',
53 | },
54 | svelteAllowShorthand: {
55 | category: 'Svelte',
56 | type: 'boolean',
57 | default: true,
58 | description:
59 | 'Option to enable/disable component attribute shorthand if attribute name and expressions are same',
60 | },
61 | svelteIndentScriptAndStyle: {
62 | category: 'Svelte',
63 | type: 'boolean',
64 | default: true,
65 | description:
66 | 'Whether or not to indent the code inside