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