{"version":3,"file":"plugin.js","sources":["src/lib/elements.ts","src/lib/extractAttributes.ts","src/lib/getText.ts","src/lib/snipTagContent.ts","src/options.ts","src/print/helpers.ts","src/print/doc-helpers.ts","src/print/node-helpers.ts","src/print/index.ts","src/embed.ts","src/index.ts"],"sourcesContent":["export type TagName = keyof HTMLElementTagNameMap | 'svg';\n\n// @see http://xahlee.info/js/html5_non-closing_tag.html\nexport const selfClosingTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n];\n\n// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements\nexport const blockElements: TagName[] = [\n 'address',\n 'article',\n 'aside',\n 'blockquote',\n 'details',\n 'dialog',\n 'dd',\n 'div',\n 'dl',\n 'dt',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hgroup',\n 'hr',\n 'li',\n 'main',\n 'nav',\n 'ol',\n 'p',\n 'pre',\n 'section',\n 'table',\n 'ul',\n];\n\n/**\n * HTML attributes that we may safely reformat (trim whitespace, add or remove newlines)\n */\nexport const formattableAttributes: string[] = [\n // None at the moment\n // Prettier HTML does not format attributes at all\n // and to be consistent we leave this array empty for now\n];\n","import { AttributeNode, TextNode } from '../print/nodes';\n\nexport function extractAttributes(html: string): AttributeNode[] {\n const extractAttributesRegex = /<[a-z]+\\s*(.*?)>/i;\n const attributeRegex = /([^\\s=]+)(?:=(\"|')(.*?)\\2)?/gi;\n\n const [, attributesString] = html.match(extractAttributesRegex)!;\n\n const attrs: AttributeNode[] = [];\n\n let match: RegExpMatchArray | null;\n while ((match = attributeRegex.exec(attributesString))) {\n const [all, name, quotes, value] = match;\n const attrStart = match.index!;\n\n let valueNode: AttributeNode['value'];\n if (!value) {\n valueNode = true;\n } else {\n let valueStart = attrStart + name.length;\n if (quotes) {\n valueStart += 2;\n }\n\n valueNode = [\n {\n type: 'Text',\n data: value,\n start: valueStart,\n end: valueStart + value.length,\n } as TextNode,\n ];\n }\n\n attrs.push({\n type: 'Attribute',\n name,\n value: valueNode,\n start: attrStart,\n end: attrStart + all.length,\n });\n }\n\n return attrs;\n}\n","import { ParserOptions } from 'prettier';\nimport { Node } from '../print/nodes';\n\nexport function getText(node: Node, options: ParserOptions) {\n const leadingComments: Node[] = (node as any).leadingComments\n\n return options.originalText.slice(\n options.locStart(\n // if there are comments before the node they are not included \n // in the `start` of the node itself\n leadingComments && leadingComments[0] || node,\n ),\n options.locEnd(node),\n );\n}\n","export const snippedTagContentAttribute = '✂prettier:content✂';\n\nexport function snipScriptAndStyleTagContent(source: string): string {\n let scriptMatchSpans = getMatchIndexes('script');\n let styleMatchSpans = getMatchIndexes('style');\n\n return snipTagContent(\n snipTagContent(source, 'script', '{}', styleMatchSpans),\n 'style',\n '',\n scriptMatchSpans,\n );\n\n function getMatchIndexes(tagName: string) {\n const regex = getRegexp(tagName);\n const indexes: [number, number][] = [];\n let match = null;\n while ((match = regex.exec(source)) != null) {\n if (source.slice(match.index, match.index + 4) !== '|<${tagName}([^]*?)>([^]*?)<\\/${tagName}>`, 'g');\n }\n}\n\nexport function hasSnippedContent(text: string) {\n return text.includes(snippedTagContentAttribute);\n}\n\nexport function unsnipContent(text: string): string {\n const regex = /(<\\w+.*?)\\s*✂prettier:content✂=\"(.*?)\">.*?(?=<\\/)/gi;\n\n return text.replace(regex, (_, start, encodedContent) => {\n const content = Buffer.from(encodedContent, 'base64').toString('utf8');\n return `${start}>${content}`;\n });\n}\n","import { ParserOptions, SupportOption } from 'prettier';\n\ndeclare module 'prettier' {\n interface RequiredOptions extends PluginOptions {}\n}\n\nexport interface PluginOptions {\n svelteSortOrder: SortOrder;\n svelteStrictMode: boolean;\n svelteBracketNewLine: boolean;\n svelteAllowShorthand: boolean;\n svelteIndentScriptAndStyle: boolean;\n}\n\nfunction makeChoice(choice: string) {\n return { value: choice, description: choice };\n}\n\nexport const options: Record = {\n svelteSortOrder: {\n since: '0.6.0',\n category: 'Svelte',\n type: 'choice',\n default: 'options-scripts-markup-styles',\n description: 'Sort order for scripts, markup, and styles',\n choices: [\n makeChoice('options-scripts-markup-styles'),\n makeChoice('options-scripts-styles-markup'),\n makeChoice('options-markup-styles-scripts'),\n makeChoice('options-markup-scripts-styles'),\n makeChoice('options-styles-markup-scripts'),\n makeChoice('options-styles-scripts-markup'),\n makeChoice('scripts-options-markup-styles'),\n makeChoice('scripts-options-styles-markup'),\n makeChoice('markup-options-styles-scripts'),\n makeChoice('markup-options-scripts-styles'),\n makeChoice('styles-options-markup-scripts'),\n makeChoice('styles-options-scripts-markup'),\n makeChoice('scripts-markup-options-styles'),\n makeChoice('scripts-styles-options-markup'),\n makeChoice('markup-styles-options-scripts'),\n makeChoice('markup-scripts-options-styles'),\n makeChoice('styles-markup-options-scripts'),\n makeChoice('styles-scripts-options-markup'),\n makeChoice('scripts-markup-styles-options'),\n makeChoice('scripts-styles-markup-options'),\n makeChoice('markup-styles-scripts-options'),\n makeChoice('markup-scripts-styles-options'),\n makeChoice('styles-markup-scripts-options'),\n makeChoice('styles-scripts-markup-options'),\n // Deprecated, keep in 2.x for backwards-compatibility. svelte:options will be moved to the top\n makeChoice('scripts-markup-styles'),\n makeChoice('scripts-styles-markup'),\n makeChoice('markup-styles-scripts'),\n makeChoice('markup-scripts-styles'),\n makeChoice('styles-markup-scripts'),\n makeChoice('styles-scripts-markup'),\n ],\n },\n svelteStrictMode: {\n since: '0.7.0',\n category: 'Svelte',\n type: 'boolean',\n default: false,\n description: 'More strict HTML syntax: self-closed tags, quotes in attributes',\n },\n svelteBracketNewLine: {\n since: '0.6.0',\n category: 'Svelte',\n type: 'boolean',\n description: 'Put the `>` of a multiline element on a new line',\n deprecated: '2.5.0',\n },\n svelteAllowShorthand: {\n since: '1.0.0',\n category: 'Svelte',\n type: 'boolean',\n default: true,\n description:\n 'Option to enable/disable component attribute shorthand if attribute name and expressions are same',\n },\n svelteIndentScriptAndStyle: {\n since: '1.2.0',\n category: 'Svelte',\n type: 'boolean',\n default: true,\n description:\n 'Whether or not to indent the code inside