@vue-macros/named-template
Advanced tools
+26
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkKEUILPOZcjs = require('./chunk-KEUILPOZ.cjs'); | ||
| exports.MAIN_TEMPLATE = _chunkKEUILPOZcjs.MAIN_TEMPLATE; exports.QUERY_NAMED_TEMPLATE = _chunkKEUILPOZcjs.QUERY_NAMED_TEMPLATE; exports.QUERY_TEMPLATE = _chunkKEUILPOZcjs.QUERY_TEMPLATE; exports.QUERY_TEMPLATE_MAIN = _chunkKEUILPOZcjs.QUERY_TEMPLATE_MAIN; exports.getChildrenLocation = _chunkKEUILPOZcjs.getChildrenLocation; exports.parseVueRequest = _chunkKEUILPOZcjs.parseVueRequest; exports.postTransform = _chunkKEUILPOZcjs.postTransform; exports.postTransformMainEntry = _chunkKEUILPOZcjs.postTransformMainEntry; exports.preTransform = _chunkKEUILPOZcjs.preTransform; exports.preTransformMainTemplate = _chunkKEUILPOZcjs.preTransformMainTemplate; exports.transformTemplateIs = _chunkKEUILPOZcjs.transformTemplateIs; |
| import { MagicStringAST, CodeTransform } from '@vue-macros/common'; | ||
| import { ElementNode, NodeTransform, RootNode } from '@vue/compiler-dom'; | ||
| import { T as TemplateContent, C as CustomBlocks } from './index.d-Ccebqmdc.js'; | ||
| export { M as MAIN_TEMPLATE, Q as QUERY_NAMED_TEMPLATE, a as QUERY_TEMPLATE, b as QUERY_TEMPLATE_MAIN } from './index.d-Ccebqmdc.js'; | ||
| import { Program } from '@babel/types'; | ||
| import 'unplugin'; | ||
| declare function getChildrenLocation(node: ElementNode): [number, number] | undefined; | ||
| interface VueQuery { | ||
| vue?: boolean; | ||
| src?: string; | ||
| type?: 'script' | 'template' | 'style' | 'custom'; | ||
| index?: number; | ||
| lang?: string; | ||
| raw?: boolean; | ||
| url?: boolean; | ||
| scoped?: boolean; | ||
| } | ||
| /** | ||
| * Copy from https://github.com/vitejs/vite-plugin-vue/blob/797e424e46600c93fa76a4ef8befc08ef6b5abdb/packages/plugin-vue/src/utils/query.ts#L12 | ||
| */ | ||
| declare function parseVueRequest(id: string): { | ||
| filename: string; | ||
| query: VueQuery; | ||
| }; | ||
| declare function transformTemplateIs(s: MagicStringAST): NodeTransform; | ||
| declare function preTransform(code: string, id: string, templateContent: TemplateContent): CodeTransform | undefined; | ||
| declare function preTransformMainTemplate({ s, root, node, id, templateContent, }: { | ||
| s: MagicStringAST; | ||
| root: RootNode; | ||
| node: ElementNode; | ||
| id: string; | ||
| templateContent: TemplateContent; | ||
| }): void; | ||
| declare function postTransform(code: string, id: string, customBlocks: CustomBlocks): CodeTransform | undefined; | ||
| declare function postTransformMainEntry(program: Program, id: string, customBlocks: CustomBlocks): void; | ||
| export { type VueQuery, getChildrenLocation, parseVueRequest, postTransform, postTransformMainEntry, preTransform, preTransformMainTemplate, transformTemplateIs }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } | ||
| var _chunkKEUILPOZcjs = require('./chunk-KEUILPOZ.cjs'); | ||
| // src/index.ts | ||
| var _common = require('@vue-macros/common'); | ||
| var _unplugin = require('unplugin'); | ||
| function resolveOptions(options) { | ||
| const version = options.version || _common.detectVueVersion.call(void 0, ); | ||
| return { | ||
| include: [_common.REGEX_VUE_SFC], | ||
| ...options, | ||
| version | ||
| }; | ||
| } | ||
| var name = "unplugin-vue-named-template"; | ||
| var PrePlugin = _unplugin.createUnplugin.call(void 0, (userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = _common.createFilter.call(void 0, options); | ||
| const templateContent = /* @__PURE__ */ Object.create(null); | ||
| return { | ||
| name: `${name}-pre`, | ||
| enforce: "pre", | ||
| loadInclude(id) { | ||
| return id.includes(_chunkKEUILPOZcjs.QUERY_TEMPLATE); | ||
| }, | ||
| load(id) { | ||
| const { filename, query } = _chunkKEUILPOZcjs.parseVueRequest.call(void 0, id); | ||
| const content = _optionalChain([templateContent, 'access', _ => _[filename], 'optionalAccess', _2 => _2["mainTemplate" in query ? _chunkKEUILPOZcjs.MAIN_TEMPLATE : query.name]]); | ||
| return content; | ||
| }, | ||
| transformInclude(id) { | ||
| return filter(id) || id.includes(_chunkKEUILPOZcjs.QUERY_NAMED_TEMPLATE); | ||
| }, | ||
| transform(code, id) { | ||
| if (id.includes(_chunkKEUILPOZcjs.QUERY_NAMED_TEMPLATE)) { | ||
| const { filename, query } = _chunkKEUILPOZcjs.parseVueRequest.call(void 0, id); | ||
| const { name: name2 } = query; | ||
| const request = `${filename}?vue&${_chunkKEUILPOZcjs.QUERY_TEMPLATE}&name=${name2}`; | ||
| return `import { createTextVNode } from 'vue' | ||
| import { render } from ${JSON.stringify(request)} | ||
| export default { | ||
| render: (...args) => { | ||
| const r = render(...args) | ||
| return typeof r === 'string' ? createTextVNode(r) : r | ||
| } | ||
| }`; | ||
| } else { | ||
| return _chunkKEUILPOZcjs.preTransform.call(void 0, code, id, templateContent); | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
| var PostPlugin = _unplugin.createUnplugin.call(void 0, (userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = _common.createFilter.call(void 0, options); | ||
| const customBlocks = /* @__PURE__ */ Object.create(null); | ||
| function transformInclude(id) { | ||
| return filter(id) || id.includes(_chunkKEUILPOZcjs.QUERY_TEMPLATE); | ||
| } | ||
| return { | ||
| name: `${name}-post`, | ||
| enforce: "post", | ||
| transformInclude, | ||
| transform(code, id) { | ||
| return _chunkKEUILPOZcjs.postTransform.call(void 0, code, id, customBlocks); | ||
| }, | ||
| rollup: { | ||
| transform: { | ||
| order: "post", | ||
| handler(code, id) { | ||
| if (!transformInclude(id)) return; | ||
| return _chunkKEUILPOZcjs.postTransform.call(void 0, code, id, customBlocks); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
| var plugin = _unplugin.createUnplugin.call(void 0, | ||
| (userOptions = {}, meta) => { | ||
| return [PrePlugin.raw(userOptions, meta), PostPlugin.raw(userOptions, meta)]; | ||
| } | ||
| ); | ||
| var src_default = plugin; | ||
| exports.PrePlugin = PrePlugin; exports.PostPlugin = PostPlugin; exports.src_default = src_default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/constants.ts | ||
| var QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
| var QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| var QUERY_TEMPLATE_MAIN = `${QUERY_TEMPLATE}&mainTemplate`; | ||
| var MAIN_TEMPLATE = Symbol(); | ||
| // src/core/utils.ts | ||
| function getChildrenLocation(node) { | ||
| if (node.children.length > 0) { | ||
| const lastChild = node.children.at(-1); | ||
| return [node.children[0].loc.start.offset, lastChild.loc.end.offset]; | ||
| } else { | ||
| return void 0; | ||
| } | ||
| } | ||
| function parseVueRequest(id) { | ||
| const [filename, rawQuery] = id.split(`?`, 2); | ||
| const query = Object.fromEntries(new URLSearchParams(rawQuery)); | ||
| if (query.vue != null) { | ||
| query.vue = true; | ||
| } | ||
| if (query.index != null) { | ||
| query.index = Number(query.index); | ||
| } | ||
| if (query.raw != null) { | ||
| query.raw = true; | ||
| } | ||
| if (query.url != null) { | ||
| query.url = true; | ||
| } | ||
| if (query.scoped != null) { | ||
| query.scoped = true; | ||
| } | ||
| return { | ||
| filename, | ||
| query | ||
| }; | ||
| } | ||
| // src/core/index.ts | ||
| var _common = require('@vue-macros/common'); | ||
| var _compilerdom = require('@vue/compiler-dom'); | ||
| function transformTemplateIs(s) { | ||
| return (node) => { | ||
| if (!(node.type === 1 && node.tag === "template")) | ||
| return; | ||
| const propIs = node.props.find( | ||
| (prop) => prop.type === 6 && prop.name === "is" | ||
| ); | ||
| if (!_optionalChain([propIs, 'optionalAccess', _ => _.value])) return; | ||
| const refName = propIs.value.content; | ||
| s.overwrite( | ||
| node.loc.start.offset, | ||
| node.loc.end.offset, | ||
| `<component is="named-template-${refName}" />` | ||
| ); | ||
| }; | ||
| } | ||
| function preTransform(code, id, templateContent) { | ||
| const root = _compilerdom.parse.call(void 0, code); | ||
| const templates = root.children.filter( | ||
| (node) => node.type === 1 && node.tag === "template" | ||
| ); | ||
| if (templates.length <= 1) return; | ||
| const s = new (0, _common.MagicStringAST)(code); | ||
| for (const node of templates) { | ||
| const propName = node.props.find( | ||
| (prop) => prop.type === 6 && prop.name === "name" | ||
| ); | ||
| if (!propName) { | ||
| preTransformMainTemplate({ s, root, node, id, templateContent }); | ||
| continue; | ||
| } else if (!propName.value) { | ||
| continue; | ||
| } | ||
| const name = propName.value.content; | ||
| let template = ""; | ||
| const templateLoc = getChildrenLocation(node); | ||
| if (templateLoc) { | ||
| template = s.slice(...templateLoc); | ||
| } | ||
| if (!templateContent[id]) templateContent[id] = /* @__PURE__ */ Object.create(null); | ||
| templateContent[id][name] = template; | ||
| s.appendLeft(node.loc.start.offset, `<named-template name="${name}">`); | ||
| s.appendLeft(node.loc.end.offset, "</named-template>"); | ||
| } | ||
| return _common.generateTransform.call(void 0, s, id); | ||
| } | ||
| function preTransformMainTemplate({ | ||
| s, | ||
| root, | ||
| node, | ||
| id, | ||
| templateContent | ||
| }) { | ||
| const ctx = _compilerdom.createTransformContext.call(void 0, root, { | ||
| filename: id, | ||
| nodeTransforms: [transformTemplateIs(s)] | ||
| }); | ||
| _compilerdom.traverseNode.call(void 0, node, ctx); | ||
| const loc = getChildrenLocation(node); | ||
| if (!loc) return; | ||
| if (!templateContent[id]) templateContent[id] = /* @__PURE__ */ Object.create(null); | ||
| templateContent[id][MAIN_TEMPLATE] = s.slice(...loc); | ||
| s.remove(...loc); | ||
| const offset = node.loc.start.offset + 1 + node.tag.length; | ||
| s.appendLeft(offset, ` src="${`${id}?vue&${QUERY_TEMPLATE_MAIN}`}"`); | ||
| } | ||
| function postTransform(code, id, customBlocks) { | ||
| const lang = _common.getLang.call(void 0, id); | ||
| const program = _common.babelParse.call(void 0, code, lang); | ||
| const { filename } = parseVueRequest(id); | ||
| if (!id.includes(QUERY_TEMPLATE_MAIN)) { | ||
| postTransformMainEntry(program, filename, customBlocks); | ||
| return; | ||
| } | ||
| const s = new (0, _common.MagicStringAST)(code); | ||
| const subTemplates = []; | ||
| for (const node of program.body) { | ||
| if (node.type === "ExportNamedDeclaration" && _optionalChain([node, 'access', _2 => _2.declaration, 'optionalAccess', _3 => _3.type]) === "FunctionDeclaration" && _optionalChain([node, 'access', _4 => _4.declaration, 'access', _5 => _5.id, 'optionalAccess', _6 => _6.name]) === "render") { | ||
| const params = node.declaration.params; | ||
| if (params.length > 0) { | ||
| const lastParams = params[node.declaration.params.length - 1]; | ||
| const loc = [params[0].start, lastParams.end]; | ||
| const paramsText = s.slice(...loc); | ||
| s.overwrite(...loc, "...args"); | ||
| s.appendLeft( | ||
| node.declaration.body.start + 1, | ||
| ` | ||
| let [${paramsText}] = args` | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| _common.walkAST.call(void 0, program, { | ||
| enter(node) { | ||
| if (_common.isCallOf.call(void 0, node, ["_createVNode", "_createBlock"]) && _common.isCallOf.call(void 0, node.arguments[0], "_resolveDynamicComponent") && node.arguments[0].arguments[0].type === "StringLiteral" && node.arguments[0].arguments[0].value.startsWith("named-template-")) { | ||
| subTemplates.push({ | ||
| vnode: node, | ||
| component: node.arguments[0], | ||
| name: node.arguments[0].arguments[0].value.replace( | ||
| "named-template-", | ||
| "" | ||
| ), | ||
| fnName: node.callee.name | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| if (subTemplates.length === 0) return; | ||
| for (const { vnode, component, name, fnName } of subTemplates) { | ||
| const block = _optionalChain([customBlocks, 'access', _7 => _7[filename], 'optionalAccess', _8 => _8[name]]); | ||
| if (!block) throw new SyntaxError(`Unknown named template: ${name}`); | ||
| const render = `${_common.HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
| )}.render(...args)`; | ||
| if (fnName === "_createVNode") { | ||
| s.overwriteNode(vnode, render); | ||
| } else if (fnName === "_createBlock") { | ||
| s.overwriteNode(component, _common.importHelperFn.call(void 0, s, 0, "Fragment")); | ||
| const text = `${vnode.arguments[1] ? "" : ", null"}, [${render}]`; | ||
| s.appendLeft((vnode.arguments[1] || vnode.arguments[0]).end, text); | ||
| } | ||
| } | ||
| for (const [name, source] of Object.entries(customBlocks[filename])) { | ||
| s.prepend( | ||
| `import ${_common.HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
| )} from ${JSON.stringify(source)}; | ||
| ` | ||
| ); | ||
| } | ||
| return _common.generateTransform.call(void 0, s, id); | ||
| } | ||
| function postTransformMainEntry(program, id, customBlocks) { | ||
| for (const node of program.body) { | ||
| if (node.type === "ImportDeclaration" && node.source.value.includes(QUERY_NAMED_TEMPLATE)) { | ||
| const { name } = parseVueRequest(node.source.value).query; | ||
| if (!customBlocks[id]) customBlocks[id] = /* @__PURE__ */ Object.create(null); | ||
| customBlocks[id][name] = node.source.value; | ||
| } | ||
| } | ||
| } | ||
| function escapeTemplateName(name) { | ||
| return name.replaceAll("-", "$DASH"); | ||
| } | ||
| exports.QUERY_NAMED_TEMPLATE = QUERY_NAMED_TEMPLATE; exports.QUERY_TEMPLATE = QUERY_TEMPLATE; exports.QUERY_TEMPLATE_MAIN = QUERY_TEMPLATE_MAIN; exports.MAIN_TEMPLATE = MAIN_TEMPLATE; exports.getChildrenLocation = getChildrenLocation; exports.parseVueRequest = parseVueRequest; exports.transformTemplateIs = transformTemplateIs; exports.preTransform = preTransform; exports.preTransformMainTemplate = preTransformMainTemplate; exports.postTransform = postTransform; exports.postTransformMainEntry = postTransformMainEntry; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/esbuild.ts | ||
| var esbuild_default = _chunk5WNB2BRYcjs.src_default.esbuild; | ||
| exports.default = esbuild_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.esbuild; | ||
| export = _default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| exports.PostPlugin = _chunk5WNB2BRYcjs.PostPlugin; exports.PrePlugin = _chunk5WNB2BRYcjs.PrePlugin; exports.default = _chunk5WNB2BRYcjs.src_default; |
| import { BaseOptions, MarkRequired } from '@vue-macros/common'; | ||
| import { UnpluginInstance } from 'unplugin'; | ||
| declare const QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
| declare const QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| declare const QUERY_TEMPLATE_MAIN: 'type=template&namedTemplate&mainTemplate'; | ||
| declare const MAIN_TEMPLATE: unique symbol; | ||
| type Options = BaseOptions; | ||
| type OptionsResolved = MarkRequired<Options, 'include' | 'version'>; | ||
| type TemplateContent = Record<string, Record<string, string> & { | ||
| [MAIN_TEMPLATE]?: string; | ||
| }>; | ||
| declare const PrePlugin: UnpluginInstance<Options | undefined, false>; | ||
| type CustomBlocks = Record<string, Record<string, string>>; | ||
| declare const PostPlugin: UnpluginInstance<Options | undefined, false>; | ||
| declare const plugin: UnpluginInstance<Options | undefined, true>; | ||
| export { type CustomBlocks as C, MAIN_TEMPLATE as M, type Options as O, PrePlugin as P, QUERY_NAMED_TEMPLATE as Q, type TemplateContent as T, QUERY_TEMPLATE as a, QUERY_TEMPLATE_MAIN as b, type OptionsResolved as c, PostPlugin as d, plugin as p }; |
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| export { C as CustomBlocks, O as Options, c as OptionsResolved, d as PostPlugin, P as PrePlugin, T as TemplateContent, p as default } from './index.d-Ccebqmdc.js'; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/rolldown.ts | ||
| var rolldown_default = _chunk5WNB2BRYcjs.src_default.rolldown; | ||
| exports.default = rolldown_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rolldown; | ||
| export = _default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/rollup.ts | ||
| var rollup_default = _chunk5WNB2BRYcjs.src_default.rollup; | ||
| exports.default = rollup_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rollup; | ||
| export = _default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/rspack.ts | ||
| var rspack_default = _chunk5WNB2BRYcjs.src_default.rspack; | ||
| exports.default = rspack_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rspack; | ||
| export = _default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/vite.ts | ||
| var vite_default = _chunk5WNB2BRYcjs.src_default.vite; | ||
| exports.default = vite_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.vite; | ||
| export = _default; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5WNB2BRYcjs = require('./chunk-5WNB2BRY.cjs'); | ||
| require('./chunk-KEUILPOZ.cjs'); | ||
| // src/webpack.ts | ||
| var webpack_default = _chunk5WNB2BRYcjs.src_default.webpack; | ||
| exports.default = webpack_default; | ||
| module.exports = exports.default; |
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.webpack; | ||
| export = _default; |
+2
-2
| import { MagicStringAST, CodeTransform } from '@vue-macros/common'; | ||
| import { ElementNode, NodeTransform, RootNode } from '@vue/compiler-dom'; | ||
| import { T as TemplateContent, C as CustomBlocks } from './index-Ccebqmdc.js'; | ||
| export { M as MAIN_TEMPLATE, Q as QUERY_NAMED_TEMPLATE, a as QUERY_TEMPLATE, b as QUERY_TEMPLATE_MAIN } from './index-Ccebqmdc.js'; | ||
| import { T as TemplateContent, C as CustomBlocks } from './index.d-Ccebqmdc.js'; | ||
| export { M as MAIN_TEMPLATE, Q as QUERY_NAMED_TEMPLATE, a as QUERY_TEMPLATE, b as QUERY_TEMPLATE_MAIN } from './index.d-Ccebqmdc.js'; | ||
| import { Program } from '@babel/types'; | ||
@@ -6,0 +6,0 @@ import 'unplugin'; |
+26
-26
@@ -1,26 +0,26 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk3JCYISGAjs = require('./chunk-3JCYISGA.js'); | ||
| exports.MAIN_TEMPLATE = _chunk3JCYISGAjs.MAIN_TEMPLATE; exports.QUERY_NAMED_TEMPLATE = _chunk3JCYISGAjs.QUERY_NAMED_TEMPLATE; exports.QUERY_TEMPLATE = _chunk3JCYISGAjs.QUERY_TEMPLATE; exports.QUERY_TEMPLATE_MAIN = _chunk3JCYISGAjs.QUERY_TEMPLATE_MAIN; exports.getChildrenLocation = _chunk3JCYISGAjs.getChildrenLocation; exports.parseVueRequest = _chunk3JCYISGAjs.parseVueRequest; exports.postTransform = _chunk3JCYISGAjs.postTransform; exports.postTransformMainEntry = _chunk3JCYISGAjs.postTransformMainEntry; exports.preTransform = _chunk3JCYISGAjs.preTransform; exports.preTransformMainTemplate = _chunk3JCYISGAjs.preTransformMainTemplate; exports.transformTemplateIs = _chunk3JCYISGAjs.transformTemplateIs; | ||
| import { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| postTransform, | ||
| postTransformMainEntry, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| transformTemplateIs | ||
| } from "./chunk-3JCYISGA.js"; | ||
| export { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| postTransform, | ||
| postTransformMainEntry, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| transformTemplateIs | ||
| }; |
+46
-46
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/constants.ts | ||
| // src/core/constants.ts | ||
| var QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
@@ -41,17 +41,17 @@ var QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| // src/core/index.ts | ||
| var _common = require('@vue-macros/common'); | ||
| var _compilerdom = require('@vue/compiler-dom'); | ||
| import { | ||
| babelParse, | ||
| generateTransform, | ||
| getLang, | ||
| HELPER_PREFIX, | ||
| importHelperFn, | ||
| isCallOf, | ||
| MagicStringAST, | ||
| walkAST | ||
| } from "@vue-macros/common"; | ||
| import { | ||
| createTransformContext, | ||
| parse, | ||
| traverseNode | ||
| } from "@vue/compiler-dom"; | ||
| function transformTemplateIs(s) { | ||
@@ -64,3 +64,3 @@ return (node) => { | ||
| ); | ||
| if (!_optionalChain([propIs, 'optionalAccess', _ => _.value])) return; | ||
| if (!propIs?.value) return; | ||
| const refName = propIs.value.content; | ||
@@ -75,3 +75,3 @@ s.overwrite( | ||
| function preTransform(code, id, templateContent) { | ||
| const root = _compilerdom.parse.call(void 0, code); | ||
| const root = parse(code); | ||
| const templates = root.children.filter( | ||
@@ -81,3 +81,3 @@ (node) => node.type === 1 && node.tag === "template" | ||
| if (templates.length <= 1) return; | ||
| const s = new (0, _common.MagicStringAST)(code); | ||
| const s = new MagicStringAST(code); | ||
| for (const node of templates) { | ||
@@ -104,3 +104,3 @@ const propName = node.props.find( | ||
| } | ||
| return _common.generateTransform.call(void 0, s, id); | ||
| return generateTransform(s, id); | ||
| } | ||
@@ -114,7 +114,7 @@ function preTransformMainTemplate({ | ||
| }) { | ||
| const ctx = _compilerdom.createTransformContext.call(void 0, root, { | ||
| const ctx = createTransformContext(root, { | ||
| filename: id, | ||
| nodeTransforms: [transformTemplateIs(s)] | ||
| }); | ||
| _compilerdom.traverseNode.call(void 0, node, ctx); | ||
| traverseNode(node, ctx); | ||
| const loc = getChildrenLocation(node); | ||
@@ -129,4 +129,4 @@ if (!loc) return; | ||
| function postTransform(code, id, customBlocks) { | ||
| const lang = _common.getLang.call(void 0, id); | ||
| const program = _common.babelParse.call(void 0, code, lang); | ||
| const lang = getLang(id); | ||
| const program = babelParse(code, lang); | ||
| const { filename } = parseVueRequest(id); | ||
@@ -137,6 +137,6 @@ if (!id.includes(QUERY_TEMPLATE_MAIN)) { | ||
| } | ||
| const s = new (0, _common.MagicStringAST)(code); | ||
| const s = new MagicStringAST(code); | ||
| const subTemplates = []; | ||
| for (const node of program.body) { | ||
| if (node.type === "ExportNamedDeclaration" && _optionalChain([node, 'access', _2 => _2.declaration, 'optionalAccess', _3 => _3.type]) === "FunctionDeclaration" && _optionalChain([node, 'access', _4 => _4.declaration, 'access', _5 => _5.id, 'optionalAccess', _6 => _6.name]) === "render") { | ||
| if (node.type === "ExportNamedDeclaration" && node.declaration?.type === "FunctionDeclaration" && node.declaration.id?.name === "render") { | ||
| const params = node.declaration.params; | ||
@@ -156,5 +156,5 @@ if (params.length > 0) { | ||
| } | ||
| _common.walkAST.call(void 0, program, { | ||
| walkAST(program, { | ||
| enter(node) { | ||
| if (_common.isCallOf.call(void 0, node, ["_createVNode", "_createBlock"]) && _common.isCallOf.call(void 0, node.arguments[0], "_resolveDynamicComponent") && node.arguments[0].arguments[0].type === "StringLiteral" && node.arguments[0].arguments[0].value.startsWith("named-template-")) { | ||
| if (isCallOf(node, ["_createVNode", "_createBlock"]) && isCallOf(node.arguments[0], "_resolveDynamicComponent") && node.arguments[0].arguments[0].type === "StringLiteral" && node.arguments[0].arguments[0].value.startsWith("named-template-")) { | ||
| subTemplates.push({ | ||
@@ -174,5 +174,5 @@ vnode: node, | ||
| for (const { vnode, component, name, fnName } of subTemplates) { | ||
| const block = _optionalChain([customBlocks, 'access', _7 => _7[filename], 'optionalAccess', _8 => _8[name]]); | ||
| const block = customBlocks[filename]?.[name]; | ||
| if (!block) throw new SyntaxError(`Unknown named template: ${name}`); | ||
| const render = `${_common.HELPER_PREFIX}block_${escapeTemplateName( | ||
| const render = `${HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
@@ -183,3 +183,3 @@ )}.render(...args)`; | ||
| } else if (fnName === "_createBlock") { | ||
| s.overwriteNode(component, _common.importHelperFn.call(void 0, s, 0, "Fragment")); | ||
| s.overwriteNode(component, importHelperFn(s, 0, "Fragment")); | ||
| const text = `${vnode.arguments[1] ? "" : ", null"}, [${render}]`; | ||
@@ -191,3 +191,3 @@ s.appendLeft((vnode.arguments[1] || vnode.arguments[0]).end, text); | ||
| s.prepend( | ||
| `import ${_common.HELPER_PREFIX}block_${escapeTemplateName( | ||
| `import ${HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
@@ -198,3 +198,3 @@ )} from ${JSON.stringify(source)}; | ||
| } | ||
| return _common.generateTransform.call(void 0, s, id); | ||
| return generateTransform(s, id); | ||
| } | ||
@@ -214,14 +214,14 @@ function postTransformMainEntry(program, id, customBlocks) { | ||
| exports.QUERY_NAMED_TEMPLATE = QUERY_NAMED_TEMPLATE; exports.QUERY_TEMPLATE = QUERY_TEMPLATE; exports.QUERY_TEMPLATE_MAIN = QUERY_TEMPLATE_MAIN; exports.MAIN_TEMPLATE = MAIN_TEMPLATE; exports.getChildrenLocation = getChildrenLocation; exports.parseVueRequest = parseVueRequest; exports.transformTemplateIs = transformTemplateIs; exports.preTransform = preTransform; exports.preTransformMainTemplate = preTransformMainTemplate; exports.postTransform = postTransform; exports.postTransformMainEntry = postTransformMainEntry; | ||
| export { | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| MAIN_TEMPLATE, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| transformTemplateIs, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| postTransform, | ||
| postTransformMainEntry | ||
| }; |
+37
-37
@@ -1,21 +0,21 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } | ||
| import { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| parseVueRequest, | ||
| postTransform, | ||
| preTransform | ||
| } from "./chunk-3JCYISGA.js"; | ||
| var _chunk3JCYISGAjs = require('./chunk-3JCYISGA.js'); | ||
| // src/index.ts | ||
| var _common = require('@vue-macros/common'); | ||
| var _unplugin = require('unplugin'); | ||
| import { | ||
| createFilter, | ||
| detectVueVersion, | ||
| REGEX_VUE_SFC | ||
| } from "@vue-macros/common"; | ||
| import { createUnplugin } from "unplugin"; | ||
| function resolveOptions(options) { | ||
| const version = options.version || _common.detectVueVersion.call(void 0, ); | ||
| const version = options.version || detectVueVersion(); | ||
| return { | ||
| include: [_common.REGEX_VUE_SFC], | ||
| include: [REGEX_VUE_SFC], | ||
| ...options, | ||
@@ -26,5 +26,5 @@ version | ||
| var name = "unplugin-vue-named-template"; | ||
| var PrePlugin = _unplugin.createUnplugin.call(void 0, (userOptions = {}) => { | ||
| var PrePlugin = createUnplugin((userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = _common.createFilter.call(void 0, options); | ||
| const filter = createFilter(options); | ||
| const templateContent = /* @__PURE__ */ Object.create(null); | ||
@@ -35,17 +35,17 @@ return { | ||
| loadInclude(id) { | ||
| return id.includes(_chunk3JCYISGAjs.QUERY_TEMPLATE); | ||
| return id.includes(QUERY_TEMPLATE); | ||
| }, | ||
| load(id) { | ||
| const { filename, query } = _chunk3JCYISGAjs.parseVueRequest.call(void 0, id); | ||
| const content = _optionalChain([templateContent, 'access', _ => _[filename], 'optionalAccess', _2 => _2["mainTemplate" in query ? _chunk3JCYISGAjs.MAIN_TEMPLATE : query.name]]); | ||
| const { filename, query } = parseVueRequest(id); | ||
| const content = templateContent[filename]?.["mainTemplate" in query ? MAIN_TEMPLATE : query.name]; | ||
| return content; | ||
| }, | ||
| transformInclude(id) { | ||
| return filter(id) || id.includes(_chunk3JCYISGAjs.QUERY_NAMED_TEMPLATE); | ||
| return filter(id) || id.includes(QUERY_NAMED_TEMPLATE); | ||
| }, | ||
| transform(code, id) { | ||
| if (id.includes(_chunk3JCYISGAjs.QUERY_NAMED_TEMPLATE)) { | ||
| const { filename, query } = _chunk3JCYISGAjs.parseVueRequest.call(void 0, id); | ||
| if (id.includes(QUERY_NAMED_TEMPLATE)) { | ||
| const { filename, query } = parseVueRequest(id); | ||
| const { name: name2 } = query; | ||
| const request = `${filename}?vue&${_chunk3JCYISGAjs.QUERY_TEMPLATE}&name=${name2}`; | ||
| const request = `${filename}?vue&${QUERY_TEMPLATE}&name=${name2}`; | ||
| return `import { createTextVNode } from 'vue' | ||
@@ -60,3 +60,3 @@ import { render } from ${JSON.stringify(request)} | ||
| } else { | ||
| return _chunk3JCYISGAjs.preTransform.call(void 0, code, id, templateContent); | ||
| return preTransform(code, id, templateContent); | ||
| } | ||
@@ -66,8 +66,8 @@ } | ||
| }); | ||
| var PostPlugin = _unplugin.createUnplugin.call(void 0, (userOptions = {}) => { | ||
| var PostPlugin = createUnplugin((userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = _common.createFilter.call(void 0, options); | ||
| const filter = createFilter(options); | ||
| const customBlocks = /* @__PURE__ */ Object.create(null); | ||
| function transformInclude(id) { | ||
| return filter(id) || id.includes(_chunk3JCYISGAjs.QUERY_TEMPLATE); | ||
| return filter(id) || id.includes(QUERY_TEMPLATE); | ||
| } | ||
@@ -79,3 +79,3 @@ return { | ||
| transform(code, id) { | ||
| return _chunk3JCYISGAjs.postTransform.call(void 0, code, id, customBlocks); | ||
| return postTransform(code, id, customBlocks); | ||
| }, | ||
@@ -87,3 +87,3 @@ rollup: { | ||
| if (!transformInclude(id)) return; | ||
| return _chunk3JCYISGAjs.postTransform.call(void 0, code, id, customBlocks); | ||
| return postTransform(code, id, customBlocks); | ||
| } | ||
@@ -94,3 +94,3 @@ } | ||
| }); | ||
| var plugin = _unplugin.createUnplugin.call(void 0, | ||
| var plugin = createUnplugin( | ||
| (userOptions = {}, meta) => { | ||
@@ -102,6 +102,6 @@ return [PrePlugin.raw(userOptions, meta), PostPlugin.raw(userOptions, meta)]; | ||
| exports.PrePlugin = PrePlugin; exports.PostPlugin = PostPlugin; exports.src_default = src_default; | ||
| export { | ||
| PrePlugin, | ||
| PostPlugin, | ||
| src_default | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/esbuild.ts | ||
| var esbuild_default = _chunkLJFU2FPDjs.src_default.esbuild; | ||
| exports.default = esbuild_default; | ||
| module.exports = exports.default; | ||
| var esbuild_default = src_default.esbuild; | ||
| export { | ||
| esbuild_default as default | ||
| }; |
+1
-1
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| export { C as CustomBlocks, O as Options, c as OptionsResolved, d as PostPlugin, P as PrePlugin, T as TemplateContent, p as default } from './index-Ccebqmdc.js'; | ||
| export { C as CustomBlocks, O as Options, c as OptionsResolved, d as PostPlugin, P as PrePlugin, T as TemplateContent, p as default } from './index.d-Ccebqmdc.js'; |
+11
-11
@@ -1,11 +0,11 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| exports.PostPlugin = _chunkLJFU2FPDjs.PostPlugin; exports.PrePlugin = _chunkLJFU2FPDjs.PrePlugin; exports.default = _chunkLJFU2FPDjs.src_default; | ||
| import { | ||
| PostPlugin, | ||
| PrePlugin, | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| export { | ||
| PostPlugin, | ||
| PrePlugin, | ||
| src_default as default | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/rolldown.ts | ||
| var rolldown_default = _chunkLJFU2FPDjs.src_default.rolldown; | ||
| exports.default = rolldown_default; | ||
| module.exports = exports.default; | ||
| var rolldown_default = src_default.rolldown; | ||
| export { | ||
| rolldown_default as default | ||
| }; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/rollup.ts | ||
| var rollup_default = _chunkLJFU2FPDjs.src_default.rollup; | ||
| exports.default = rollup_default; | ||
| module.exports = exports.default; | ||
| var rollup_default = src_default.rollup; | ||
| export { | ||
| rollup_default as default | ||
| }; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/rspack.ts | ||
| var rspack_default = _chunkLJFU2FPDjs.src_default.rspack; | ||
| exports.default = rspack_default; | ||
| module.exports = exports.default; | ||
| var rspack_default = src_default.rspack; | ||
| export { | ||
| rspack_default as default | ||
| }; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/vite.ts | ||
| var vite_default = _chunkLJFU2FPDjs.src_default.vite; | ||
| exports.default = vite_default; | ||
| module.exports = exports.default; | ||
| var vite_default = src_default.vite; | ||
| export { | ||
| vite_default as default | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| import { p as plugin } from './index-Ccebqmdc.js'; | ||
| import { p as plugin } from './index.d-Ccebqmdc.js'; | ||
| import '@vue-macros/common'; | ||
@@ -7,2 +7,2 @@ import 'unplugin'; | ||
| export = _default; | ||
| export { _default as default }; |
+8
-10
@@ -1,12 +0,10 @@ | ||
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| import { | ||
| src_default | ||
| } from "./chunk-LJFU2FPD.js"; | ||
| import "./chunk-3JCYISGA.js"; | ||
| var _chunkLJFU2FPDjs = require('./chunk-LJFU2FPD.js'); | ||
| require('./chunk-3JCYISGA.js'); | ||
| // src/webpack.ts | ||
| var webpack_default = _chunkLJFU2FPDjs.src_default.webpack; | ||
| exports.default = webpack_default; | ||
| module.exports = exports.default; | ||
| var webpack_default = src_default.webpack; | ||
| export { | ||
| webpack_default as default | ||
| }; |
+24
-24
| { | ||
| "name": "@vue-macros/named-template", | ||
| "version": "0.4.10", | ||
| "version": "0.5.0", | ||
| "description": "named-template feature from Vue Macros.", | ||
| "type": "commonjs", | ||
| "type": "module", | ||
| "keywords": [ | ||
@@ -30,37 +30,37 @@ "vue-macros", | ||
| ], | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.mjs", | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/index.js", | ||
| "import": "./dist/index.mjs" | ||
| "require": "./dist/index.cjs", | ||
| "import": "./dist/index.js" | ||
| }, | ||
| "./api": { | ||
| "require": "./dist/api.js", | ||
| "import": "./dist/api.mjs" | ||
| "require": "./dist/api.cjs", | ||
| "import": "./dist/api.js" | ||
| }, | ||
| "./esbuild": { | ||
| "require": "./dist/esbuild.js", | ||
| "import": "./dist/esbuild.mjs" | ||
| "require": "./dist/esbuild.cjs", | ||
| "import": "./dist/esbuild.js" | ||
| }, | ||
| "./rolldown": { | ||
| "require": "./dist/rolldown.js", | ||
| "import": "./dist/rolldown.mjs" | ||
| "require": "./dist/rolldown.cjs", | ||
| "import": "./dist/rolldown.js" | ||
| }, | ||
| "./rollup": { | ||
| "require": "./dist/rollup.js", | ||
| "import": "./dist/rollup.mjs" | ||
| "require": "./dist/rollup.cjs", | ||
| "import": "./dist/rollup.js" | ||
| }, | ||
| "./rspack": { | ||
| "require": "./dist/rspack.js", | ||
| "import": "./dist/rspack.mjs" | ||
| "require": "./dist/rspack.cjs", | ||
| "import": "./dist/rspack.js" | ||
| }, | ||
| "./vite": { | ||
| "require": "./dist/vite.js", | ||
| "import": "./dist/vite.mjs" | ||
| "require": "./dist/vite.cjs", | ||
| "import": "./dist/vite.js" | ||
| }, | ||
| "./webpack": { | ||
| "require": "./dist/webpack.js", | ||
| "import": "./dist/webpack.mjs" | ||
| "require": "./dist/webpack.cjs", | ||
| "import": "./dist/webpack.js" | ||
| }, | ||
@@ -81,8 +81,8 @@ "./*": "./*" | ||
| "dependencies": { | ||
| "@vue/compiler-dom": "^3.5.3", | ||
| "unplugin": "^1.13.1", | ||
| "@vue-macros/common": "1.12.3" | ||
| "@vue/compiler-dom": "^3.5.4", | ||
| "unplugin": "^1.14.1", | ||
| "@vue-macros/common": "1.13.0" | ||
| }, | ||
| "devDependencies": { | ||
| "vue": "^3.5.3" | ||
| "vue": "^3.5.4" | ||
| }, | ||
@@ -89,0 +89,0 @@ "engines": { |
| import { MagicStringAST, CodeTransform } from '@vue-macros/common'; | ||
| import { ElementNode, NodeTransform, RootNode } from '@vue/compiler-dom'; | ||
| import { T as TemplateContent, C as CustomBlocks } from './index-Ccebqmdc.mjs'; | ||
| export { M as MAIN_TEMPLATE, Q as QUERY_NAMED_TEMPLATE, a as QUERY_TEMPLATE, b as QUERY_TEMPLATE_MAIN } from './index-Ccebqmdc.mjs'; | ||
| import { Program } from '@babel/types'; | ||
| import 'unplugin'; | ||
| declare function getChildrenLocation(node: ElementNode): [number, number] | undefined; | ||
| interface VueQuery { | ||
| vue?: boolean; | ||
| src?: string; | ||
| type?: 'script' | 'template' | 'style' | 'custom'; | ||
| index?: number; | ||
| lang?: string; | ||
| raw?: boolean; | ||
| url?: boolean; | ||
| scoped?: boolean; | ||
| } | ||
| /** | ||
| * Copy from https://github.com/vitejs/vite-plugin-vue/blob/797e424e46600c93fa76a4ef8befc08ef6b5abdb/packages/plugin-vue/src/utils/query.ts#L12 | ||
| */ | ||
| declare function parseVueRequest(id: string): { | ||
| filename: string; | ||
| query: VueQuery; | ||
| }; | ||
| declare function transformTemplateIs(s: MagicStringAST): NodeTransform; | ||
| declare function preTransform(code: string, id: string, templateContent: TemplateContent): CodeTransform | undefined; | ||
| declare function preTransformMainTemplate({ s, root, node, id, templateContent, }: { | ||
| s: MagicStringAST; | ||
| root: RootNode; | ||
| node: ElementNode; | ||
| id: string; | ||
| templateContent: TemplateContent; | ||
| }): void; | ||
| declare function postTransform(code: string, id: string, customBlocks: CustomBlocks): CodeTransform | undefined; | ||
| declare function postTransformMainEntry(program: Program, id: string, customBlocks: CustomBlocks): void; | ||
| export { type VueQuery, getChildrenLocation, parseVueRequest, postTransform, postTransformMainEntry, preTransform, preTransformMainTemplate, transformTemplateIs }; |
-26
| import { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| postTransform, | ||
| postTransformMainEntry, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| transformTemplateIs | ||
| } from "./chunk-B3MW6NAR.mjs"; | ||
| export { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| postTransform, | ||
| postTransformMainEntry, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| transformTemplateIs | ||
| }; |
| import { | ||
| MAIN_TEMPLATE, | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| parseVueRequest, | ||
| postTransform, | ||
| preTransform | ||
| } from "./chunk-B3MW6NAR.mjs"; | ||
| // src/index.ts | ||
| import { | ||
| createFilter, | ||
| detectVueVersion, | ||
| REGEX_VUE_SFC | ||
| } from "@vue-macros/common"; | ||
| import { createUnplugin } from "unplugin"; | ||
| function resolveOptions(options) { | ||
| const version = options.version || detectVueVersion(); | ||
| return { | ||
| include: [REGEX_VUE_SFC], | ||
| ...options, | ||
| version | ||
| }; | ||
| } | ||
| var name = "unplugin-vue-named-template"; | ||
| var PrePlugin = createUnplugin((userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = createFilter(options); | ||
| const templateContent = /* @__PURE__ */ Object.create(null); | ||
| return { | ||
| name: `${name}-pre`, | ||
| enforce: "pre", | ||
| loadInclude(id) { | ||
| return id.includes(QUERY_TEMPLATE); | ||
| }, | ||
| load(id) { | ||
| const { filename, query } = parseVueRequest(id); | ||
| const content = templateContent[filename]?.["mainTemplate" in query ? MAIN_TEMPLATE : query.name]; | ||
| return content; | ||
| }, | ||
| transformInclude(id) { | ||
| return filter(id) || id.includes(QUERY_NAMED_TEMPLATE); | ||
| }, | ||
| transform(code, id) { | ||
| if (id.includes(QUERY_NAMED_TEMPLATE)) { | ||
| const { filename, query } = parseVueRequest(id); | ||
| const { name: name2 } = query; | ||
| const request = `${filename}?vue&${QUERY_TEMPLATE}&name=${name2}`; | ||
| return `import { createTextVNode } from 'vue' | ||
| import { render } from ${JSON.stringify(request)} | ||
| export default { | ||
| render: (...args) => { | ||
| const r = render(...args) | ||
| return typeof r === 'string' ? createTextVNode(r) : r | ||
| } | ||
| }`; | ||
| } else { | ||
| return preTransform(code, id, templateContent); | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
| var PostPlugin = createUnplugin((userOptions = {}) => { | ||
| const options = resolveOptions(userOptions); | ||
| const filter = createFilter(options); | ||
| const customBlocks = /* @__PURE__ */ Object.create(null); | ||
| function transformInclude(id) { | ||
| return filter(id) || id.includes(QUERY_TEMPLATE); | ||
| } | ||
| return { | ||
| name: `${name}-post`, | ||
| enforce: "post", | ||
| transformInclude, | ||
| transform(code, id) { | ||
| return postTransform(code, id, customBlocks); | ||
| }, | ||
| rollup: { | ||
| transform: { | ||
| order: "post", | ||
| handler(code, id) { | ||
| if (!transformInclude(id)) return; | ||
| return postTransform(code, id, customBlocks); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
| var plugin = createUnplugin( | ||
| (userOptions = {}, meta) => { | ||
| return [PrePlugin.raw(userOptions, meta), PostPlugin.raw(userOptions, meta)]; | ||
| } | ||
| ); | ||
| var src_default = plugin; | ||
| export { | ||
| PrePlugin, | ||
| PostPlugin, | ||
| src_default | ||
| }; |
| // src/core/constants.ts | ||
| var QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
| var QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| var QUERY_TEMPLATE_MAIN = `${QUERY_TEMPLATE}&mainTemplate`; | ||
| var MAIN_TEMPLATE = Symbol(); | ||
| // src/core/utils.ts | ||
| function getChildrenLocation(node) { | ||
| if (node.children.length > 0) { | ||
| const lastChild = node.children.at(-1); | ||
| return [node.children[0].loc.start.offset, lastChild.loc.end.offset]; | ||
| } else { | ||
| return void 0; | ||
| } | ||
| } | ||
| function parseVueRequest(id) { | ||
| const [filename, rawQuery] = id.split(`?`, 2); | ||
| const query = Object.fromEntries(new URLSearchParams(rawQuery)); | ||
| if (query.vue != null) { | ||
| query.vue = true; | ||
| } | ||
| if (query.index != null) { | ||
| query.index = Number(query.index); | ||
| } | ||
| if (query.raw != null) { | ||
| query.raw = true; | ||
| } | ||
| if (query.url != null) { | ||
| query.url = true; | ||
| } | ||
| if (query.scoped != null) { | ||
| query.scoped = true; | ||
| } | ||
| return { | ||
| filename, | ||
| query | ||
| }; | ||
| } | ||
| // src/core/index.ts | ||
| import { | ||
| babelParse, | ||
| generateTransform, | ||
| getLang, | ||
| HELPER_PREFIX, | ||
| importHelperFn, | ||
| isCallOf, | ||
| MagicStringAST, | ||
| walkAST | ||
| } from "@vue-macros/common"; | ||
| import { | ||
| createTransformContext, | ||
| parse, | ||
| traverseNode | ||
| } from "@vue/compiler-dom"; | ||
| function transformTemplateIs(s) { | ||
| return (node) => { | ||
| if (!(node.type === 1 && node.tag === "template")) | ||
| return; | ||
| const propIs = node.props.find( | ||
| (prop) => prop.type === 6 && prop.name === "is" | ||
| ); | ||
| if (!propIs?.value) return; | ||
| const refName = propIs.value.content; | ||
| s.overwrite( | ||
| node.loc.start.offset, | ||
| node.loc.end.offset, | ||
| `<component is="named-template-${refName}" />` | ||
| ); | ||
| }; | ||
| } | ||
| function preTransform(code, id, templateContent) { | ||
| const root = parse(code); | ||
| const templates = root.children.filter( | ||
| (node) => node.type === 1 && node.tag === "template" | ||
| ); | ||
| if (templates.length <= 1) return; | ||
| const s = new MagicStringAST(code); | ||
| for (const node of templates) { | ||
| const propName = node.props.find( | ||
| (prop) => prop.type === 6 && prop.name === "name" | ||
| ); | ||
| if (!propName) { | ||
| preTransformMainTemplate({ s, root, node, id, templateContent }); | ||
| continue; | ||
| } else if (!propName.value) { | ||
| continue; | ||
| } | ||
| const name = propName.value.content; | ||
| let template = ""; | ||
| const templateLoc = getChildrenLocation(node); | ||
| if (templateLoc) { | ||
| template = s.slice(...templateLoc); | ||
| } | ||
| if (!templateContent[id]) templateContent[id] = /* @__PURE__ */ Object.create(null); | ||
| templateContent[id][name] = template; | ||
| s.appendLeft(node.loc.start.offset, `<named-template name="${name}">`); | ||
| s.appendLeft(node.loc.end.offset, "</named-template>"); | ||
| } | ||
| return generateTransform(s, id); | ||
| } | ||
| function preTransformMainTemplate({ | ||
| s, | ||
| root, | ||
| node, | ||
| id, | ||
| templateContent | ||
| }) { | ||
| const ctx = createTransformContext(root, { | ||
| filename: id, | ||
| nodeTransforms: [transformTemplateIs(s)] | ||
| }); | ||
| traverseNode(node, ctx); | ||
| const loc = getChildrenLocation(node); | ||
| if (!loc) return; | ||
| if (!templateContent[id]) templateContent[id] = /* @__PURE__ */ Object.create(null); | ||
| templateContent[id][MAIN_TEMPLATE] = s.slice(...loc); | ||
| s.remove(...loc); | ||
| const offset = node.loc.start.offset + 1 + node.tag.length; | ||
| s.appendLeft(offset, ` src="${`${id}?vue&${QUERY_TEMPLATE_MAIN}`}"`); | ||
| } | ||
| function postTransform(code, id, customBlocks) { | ||
| const lang = getLang(id); | ||
| const program = babelParse(code, lang); | ||
| const { filename } = parseVueRequest(id); | ||
| if (!id.includes(QUERY_TEMPLATE_MAIN)) { | ||
| postTransformMainEntry(program, filename, customBlocks); | ||
| return; | ||
| } | ||
| const s = new MagicStringAST(code); | ||
| const subTemplates = []; | ||
| for (const node of program.body) { | ||
| if (node.type === "ExportNamedDeclaration" && node.declaration?.type === "FunctionDeclaration" && node.declaration.id?.name === "render") { | ||
| const params = node.declaration.params; | ||
| if (params.length > 0) { | ||
| const lastParams = params[node.declaration.params.length - 1]; | ||
| const loc = [params[0].start, lastParams.end]; | ||
| const paramsText = s.slice(...loc); | ||
| s.overwrite(...loc, "...args"); | ||
| s.appendLeft( | ||
| node.declaration.body.start + 1, | ||
| ` | ||
| let [${paramsText}] = args` | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| walkAST(program, { | ||
| enter(node) { | ||
| if (isCallOf(node, ["_createVNode", "_createBlock"]) && isCallOf(node.arguments[0], "_resolveDynamicComponent") && node.arguments[0].arguments[0].type === "StringLiteral" && node.arguments[0].arguments[0].value.startsWith("named-template-")) { | ||
| subTemplates.push({ | ||
| vnode: node, | ||
| component: node.arguments[0], | ||
| name: node.arguments[0].arguments[0].value.replace( | ||
| "named-template-", | ||
| "" | ||
| ), | ||
| fnName: node.callee.name | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| if (subTemplates.length === 0) return; | ||
| for (const { vnode, component, name, fnName } of subTemplates) { | ||
| const block = customBlocks[filename]?.[name]; | ||
| if (!block) throw new SyntaxError(`Unknown named template: ${name}`); | ||
| const render = `${HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
| )}.render(...args)`; | ||
| if (fnName === "_createVNode") { | ||
| s.overwriteNode(vnode, render); | ||
| } else if (fnName === "_createBlock") { | ||
| s.overwriteNode(component, importHelperFn(s, 0, "Fragment")); | ||
| const text = `${vnode.arguments[1] ? "" : ", null"}, [${render}]`; | ||
| s.appendLeft((vnode.arguments[1] || vnode.arguments[0]).end, text); | ||
| } | ||
| } | ||
| for (const [name, source] of Object.entries(customBlocks[filename])) { | ||
| s.prepend( | ||
| `import ${HELPER_PREFIX}block_${escapeTemplateName( | ||
| name | ||
| )} from ${JSON.stringify(source)}; | ||
| ` | ||
| ); | ||
| } | ||
| return generateTransform(s, id); | ||
| } | ||
| function postTransformMainEntry(program, id, customBlocks) { | ||
| for (const node of program.body) { | ||
| if (node.type === "ImportDeclaration" && node.source.value.includes(QUERY_NAMED_TEMPLATE)) { | ||
| const { name } = parseVueRequest(node.source.value).query; | ||
| if (!customBlocks[id]) customBlocks[id] = /* @__PURE__ */ Object.create(null); | ||
| customBlocks[id][name] = node.source.value; | ||
| } | ||
| } | ||
| } | ||
| function escapeTemplateName(name) { | ||
| return name.replaceAll("-", "$DASH"); | ||
| } | ||
| export { | ||
| QUERY_NAMED_TEMPLATE, | ||
| QUERY_TEMPLATE, | ||
| QUERY_TEMPLATE_MAIN, | ||
| MAIN_TEMPLATE, | ||
| getChildrenLocation, | ||
| parseVueRequest, | ||
| transformTemplateIs, | ||
| preTransform, | ||
| preTransformMainTemplate, | ||
| postTransform, | ||
| postTransformMainEntry | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.esbuild; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/esbuild.ts | ||
| var esbuild_default = src_default.esbuild; | ||
| export { | ||
| esbuild_default as default | ||
| }; |
| import { BaseOptions, MarkRequired } from '@vue-macros/common'; | ||
| import { UnpluginInstance } from 'unplugin'; | ||
| declare const QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
| declare const QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| declare const QUERY_TEMPLATE_MAIN: 'type=template&namedTemplate&mainTemplate'; | ||
| declare const MAIN_TEMPLATE: unique symbol; | ||
| type Options = BaseOptions; | ||
| type OptionsResolved = MarkRequired<Options, 'include' | 'version'>; | ||
| type TemplateContent = Record<string, Record<string, string> & { | ||
| [MAIN_TEMPLATE]?: string; | ||
| }>; | ||
| declare const PrePlugin: UnpluginInstance<Options | undefined, false>; | ||
| type CustomBlocks = Record<string, Record<string, string>>; | ||
| declare const PostPlugin: UnpluginInstance<Options | undefined, false>; | ||
| declare const plugin: UnpluginInstance<Options | undefined, true>; | ||
| export { type CustomBlocks as C, MAIN_TEMPLATE as M, type Options as O, PrePlugin as P, QUERY_NAMED_TEMPLATE as Q, type TemplateContent as T, QUERY_TEMPLATE as a, QUERY_TEMPLATE_MAIN as b, type OptionsResolved as c, PostPlugin as d, plugin as p }; |
| import { BaseOptions, MarkRequired } from '@vue-macros/common'; | ||
| import { UnpluginInstance } from 'unplugin'; | ||
| declare const QUERY_NAMED_TEMPLATE = "?vue&type=named-template"; | ||
| declare const QUERY_TEMPLATE = "type=template&namedTemplate"; | ||
| declare const QUERY_TEMPLATE_MAIN: 'type=template&namedTemplate&mainTemplate'; | ||
| declare const MAIN_TEMPLATE: unique symbol; | ||
| type Options = BaseOptions; | ||
| type OptionsResolved = MarkRequired<Options, 'include' | 'version'>; | ||
| type TemplateContent = Record<string, Record<string, string> & { | ||
| [MAIN_TEMPLATE]?: string; | ||
| }>; | ||
| declare const PrePlugin: UnpluginInstance<Options | undefined, false>; | ||
| type CustomBlocks = Record<string, Record<string, string>>; | ||
| declare const PostPlugin: UnpluginInstance<Options | undefined, false>; | ||
| declare const plugin: UnpluginInstance<Options | undefined, true>; | ||
| export { type CustomBlocks as C, MAIN_TEMPLATE as M, type Options as O, PrePlugin as P, QUERY_NAMED_TEMPLATE as Q, type TemplateContent as T, QUERY_TEMPLATE as a, QUERY_TEMPLATE_MAIN as b, type OptionsResolved as c, PostPlugin as d, plugin as p }; |
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| export { C as CustomBlocks, O as Options, c as OptionsResolved, d as PostPlugin, P as PrePlugin, T as TemplateContent, p as default } from './index-Ccebqmdc.mjs'; |
| import { | ||
| PostPlugin, | ||
| PrePlugin, | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| export { | ||
| PostPlugin, | ||
| PrePlugin, | ||
| src_default as default | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rolldown; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/rolldown.ts | ||
| var rolldown_default = src_default.rolldown; | ||
| export { | ||
| rolldown_default as default | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rollup; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/rollup.ts | ||
| var rollup_default = src_default.rollup; | ||
| export { | ||
| rollup_default as default | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.rspack; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/rspack.ts | ||
| var rspack_default = src_default.rspack; | ||
| export { | ||
| rspack_default as default | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.vite; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/vite.ts | ||
| var vite_default = src_default.vite; | ||
| export { | ||
| vite_default as default | ||
| }; |
| import { p as plugin } from './index-Ccebqmdc.mjs'; | ||
| import '@vue-macros/common'; | ||
| import 'unplugin'; | ||
| declare const _default: typeof plugin.webpack; | ||
| export { _default as default }; |
| import { | ||
| src_default | ||
| } from "./chunk-AZIMYJ2L.mjs"; | ||
| import "./chunk-B3MW6NAR.mjs"; | ||
| // src/webpack.ts | ||
| var webpack_default = src_default.webpack; | ||
| export { | ||
| webpack_default as default | ||
| }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Yes
NaN35704
-2.76%40
-2.44%1
Infinity%+ Added
- Removed
Updated
Updated
Updated