astro-ghostcms/.pnpm-store/v3/files/8f/bec64e413ef7092a8f0f2501f93...

1 line
66 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
{"version":3,"file":"index.js","sources":["../src/options.ts","../src/printer/elements.ts","../src/printer/utils.ts","../src/printer/index.ts","../src/printer/embed.ts","../src/index.ts"],"sourcesContent":["import type { SupportOption } from 'prettier';\n\ninterface PluginOptions {\n\tastroAllowShorthand: boolean;\n}\n\ndeclare module 'prettier' {\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface RequiredOptions extends PluginOptions {}\n}\n\n// https://prettier.io/docs/en/plugins.html#options\nexport const options: Record<keyof PluginOptions, SupportOption> = {\n\tastroAllowShorthand: {\n\t\tcategory: 'Astro',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tdescription: 'Enable/disable attribute shorthand if attribute name and expression are the same',\n\t},\n};\n","export type TagName = keyof HTMLElementTagNameMap | 'svg';\n\n// https://github.com/prettier/prettier/blob/b77d912c0c1a5df85e3e9b5b192fc92523e411ee/vendors/html-void-elements.json\nexport const selfClosingTags = [\n\t'area',\n\t'base',\n\t'basefont',\n\t'bgsound',\n\t'br',\n\t'col',\n\t'command',\n\t'embed',\n\t'frame',\n\t'hr',\n\t'image',\n\t'img',\n\t'input',\n\t'isindex',\n\t'keygen',\n\t'link',\n\t'menuitem',\n\t'meta',\n\t'nextid',\n\t'param',\n\t'slot',\n\t'source',\n\t'track',\n\t'wbr',\n];\n\n// https://web.archive.org/web/20230108213516/https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#elements\nexport const blockElements: TagName[] = [\n\t'address',\n\t'article',\n\t'aside',\n\t'blockquote',\n\t'details',\n\t'dialog',\n\t'dd',\n\t'div',\n\t'dl',\n\t'dt',\n\t'fieldset',\n\t'figcaption',\n\t'figure',\n\t'footer',\n\t'form',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'header',\n\t'hgroup',\n\t'hr',\n\t'li',\n\t'main',\n\t'nav',\n\t'ol',\n\t'p',\n\t'pre',\n\t'section',\n\t'table',\n\t'ul',\n\t// TODO: WIP\n\t'title',\n\t'html',\n];\n\n/**\n * HTML attributes that we may safely reformat (trim whitespace, add or remove newlines)\n */\nexport const formattableAttributes: string[] = [\n\t// None at the moment\n\t// Prettier HTML does not format attributes at all\n\t// and to be consistent we leave this array empty for now\n];\n","import { serialize } from '@astrojs/compiler/utils';\nimport {\n\ttype AstPath as AstP,\n\ttype BuiltInParserName,\n\ttype Doc,\n\ttype ParserOptions as ParserOpts,\n} from 'prettier';\nimport { blockElements, formattableAttributes, type TagName } from './elements';\nimport type {\n\tCommentNode,\n\tExpressionNode,\n\tNode,\n\tParentLikeNode,\n\tTagLikeNode,\n\tTextNode,\n\tanyNode,\n} from './nodes';\n\nexport type printFn = (path: AstPath) => Doc;\nexport type ParserOptions = ParserOpts<anyNode>;\nexport type AstPath = AstP<anyNode>;\n\nexport const openingBracketReplace = '_Pé';\nexport const closingBracketReplace = 'èP_';\nexport const atSignReplace = 'ΩP_';\nexport const dotReplace = 'ωP_';\nexport const interrogationReplace = 'ΔP_';\n\nexport function isInlineElement(path: AstPath, opts: ParserOptions, node: anyNode): boolean {\n\treturn node && isTagLikeNode(node) && !isBlockElement(node, opts) && !isPreTagContent(path);\n}\n\nexport function isBlockElement(node: anyNode, opts: ParserOptions): boolean {\n\treturn (\n\t\tnode &&\n\t\tnode.type === 'element' &&\n\t\topts.htmlWhitespaceSensitivity !== 'strict' &&\n\t\t(opts.htmlWhitespaceSensitivity === 'ignore' || blockElements.includes(node.name as TagName))\n\t);\n}\n\nexport function isIgnoreDirective(node: Node): boolean {\n\treturn node.type === 'comment' && node.value.trim() === 'prettier-ignore';\n}\n\n/**\n * Returns the content of the node\n */\nexport function printRaw(node: anyNode, stripLeadingAndTrailingNewline = false): string {\n\tif (!isNodeWithChildren(node)) {\n\t\treturn '';\n\t}\n\n\tif (node.children.length === 0) {\n\t\treturn '';\n\t}\n\n\tlet raw = node.children.reduce((prev: string, curr: Node) => prev + serialize(curr), '');\n\n\tif (!stripLeadingAndTrailingNewline) {\n\t\treturn raw;\n\t}\n\n\tif (startsWithLinebreak(raw)) {\n\t\traw = raw.substring(raw.indexOf('\\n') + 1);\n