@pairdraw/emit 0.19.1 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ var jsx_exports = /* @__PURE__ */ __exportAll({
14
14
  literal: () => literal,
15
15
  printJSX: () => printJSX,
16
16
  printModule: () => printModule,
17
- spread: () => spread,
17
+ spread: () => spread$1,
18
18
  stringValue: () => stringValue,
19
19
  text: () => text$1,
20
20
  whitespace: () => whitespace
@@ -57,7 +57,7 @@ const whitespace = (value) => ({
57
57
  /** A string attribute value: quoted when JSX keeps it as written, an expression otherwise. */
58
58
  const stringValue = (value) => LITERAL_ATTRIBUTE.test(value) ? literal(value) : container(literal(value));
59
59
  /** `{...expression}`, passing an object's properties on as attributes. */
60
- const spread = (argument) => ({
60
+ const spread$1 = (argument) => ({
61
61
  type: "JSXSpreadAttribute",
62
62
  argument
63
63
  });
@@ -152,6 +152,7 @@ var vue_exports = /* @__PURE__ */ __exportAll({
152
152
  printComponent: () => printComponent,
153
153
  printTemplate: () => printTemplate,
154
154
  renderIf: () => renderIf,
155
+ spread: () => spread,
155
156
  text: () => text
156
157
  });
157
158
  /**
@@ -179,6 +180,10 @@ const renderIf = (expression) => ({
179
180
  type: "if",
180
181
  expression
181
182
  });
183
+ const spread = (expression) => ({
184
+ type: "spread",
185
+ expression
186
+ });
182
187
  const element = (tag, attributes = [], children = []) => ({
183
188
  type: "element",
184
189
  tag,
@@ -198,6 +203,7 @@ function printAttribute(item) {
198
203
  const value = escapeAttribute(printExpression(item.expression));
199
204
  if (item.type === "bound") return `:${item.name}="${value}"`;
200
205
  if (item.type === "if") return `v-if="${value}"`;
206
+ if (item.type === "spread") return `v-bind="${value}"`;
201
207
  return `${item.argument ? `v-model:${item.argument}` : "v-model"}="${value}"`;
202
208
  }
203
209
  /** Markup with nothing added around it, as text content needs. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["attribute","text","element","printModule"],"sources":["../../src/jsx.ts","../../src/vue.ts"],"sourcesContent":["import { print } from 'esrap'\nimport tsx from 'esrap/languages/tsx'\n\nimport { isNode, type SyntaxNode } from './estree'\n\n/**\n * JSX attribute strings end at `\"`, decode `&` entities, and keep backslashes literally,\n * so the printer's escapes for backslashes and line breaks would change the value. JSX\n * text also treats braces and angle brackets as syntax and trims whitespace at line\n * edges. Anything else is written as a string literal, which the printer escapes.\n */\nconst LITERAL_ATTRIBUTE = /^[^\"&\\\\\\r\\n]*$/\nconst LITERAL_TEXT = /^[^{}<>&\\r\\n]*$/\n\nexport const identifier = (name: string): SyntaxNode => ({ type: 'JSXIdentifier', name })\n\n/** A tag name; a dotted one such as `Switch.Root` is a member of a namespace. */\nfunction tagName(tag: string): SyntaxNode {\n const [first = tag, ...rest] = tag.split('.')\n return rest.reduce<SyntaxNode>(\n (object, property) => ({ type: 'JSXMemberExpression', object, property: identifier(property) }),\n identifier(first)\n )\n}\n\nexport const literal = (value: string | number | boolean): SyntaxNode => ({\n type: 'Literal',\n value\n})\n\nexport const container = (expression: SyntaxNode): SyntaxNode => ({\n type: 'JSXExpressionContainer',\n expression\n})\n\n/** Raw JSX text, printed as is. */\nexport const whitespace = (value: string): SyntaxNode => ({ type: 'JSXText', value, raw: value })\n\n/** A string attribute value: quoted when JSX keeps it as written, an expression otherwise. */\nexport const stringValue = (value: string): SyntaxNode =>\n LITERAL_ATTRIBUTE.test(value) ? literal(value) : container(literal(value))\n\n/** `{...expression}`, passing an object's properties on as attributes. */\nexport const spread = (argument: SyntaxNode): SyntaxNode => ({\n type: 'JSXSpreadAttribute',\n argument\n})\n\n/** An attribute; a null value prints the bare name, as for `true`. */\n/** An attribute. A name such as `xlink:href` is namespaced, as JSX parses it. */\nexport function attribute(name: string, value: SyntaxNode | null): SyntaxNode {\n const colon = name.indexOf(':')\n const attributeName =\n colon > 0\n ? {\n type: 'JSXNamespacedName',\n namespace: identifier(name.slice(0, colon)),\n name: identifier(name.slice(colon + 1))\n }\n : identifier(name)\n return { type: 'JSXAttribute', name: attributeName, value }\n}\n\n/** Text content: plain JSX text when it survives as written, a string expression otherwise. */\nexport function text(value: string): SyntaxNode {\n const plain = LITERAL_TEXT.test(value) && value.trim() === value && value.length > 0\n return plain ? whitespace(value) : container(literal(value))\n}\n\n/**\n * Text that shares a line with elements, as beside a span. JSX trims whitespace only at line\n * edges, so text without a line break is kept as written, spaces at its ends included.\n */\nexport function inlineText(value: string): SyntaxNode {\n const plain = LITERAL_TEXT.test(value) && value.length > 0\n return plain ? whitespace(value) : container(literal(value))\n}\n\n/** Children on their own lines; JSX drops whitespace-only lines between elements. */\nfunction indented(children: SyntaxNode[], depth: number): SyntaxNode[] {\n const inner = `\\n${' '.repeat(depth + 1)}`\n return [\n ...children.flatMap((child) => [whitespace(inner), child]),\n whitespace(`\\n${' '.repeat(depth)}`)\n ]\n}\n\n/**\n * An element at nesting `depth`. Children go on their own lines unless `inline`, as for a\n * lone text child; without children the element self-closes.\n */\nexport function element(\n tag: string,\n attributes: SyntaxNode[],\n children: SyntaxNode[],\n depth: number,\n inline = false\n): SyntaxNode {\n const name = tagName(tag)\n const content = inline || children.length === 0 ? children : indented(children, depth)\n return {\n type: 'JSXElement',\n openingElement: {\n type: 'JSXOpeningElement',\n name,\n attributes,\n selfClosing: content.length === 0\n },\n closingElement: content.length > 0 ? { type: 'JSXClosingElement', name } : null,\n children: content\n }\n}\n\n/** `<>…</>`: children without an element around them, laid out as an element's are. */\nexport function fragment(children: SyntaxNode[], depth: number): SyntaxNode {\n return {\n type: 'JSXFragment',\n openingFragment: { type: 'JSXOpeningFragment' },\n closingFragment: { type: 'JSXClosingFragment' },\n children: children.length === 0 ? [] : indented(children, depth)\n }\n}\n\nexport function printJSX(node: SyntaxNode): string {\n return print(node, tsx({ quotes: 'double' }), { indent: ' ' }).code\n}\n\n/** A copy without strings' source spelling, so the printer quotes every string the same way. */\nfunction withoutRawStrings(node: SyntaxNode): SyntaxNode {\n const copy: SyntaxNode = { ...node }\n if (node.type === 'Literal' && typeof node.value === 'string') delete copy.raw\n for (const [key, value] of Object.entries(node)) {\n if (Array.isArray(value))\n copy[key] = value.map((item: unknown) => (isNode(item) ? withoutRawStrings(item) : item))\n else if (isNode(value)) copy[key] = withoutRawStrings(value)\n }\n return copy\n}\n\n/**\n * A TSX module, such as a component built with `es` templates and JSX from this module. Strings\n * parsed from a template and strings built here print with the same double quotes.\n */\nexport function printModule(program: SyntaxNode): string {\n return print(withoutRawStrings(program), tsx({ quotes: 'double' }), { indent: ' ' }).code\n}\n","import { escapeAttribute, escapeText } from 'entities'\n\nimport { printExpression, printModule, type SyntaxNode } from './estree'\n\n/**\n * Text and attribute values are escaped as HTML by `entities`. Vue also reads `{{` as an\n * interpolation before it decodes entities, so text writes `{` as one too and a design's text\n * can never become template syntax.\n */\nconst templateText = (value: string) => escapeText(value).replaceAll('{', '&#123;')\n\nexport type VueAttribute =\n | { type: 'static'; name: string; value: string }\n /** `:name=\"expression\"` */\n | { type: 'bound'; name: string; expression: SyntaxNode }\n /** `v-model=\"expression\"`, or `v-model:argument` */\n | { type: 'model'; argument?: string; expression: SyntaxNode }\n /** `v-if=\"expression\"`: the element renders only while the expression holds. */\n | { type: 'if'; expression: SyntaxNode }\n\nexport interface VueElement {\n type: 'element'\n tag: string\n attributes: VueAttribute[]\n children: VueNode[]\n}\n\nexport interface VueText {\n type: 'text'\n value: string\n}\n\n/** `{{ expression }}`, printed from a syntax tree so it holds only what the tree says. */\nexport interface VueInterpolation {\n type: 'interpolation'\n expression: SyntaxNode\n}\n\nexport type VueNode = VueElement | VueText | VueInterpolation\n\nexport const attribute = (name: string, value: string): VueAttribute => ({\n type: 'static',\n name,\n value\n})\n\nexport const bound = (name: string, expression: SyntaxNode): VueAttribute => ({\n type: 'bound',\n name,\n expression\n})\n\nexport const model = (expression: SyntaxNode, argument?: string): VueAttribute => ({\n type: 'model',\n argument,\n expression\n})\n\nexport const renderIf = (expression: SyntaxNode): VueAttribute => ({ type: 'if', expression })\n\nexport const element = (\n tag: string,\n attributes: VueAttribute[] = [],\n children: VueNode[] = []\n): VueElement => ({ type: 'element', tag, attributes, children })\n\nexport const text = (value: string): VueText => ({ type: 'text', value })\n\nexport const interpolation = (expression: SyntaxNode): VueInterpolation => ({\n type: 'interpolation',\n expression\n})\n\nfunction printAttribute(item: VueAttribute): string {\n if (item.type === 'static') return `${item.name}=\"${escapeAttribute(item.value)}\"`\n const value = escapeAttribute(printExpression(item.expression))\n if (item.type === 'bound') return `:${item.name}=\"${value}\"`\n if (item.type === 'if') return `v-if=\"${value}\"`\n return `${item.argument ? `v-model:${item.argument}` : 'v-model'}=\"${value}\"`\n}\n\n/** Markup with nothing added around it, as text content needs. */\nfunction printInline(node: VueNode): string {\n if (node.type === 'text') return templateText(node.value)\n if (node.type === 'interpolation') {\n const expression = printExpression(node.expression)\n // The template ends an interpolation at the first `}}`, wherever it falls.\n if (expression.includes('}}'))\n throw new Error(`An interpolated expression cannot contain \"}}\": ${expression}`)\n return `{{ ${expression} }}`\n }\n const open = [node.tag, ...node.attributes.map(printAttribute)].join(' ')\n if (node.children.length === 0) return `<${open} />`\n return `<${open}>${node.children.map(printInline).join('')}</${node.tag}>`\n}\n\nfunction printNode(node: VueNode, depth: number): string {\n const indent = ' '.repeat(depth)\n // Vue renders whitespace between text and elements as a space, so an element with text or\n // an interpolation in it keeps its children on its own line, exactly as given.\n if (node.type !== 'element' || node.children.some((child) => child.type !== 'element'))\n return `${indent}${printInline(node)}`\n const open = [node.tag, ...node.attributes.map(printAttribute)].join(' ')\n if (node.children.length === 0) return `${indent}<${open} />`\n const children = node.children.map((child) => printNode(child, depth + 1))\n return [`${indent}<${open}>`, ...children, `${indent}</${node.tag}>`].join('\\n')\n}\n\n/** A template's markup, one element per line. */\nexport function printTemplate(root: VueNode): string {\n return printNode(root, 0)\n}\n\nexport interface VueComponent {\n /** The `<script setup lang=\"ts\">` body, a TypeScript program from `es`. */\n script: SyntaxNode\n template: VueNode\n /** Stylesheet text for a `<style scoped>` block. */\n style?: string\n}\n\n/**\n * A raw block's content, which ends at the first closing tag for its element. Strings in the\n * script and values in the stylesheet can come from an imported design, so a closing tag in\n * them is written `<\\\\/`, which JavaScript strings and CSS both read back as `</`.\n */\nconst rawBlock = (tag: string, content: string) =>\n `<${tag}>\\n${content.trim().replace(/<\\/(?=script|style)/gi, '<\\\\/')}\\n</${tag.split(' ')[0]}>`\n\n/** Whether a component's script has anything to write, so it gets a script block. */\nconst hasScript = (script: SyntaxNode) => printModule(script).trim() !== ''\n\nfunction templateElements(node: VueNode): VueElement[] {\n return node.type === 'element' ? [node, ...node.children.flatMap(templateElements)] : []\n}\n\n/**\n * The elements `printComponent` writes, in the order they open: the template's own, between\n * `null`s for the script, template, and style blocks that hold them.\n */\nexport function componentElements({\n script,\n template,\n style\n}: VueComponent): (VueElement | null)[] {\n return [\n ...(hasScript(script) ? [null] : []),\n null,\n ...templateElements(template),\n ...(style ? [null] : [])\n ]\n}\n\n/** A single-file component: script setup, template, and scoped style. */\nexport function printComponent({ script, template, style }: VueComponent): string {\n const code = printModule(script)\n // A component with nothing to import or declare has no script block.\n const blocks = [\n ...(code.trim() ? [rawBlock('script setup lang=\"ts\"', code)] : []),\n `<template>\\n${printNode(template, 1)}\\n</template>`,\n ...(style ? [rawBlock('style scoped', style)] : [])\n ]\n return `${blocks.join('\\n\\n')}\\n`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AAErB,MAAa,cAAc,UAA8B;CAAE,MAAM;CAAiB;AAAK;;AAGvF,SAAS,QAAQ,KAAyB;CACxC,MAAM,CAAC,QAAQ,KAAK,GAAG,QAAQ,IAAI,MAAM,GAAG;CAC5C,OAAO,KAAK,QACT,QAAQ,cAAc;EAAE,MAAM;EAAuB;EAAQ,UAAU,WAAW,QAAQ;CAAE,IAC7F,WAAW,KAAK,CAClB;AACF;AAEA,MAAa,WAAW,WAAkD;CACxE,MAAM;CACN;AACF;AAEA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AAI,CAAC,IAAI,CAAC;EAChE,eAAe,UAAU,UAAU,CAAC,EAAE;EACtC,GAAI,QAAQ,CAAC,SAAS,gBAAgB,KAAK,CAAC,IAAI,CAAC;CAEpC,CAAC,CAAC,KAAK,MAAM,EAAE;AAChC"}
1
+ {"version":3,"file":"index.js","names":["spread","attribute","text","element","printModule"],"sources":["../../src/jsx.ts","../../src/vue.ts"],"sourcesContent":["import { print } from 'esrap'\nimport tsx from 'esrap/languages/tsx'\n\nimport { isNode, type SyntaxNode } from './estree'\n\n/**\n * JSX attribute strings end at `\"`, decode `&` entities, and keep backslashes literally,\n * so the printer's escapes for backslashes and line breaks would change the value. JSX\n * text also treats braces and angle brackets as syntax and trims whitespace at line\n * edges. Anything else is written as a string literal, which the printer escapes.\n */\nconst LITERAL_ATTRIBUTE = /^[^\"&\\\\\\r\\n]*$/\nconst LITERAL_TEXT = /^[^{}<>&\\r\\n]*$/\n\nexport const identifier = (name: string): SyntaxNode => ({ type: 'JSXIdentifier', name })\n\n/** A tag name; a dotted one such as `Switch.Root` is a member of a namespace. */\nfunction tagName(tag: string): SyntaxNode {\n const [first = tag, ...rest] = tag.split('.')\n return rest.reduce<SyntaxNode>(\n (object, property) => ({ type: 'JSXMemberExpression', object, property: identifier(property) }),\n identifier(first)\n )\n}\n\nexport const literal = (value: string | number | boolean): SyntaxNode => ({\n type: 'Literal',\n value\n})\n\nexport const container = (expression: SyntaxNode): SyntaxNode => ({\n type: 'JSXExpressionContainer',\n expression\n})\n\n/** Raw JSX text, printed as is. */\nexport const whitespace = (value: string): SyntaxNode => ({ type: 'JSXText', value, raw: value })\n\n/** A string attribute value: quoted when JSX keeps it as written, an expression otherwise. */\nexport const stringValue = (value: string): SyntaxNode =>\n LITERAL_ATTRIBUTE.test(value) ? literal(value) : container(literal(value))\n\n/** `{...expression}`, passing an object's properties on as attributes. */\nexport const spread = (argument: SyntaxNode): SyntaxNode => ({\n type: 'JSXSpreadAttribute',\n argument\n})\n\n/** An attribute; a null value prints the bare name, as for `true`. */\n/** An attribute. A name such as `xlink:href` is namespaced, as JSX parses it. */\nexport function attribute(name: string, value: SyntaxNode | null): SyntaxNode {\n const colon = name.indexOf(':')\n const attributeName =\n colon > 0\n ? {\n type: 'JSXNamespacedName',\n namespace: identifier(name.slice(0, colon)),\n name: identifier(name.slice(colon + 1))\n }\n : identifier(name)\n return { type: 'JSXAttribute', name: attributeName, value }\n}\n\n/** Text content: plain JSX text when it survives as written, a string expression otherwise. */\nexport function text(value: string): SyntaxNode {\n const plain = LITERAL_TEXT.test(value) && value.trim() === value && value.length > 0\n return plain ? whitespace(value) : container(literal(value))\n}\n\n/**\n * Text that shares a line with elements, as beside a span. JSX trims whitespace only at line\n * edges, so text without a line break is kept as written, spaces at its ends included.\n */\nexport function inlineText(value: string): SyntaxNode {\n const plain = LITERAL_TEXT.test(value) && value.length > 0\n return plain ? whitespace(value) : container(literal(value))\n}\n\n/** Children on their own lines; JSX drops whitespace-only lines between elements. */\nfunction indented(children: SyntaxNode[], depth: number): SyntaxNode[] {\n const inner = `\\n${' '.repeat(depth + 1)}`\n return [\n ...children.flatMap((child) => [whitespace(inner), child]),\n whitespace(`\\n${' '.repeat(depth)}`)\n ]\n}\n\n/**\n * An element at nesting `depth`. Children go on their own lines unless `inline`, as for a\n * lone text child; without children the element self-closes.\n */\nexport function element(\n tag: string,\n attributes: SyntaxNode[],\n children: SyntaxNode[],\n depth: number,\n inline = false\n): SyntaxNode {\n const name = tagName(tag)\n const content = inline || children.length === 0 ? children : indented(children, depth)\n return {\n type: 'JSXElement',\n openingElement: {\n type: 'JSXOpeningElement',\n name,\n attributes,\n selfClosing: content.length === 0\n },\n closingElement: content.length > 0 ? { type: 'JSXClosingElement', name } : null,\n children: content\n }\n}\n\n/** `<>…</>`: children without an element around them, laid out as an element's are. */\nexport function fragment(children: SyntaxNode[], depth: number): SyntaxNode {\n return {\n type: 'JSXFragment',\n openingFragment: { type: 'JSXOpeningFragment' },\n closingFragment: { type: 'JSXClosingFragment' },\n children: children.length === 0 ? [] : indented(children, depth)\n }\n}\n\nexport function printJSX(node: SyntaxNode): string {\n return print(node, tsx({ quotes: 'double' }), { indent: ' ' }).code\n}\n\n/** A copy without strings' source spelling, so the printer quotes every string the same way. */\nfunction withoutRawStrings(node: SyntaxNode): SyntaxNode {\n const copy: SyntaxNode = { ...node }\n if (node.type === 'Literal' && typeof node.value === 'string') delete copy.raw\n for (const [key, value] of Object.entries(node)) {\n if (Array.isArray(value))\n copy[key] = value.map((item: unknown) => (isNode(item) ? withoutRawStrings(item) : item))\n else if (isNode(value)) copy[key] = withoutRawStrings(value)\n }\n return copy\n}\n\n/**\n * A TSX module, such as a component built with `es` templates and JSX from this module. Strings\n * parsed from a template and strings built here print with the same double quotes.\n */\nexport function printModule(program: SyntaxNode): string {\n return print(withoutRawStrings(program), tsx({ quotes: 'double' }), { indent: ' ' }).code\n}\n","import { escapeAttribute, escapeText } from 'entities'\n\nimport { printExpression, printModule, type SyntaxNode } from './estree'\n\n/**\n * Text and attribute values are escaped as HTML by `entities`. Vue also reads `{{` as an\n * interpolation before it decodes entities, so text writes `{` as one too and a design's text\n * can never become template syntax.\n */\nconst templateText = (value: string) => escapeText(value).replaceAll('{', '&#123;')\n\nexport type VueAttribute =\n | { type: 'static'; name: string; value: string }\n /** `:name=\"expression\"` */\n | { type: 'bound'; name: string; expression: SyntaxNode }\n /** `v-model=\"expression\"`, or `v-model:argument` */\n | { type: 'model'; argument?: string; expression: SyntaxNode }\n /** `v-if=\"expression\"`: the element renders only while the expression holds. */\n | { type: 'if'; expression: SyntaxNode }\n /**\n * `v-bind=\"expression\"`: every attribute of an object, such as `$attrs`. Attributes after it\n * override its own of the same name, as Vue merges them in order.\n */\n | { type: 'spread'; expression: SyntaxNode }\n\nexport interface VueElement {\n type: 'element'\n tag: string\n attributes: VueAttribute[]\n children: VueNode[]\n}\n\nexport interface VueText {\n type: 'text'\n value: string\n}\n\n/** `{{ expression }}`, printed from a syntax tree so it holds only what the tree says. */\nexport interface VueInterpolation {\n type: 'interpolation'\n expression: SyntaxNode\n}\n\nexport type VueNode = VueElement | VueText | VueInterpolation\n\nexport const attribute = (name: string, value: string): VueAttribute => ({\n type: 'static',\n name,\n value\n})\n\nexport const bound = (name: string, expression: SyntaxNode): VueAttribute => ({\n type: 'bound',\n name,\n expression\n})\n\nexport const model = (expression: SyntaxNode, argument?: string): VueAttribute => ({\n type: 'model',\n argument,\n expression\n})\n\nexport const renderIf = (expression: SyntaxNode): VueAttribute => ({ type: 'if', expression })\n\nexport const spread = (expression: SyntaxNode): VueAttribute => ({ type: 'spread', expression })\n\nexport const element = (\n tag: string,\n attributes: VueAttribute[] = [],\n children: VueNode[] = []\n): VueElement => ({ type: 'element', tag, attributes, children })\n\nexport const text = (value: string): VueText => ({ type: 'text', value })\n\nexport const interpolation = (expression: SyntaxNode): VueInterpolation => ({\n type: 'interpolation',\n expression\n})\n\nfunction printAttribute(item: VueAttribute): string {\n if (item.type === 'static') return `${item.name}=\"${escapeAttribute(item.value)}\"`\n const value = escapeAttribute(printExpression(item.expression))\n if (item.type === 'bound') return `:${item.name}=\"${value}\"`\n if (item.type === 'if') return `v-if=\"${value}\"`\n if (item.type === 'spread') return `v-bind=\"${value}\"`\n return `${item.argument ? `v-model:${item.argument}` : 'v-model'}=\"${value}\"`\n}\n\n/** Markup with nothing added around it, as text content needs. */\nfunction printInline(node: VueNode): string {\n if (node.type === 'text') return templateText(node.value)\n if (node.type === 'interpolation') {\n const expression = printExpression(node.expression)\n // The template ends an interpolation at the first `}}`, wherever it falls.\n if (expression.includes('}}'))\n throw new Error(`An interpolated expression cannot contain \"}}\": ${expression}`)\n return `{{ ${expression} }}`\n }\n const open = [node.tag, ...node.attributes.map(printAttribute)].join(' ')\n if (node.children.length === 0) return `<${open} />`\n return `<${open}>${node.children.map(printInline).join('')}</${node.tag}>`\n}\n\nfunction printNode(node: VueNode, depth: number): string {\n const indent = ' '.repeat(depth)\n // Vue renders whitespace between text and elements as a space, so an element with text or\n // an interpolation in it keeps its children on its own line, exactly as given.\n if (node.type !== 'element' || node.children.some((child) => child.type !== 'element'))\n return `${indent}${printInline(node)}`\n const open = [node.tag, ...node.attributes.map(printAttribute)].join(' ')\n if (node.children.length === 0) return `${indent}<${open} />`\n const children = node.children.map((child) => printNode(child, depth + 1))\n return [`${indent}<${open}>`, ...children, `${indent}</${node.tag}>`].join('\\n')\n}\n\n/** A template's markup, one element per line. */\nexport function printTemplate(root: VueNode): string {\n return printNode(root, 0)\n}\n\nexport interface VueComponent {\n /** The `<script setup lang=\"ts\">` body, a TypeScript program from `es`. */\n script: SyntaxNode\n template: VueNode\n /** Stylesheet text for a `<style scoped>` block. */\n style?: string\n}\n\n/**\n * A raw block's content, which ends at the first closing tag for its element. Strings in the\n * script and values in the stylesheet can come from an imported design, so a closing tag in\n * them is written `<\\\\/`, which JavaScript strings and CSS both read back as `</`.\n */\nconst rawBlock = (tag: string, content: string) =>\n `<${tag}>\\n${content.trim().replace(/<\\/(?=script|style)/gi, '<\\\\/')}\\n</${tag.split(' ')[0]}>`\n\n/** Whether a component's script has anything to write, so it gets a script block. */\nconst hasScript = (script: SyntaxNode) => printModule(script).trim() !== ''\n\nfunction templateElements(node: VueNode): VueElement[] {\n return node.type === 'element' ? [node, ...node.children.flatMap(templateElements)] : []\n}\n\n/**\n * The elements `printComponent` writes, in the order they open: the template's own, between\n * `null`s for the script, template, and style blocks that hold them.\n */\nexport function componentElements({\n script,\n template,\n style\n}: VueComponent): (VueElement | null)[] {\n return [\n ...(hasScript(script) ? [null] : []),\n null,\n ...templateElements(template),\n ...(style ? [null] : [])\n ]\n}\n\n/** A single-file component: script setup, template, and scoped style. */\nexport function printComponent({ script, template, style }: VueComponent): string {\n const code = printModule(script)\n // A component with nothing to import or declare has no script block.\n const blocks = [\n ...(code.trim() ? [rawBlock('script setup lang=\"ts\"', code)] : []),\n `<template>\\n${printNode(template, 1)}\\n</template>`,\n ...(style ? [rawBlock('style scoped', style)] : [])\n ]\n return `${bloc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uBC,cAAY,MAAM,CAAC,CAAC,KAAK,MAAM;AAEzE,SAAS,iBAAiB,MAA6B;CACrD,OAAO,KAAK,SAAS,YAAY,CAAC,MAAM,GAAG,KAAK,SAAS,QAAQ,gBAAgB,CAAC,IAAI,CAAC;AACzF;;;;;AAMA,SAAgB,kBAAkB,EAChC,QACA,UACA,SACsC;CACtC,OAAO;EACL,GAAI,UAAU,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC;EAClC;EACA,GAAG,iBAAiB,QAAQ;EAC5B,GAAI,QAAQ,CAAC,IAAI,IAAI,CAAC;CACxB;AACF;;AAGA,SAAgB,eAAe,EAAE,QAAQ,UAAU,SAA+B;CAChF,MAAM,OAAOA,cAAY,MAAM;CAO/B,OAAO,GAAG;EAJR,GAAI,KAAK,KAAK,IAAI,CAAC,SAAS,4BAA0B,IAAI,CAAC,IAAI,CAAC;EAChE,eAAe,UAAU,UAAU,CAAC,EAAE;EACtC,GAAI,QAAQ,CAAC,SAAS,gBAAgB,KAAK,CAAC,IAAI,CAAC;CAEpC,CAAC,CAAC,KAAK,MAAM,EAAE;AAChC"}
package/dist/index.d.ts CHANGED
@@ -49,7 +49,7 @@ declare function stringUnionType(values: string[]): SyntaxNode;
49
49
  /** An object type; a member whose third element is `true` is optional. */
50
50
  declare function objectType(entries: [string, SyntaxNode, boolean?][]): SyntaxNode;
51
51
  declare namespace jsx_d_exports {
52
- export { attribute$1 as attribute, container, element$1 as element, fragment, identifier, inlineText, literal, printJSX, printModule, spread, stringValue, text$1 as text, whitespace };
52
+ export { attribute$1 as attribute, container, element$1 as element, fragment, identifier, inlineText, literal, printJSX, printModule, spread$1 as spread, stringValue, text$1 as text, whitespace };
53
53
  }
54
54
  declare const identifier: (name: string) => SyntaxNode;
55
55
  declare const literal: (value: string | number | boolean) => SyntaxNode;
@@ -59,7 +59,7 @@ declare const whitespace: (value: string) => SyntaxNode;
59
59
  /** A string attribute value: quoted when JSX keeps it as written, an expression otherwise. */
60
60
  declare const stringValue: (value: string) => SyntaxNode;
61
61
  /** `{...expression}`, passing an object's properties on as attributes. */
62
- declare const spread: (argument: SyntaxNode) => SyntaxNode;
62
+ declare const spread$1: (argument: SyntaxNode) => SyntaxNode;
63
63
  /** An attribute; a null value prints the bare name, as for `true`. */
64
64
  /** An attribute. A name such as `xlink:href` is namespaced, as JSX parses it. */
65
65
  declare function attribute$1(name: string, value: SyntaxNode | null): SyntaxNode;
@@ -84,7 +84,7 @@ declare function printJSX(node: SyntaxNode): string;
84
84
  */
85
85
  declare function printModule(program: SyntaxNode): string;
86
86
  declare namespace vue_d_exports {
87
- export { VueAttribute, VueComponent, VueElement, VueInterpolation, VueNode, VueText, attribute, bound, componentElements, element, interpolation, model, printComponent, printTemplate, renderIf, text };
87
+ export { VueAttribute, VueComponent, VueElement, VueInterpolation, VueNode, VueText, attribute, bound, componentElements, element, interpolation, model, printComponent, printTemplate, renderIf, spread, text };
88
88
  }
89
89
  type VueAttribute = {
90
90
  type: 'static';
@@ -107,6 +107,14 @@ type VueAttribute = {
107
107
  {
108
108
  type: 'if';
109
109
  expression: SyntaxNode;
110
+ } |
111
+ /**
112
+ * `v-bind="expression"`: every attribute of an object, such as `$attrs`. Attributes after it
113
+ * override its own of the same name, as Vue merges them in order.
114
+ */
115
+ {
116
+ type: 'spread';
117
+ expression: SyntaxNode;
110
118
  };
111
119
  interface VueElement {
112
120
  type: 'element';
@@ -128,6 +136,7 @@ declare const attribute: (name: string, value: string) => VueAttribute;
128
136
  declare const bound: (name: string, expression: SyntaxNode) => VueAttribute;
129
137
  declare const model: (expression: SyntaxNode, argument?: string) => VueAttribute;
130
138
  declare const renderIf: (expression: SyntaxNode) => VueAttribute;
139
+ declare const spread: (expression: SyntaxNode) => VueAttribute;
131
140
  declare const element: (tag: string, attributes?: VueAttribute[], children?: VueNode[]) => VueElement;
132
141
  declare const text: (value: string) => VueText;
133
142
  declare const interpolation: (expression: SyntaxNode) => VueInterpolation;
@@ -1 +1 @@
1
- {"version":3,"file":"index.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eAAa;;;iBAO9B,YAAU,cAAc,OAAO,oBAAoB;;iBAcnD,OAAK,gBAAgB;;;;;iBASrB,WAAW,gBAAgB;;;;;iBAkB3B,UACd,aACA,YAAY,cACZ,UAAU,cACV,eACA,mBACC;;iBAiBa,SAAS,UAAU,cAAc,gBAAgB;iBASjD,SAAS,MAAM;;;;;iBAoBf,YAAY,SAAS;;;;KCpIzB;EACN;EAAgB;EAAc;;;;EAE9B;EAAe;EAAc,YAAY;;;;EAEzC;EAAe;EAAmB,YAAY;;;;EAE9C;EAAY,YAAY;;;;;;;EAKxB;EAAgB,YAAY;;UAEjB;EACf;EACA;EACA,YAAY;EACZ,UAAU;;UAGK;EACf;EACA;;;UAIe;EACf;EACA,YAAY;;KAGF,UAAU,aAAa,UAAU;cAEhC,YAAa,cAAc,kBAAgB;cAM3C,QAAS,cAAc,YAAY,eAAa;cAMhD,QAAS,YAAY,YAAY,sBAAoB;cAMrD,WAAY,YAAY,eAAa;cAErC,SAAU,YAAY,eAAa;cAEnC,UACX,aACA,aAAY,gBACZ,WAAU,cACT;cAEU,OAAQ,kBAAgB;cAExB,gBAAiB,YAAY,eAAa;;iBA0CvC,cAAc,MAAM;UAInB;;EAEf,QAAQ;EACR,UAAU;;EAEV;;;;;;iBAsBc,oBACd,QACA,UACA,SACC,gBAAgB;;iBAUH,iBAAiB,QAAQ,UAAU,SAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/emit",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
package/src/vue.ts CHANGED
@@ -17,6 +17,11 @@ export type VueAttribute =
17
17
  | { type: 'model'; argument?: string; expression: SyntaxNode }
18
18
  /** `v-if="expression"`: the element renders only while the expression holds. */
19
19
  | { type: 'if'; expression: SyntaxNode }
20
+ /**
21
+ * `v-bind="expression"`: every attribute of an object, such as `$attrs`. Attributes after it
22
+ * override its own of the same name, as Vue merges them in order.
23
+ */
24
+ | { type: 'spread'; expression: SyntaxNode }
20
25
 
21
26
  export interface VueElement {
22
27
  type: 'element'
@@ -58,6 +63,8 @@ export const model = (expression: SyntaxNode, argument?: string): VueAttribute =
58
63
 
59
64
  export const renderIf = (expression: SyntaxNode): VueAttribute => ({ type: 'if', expression })
60
65
 
66
+ export const spread = (expression: SyntaxNode): VueAttribute => ({ type: 'spread', expression })
67
+
61
68
  export const element = (
62
69
  tag: string,
63
70
  attributes: VueAttribute[] = [],
@@ -76,6 +83,7 @@ function printAttribute(item: VueAttribute): string {
76
83
  const value = escapeAttribute(printExpression(item.expression))
77
84
  if (item.type === 'bound') return `:${item.name}="${value}"`
78
85
  if (item.type === 'if') return `v-if="${value}"`
86
+ if (item.type === 'spread') return `v-bind="${value}"`
79
87
  return `${item.argument ? `v-model:${item.argument}` : 'v-model'}="${value}"`
80
88
  }
81
89