+
- {{ lang === 'zh-CN' ? '稳定性:' : 'Stability: ' }}
-
- {{ lang === 'zh-CN' ? '稳定' : 'stable' }}
+ {{ t('Stability: ') }}
+
+ {{ t('official') }}
+
+
+ {{ t('stable') }}
- {{ lang === 'zh-CN' ? '实验性' : 'experimental' }}
+ {{ t('experimental') }}
- {{
- lang === 'zh-CN'
- ? '实验性功能,风险自负'
- : 'Experimental feature, use at your risk'
- }}
+ {{ t('Experimental feature, use at your risk') }}
diff --git a/docs/.vitepress/components/WarnBadge.vue b/docs/.vitepress/components/WarnBadge.vue
index a67efec56..a72c3dab6 100644
--- a/docs/.vitepress/components/WarnBadge.vue
+++ b/docs/.vitepress/components/WarnBadge.vue
@@ -1,5 +1,5 @@
-
+
⚠️
diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts
deleted file mode 100644
index fda0d83c5..000000000
--- a/docs/.vitepress/config.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { defineConfig } from 'vitepress'
-import { withPwa } from '@vite-pwa/vitepress'
-import { pwa } from './configs'
-import { en } from './locales/en'
-import { zhCN } from './locales/zh-cn'
-
-export default withPwa(
- defineConfig({
- lastUpdated: true,
- locales: {
- root: en,
- 'zh-CN': zhCN,
- },
- themeConfig: {
- search: {
- provider: 'local',
- options: {
- locales: {
- 'zh-CN': {
- translations: {
- button: {
- buttonText: '搜索文档',
- buttonAriaLabel: '搜索文档',
- },
- modal: {
- noResultsText: '无法找到相关结果',
- resetButtonTitle: '清除查询条件',
- footer: {
- selectText: '选择',
- navigateText: '切换',
- closeText: '关闭',
- },
- },
- },
- },
- },
- },
- },
- },
- pwa,
- })
-)
diff --git a/docs/.vitepress/config/index.ts b/docs/.vitepress/config/index.ts
new file mode 100644
index 000000000..10a9a7759
--- /dev/null
+++ b/docs/.vitepress/config/index.ts
@@ -0,0 +1,74 @@
+import process from 'node:process'
+import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
+import ts from 'typescript'
+import { defineConfig } from 'vitepress'
+import { groupIconMdPlugin } from 'vitepress-plugin-group-icons'
+import { docsLink } from '../../../macros'
+import { getLocaleConfig } from './theme'
+
+const enableTwoslash = !!process.env.TWOSLASH
+
+if (!enableTwoslash) {
+ console.warn('twoslash is not enabled, set TWOSLASH=1 to enable it')
+}
+
+export default defineConfig({
+ lastUpdated: true,
+ locales: {
+ root: getLocaleConfig('en'),
+ 'zh-CN': getLocaleConfig('zh-CN'),
+ },
+ themeConfig: {
+ search: {
+ provider: 'local',
+ options: {
+ locales: {
+ 'zh-CN': {
+ translations: {
+ button: {
+ buttonText: '搜索文档',
+ buttonAriaLabel: '搜索文档',
+ },
+ modal: {
+ noResultsText: '无法找到相关结果',
+ resetButtonTitle: '清除查询条件',
+ footer: {
+ selectText: '选择',
+ navigateText: '切换',
+ closeText: '关闭',
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ sitemap: {
+ hostname: docsLink,
+ },
+ markdown: {
+ languages: ['js', 'ts'],
+ config(md) {
+ md.use(groupIconMdPlugin)
+ },
+ codeTransformers: [
+ ...(enableTwoslash
+ ? [
+ transformerTwoslash({
+ twoslashOptions: {
+ compilerOptions: {
+ jsx: ts.JsxEmit.Preserve,
+ jsxFactory: 'vue',
+ types: ['vue-macros/macros-global', 'vue/jsx'],
+ },
+ vueCompilerOptions: {
+ plugins: ['@vue-macros/volar'],
+ },
+ },
+ }),
+ ]
+ : []),
+ ],
+ },
+})
diff --git a/docs/.vitepress/config/theme.ts b/docs/.vitepress/config/theme.ts
new file mode 100644
index 000000000..add286e7c
--- /dev/null
+++ b/docs/.vitepress/config/theme.ts
@@ -0,0 +1,346 @@
+import { docsLink, githubLink } from '../../../macros/repo'
+import { createTranslate } from '../i18n/utils'
+import type { DefaultTheme, HeadConfig, LocaleConfig } from 'vitepress'
+
+export function getLocaleConfig(lang: string) {
+ const t = createTranslate(lang)
+
+ const urlPrefix = lang && lang !== 'en' ? (`/${lang}` as const) : ''
+ const title = t('Vue Macros')
+ const description = t('Explore more macros and syntax sugar to Vue.')
+
+ const head: HeadConfig[] = [
+ ['meta', { property: 'og:title', content: title }],
+ ['meta', { property: 'og:description', content: description }],
+ ['meta', { property: 'og:image', content: `${docsLink}/og.png` }],
+ ['meta', { property: 'og:type', content: 'website' }],
+ ['meta', { property: 'og:url', content: docsLink }],
+ ['meta', { property: 'twitter:card', content: 'summary_large_image' }],
+ ['meta', { property: 'twitter:image', content: `${docsLink}/og.png` }],
+ ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }],
+ ['meta', { name: 'theme-color', content: '#914796' }],
+ [
+ 'script',
+ {
+ defer: '',
+ 'data-domain': 'vue-macros.dev',
+ src: 'https://evt.sxzz.dev/js/script.js',
+ },
+ ],
+ ]
+
+ const nav: DefaultTheme.NavItem[] = [
+ {
+ text: t('Guide'),
+ link: `${urlPrefix}/guide/getting-started`,
+ activeMatch: 'guide',
+ },
+ {
+ text: t('Macros'),
+ link: `${urlPrefix}/macros/`,
+ activeMatch: 'macros',
+ },
+ {
+ text: t('Features'),
+ link: `${urlPrefix}/features/hoist-static`,
+ activeMatch: 'features',
+ },
+ {
+ text: 'Volar',
+ link: `${urlPrefix}/volar/template-ref`,
+ activeMatch: 'volar',
+ },
+ {
+ text: t('Example'),
+ link: `${urlPrefix}/interactive/`,
+ activeMatch: 'interactive',
+ },
+ ]
+
+ const sidebar: DefaultTheme.SidebarItem[] = [
+ {
+ text: t('Guide'),
+ base: urlPrefix,
+ items: [
+ {
+ text: t('Getting Started'),
+ link: `/guide/getting-started`,
+ },
+ {
+ text: t('Bundler Integration'),
+ link: `/guide/bundler-integration`,
+ },
+ {
+ text: t('Nuxt Integration'),
+ link: `/guide/nuxt-integration`,
+ },
+ {
+ text: t('Astro Integration'),
+ link: `/guide/astro-integration`,
+ },
+ {
+ text: t('ESLint Integration'),
+ link: '/guide/eslint-integration',
+ },
+ {
+ text: t('Configurations'),
+ link: `/guide/configurations`,
+ },
+ {
+ text: t('Migration to v3'),
+ link: `/guide/migration-v3`,
+ },
+ {
+ text: t('Interactive Example'),
+ link: `/interactive`,
+ },
+ ],
+ },
+ {
+ text: t('Macros'),
+ base: `${urlPrefix}/macros`,
+ items: [
+ {
+ text: t('All Macros'),
+ link: `/`,
+ },
+
+ {
+ text: t('Official'),
+ items: [
+ {
+ text: 'defineOptions',
+ link: `/define-options`,
+ },
+ {
+ text: 'defineSlots',
+ link: `/define-slots`,
+ },
+ {
+ text: 'shortEmits',
+ link: `/short-emits`,
+ },
+ ],
+ },
+
+ {
+ text: t('Stable'),
+ items: [
+ {
+ text: 'defineModels',
+ link: `/define-models`,
+ },
+ {
+ text: 'defineProps',
+ link: `/define-props`,
+ },
+ {
+ text: 'definePropsRefs',
+ link: `/define-props-refs`,
+ },
+ {
+ text: 'defineRender',
+ link: `/define-render`,
+ },
+ {
+ text: 'shortVmodel',
+ link: `/short-vmodel`,
+ },
+ ],
+ },
+
+ {
+ text: t('Experimental'),
+ items: [
+ {
+ text: 'defineProp',
+ link: `/define-prop`,
+ },
+ {
+ text: 'defineEmit',
+ link: `/define-emit`,
+ },
+ {
+ text: 'setupComponent',
+ link: `/setup-component`,
+ },
+ {
+ text: 'setupSFC',
+ link: `/setup-sfc`,
+ },
+ {
+ text: 'chainCall',
+ link: `/chain-call`,
+ },
+ {
+ text: 'defineStyleX',
+ link: `/define-stylex`,
+ },
+ ],
+ },
+ ],
+ },
+ {
+ text: t('Features'),
+ base: `${urlPrefix}/features`,
+ items: [
+ {
+ text: t('Official'),
+ items: [
+ {
+ text: 'hoistStatic',
+ link: `/hoist-static`,
+ },
+ {
+ text: 'shortBind',
+ link: `/short-bind`,
+ },
+ ],
+ },
+
+ {
+ text: t('Stable'),
+ items: [
+ {
+ text: 'betterDefine',
+ link: `/better-define`,
+ },
+ {
+ text: 'reactivityTransform',
+ link: `/reactivity-transform`,
+ },
+ {
+ text: 'jsxDirective',
+ link: `/jsx-directive`,
+ },
+ ],
+ },
+
+ {
+ text: t('Experimental'),
+ items: [
+ {
+ text: 'namedTemplate',
+ link: `/named-template`,
+ },
+ {
+ text: 'exportProps',
+ link: `/export-props`,
+ },
+ {
+ text: 'exportExpose',
+ link: `/export-expose`,
+ },
+ {
+ text: 'exportRender',
+ link: `/export-render`,
+ },
+ {
+ text: 'booleanProp',
+ link: `/boolean-prop`,
+ },
+ {
+ text: 'scriptLang',
+ link: `/script-lang`,
+ },
+ ],
+ },
+ ],
+ },
+ {
+ text: 'Volar',
+ base: `${urlPrefix}/volar`,
+ items: [
+ {
+ text: t('Official'),
+ items: [
+ {
+ text: 'templateRef',
+ link: `/template-ref`,
+ },
+ ],
+ },
+ {
+ text: t('Stable'),
+ items: [
+ {
+ text: 'setupJsdoc',
+ link: `/setup-jsdoc`,
+ },
+ {
+ text: 'defineGeneric',
+ link: `/define-generic`,
+ },
+ ],
+ },
+ {
+ text: t('Experimental'),
+ items: [
+ {
+ text: 'scriptSFC',
+ link: `/script-sfc`,
+ },
+ {
+ text: 'jsxRef',
+ link: `/jsx-ref`,
+ },
+ ],
+ },
+ ],
+ },
+ ]
+
+ const themeConfig: DefaultTheme.Config = {
+ logo: '/favicon.svg',
+ nav,
+ sidebar,
+ socialLinks: [
+ { icon: 'discord', link: 'https://discord.com/invite/RbVHMsFVXU' },
+ { icon: 'github', link: githubLink },
+ { icon: 'bluesky', link: 'https://bsky.app/profile/vue-macros.dev' },
+ {
+ icon: {
+ svg: '
',
+ },
+ link: 'https://github.com/sponsors/vue-macros',
+ },
+ ],
+ footer: {
+ message: t('Made with ❤️'),
+ copyright:
+ 'MIT License © 2022-PRESENT
三咲智子 Kevin Deng & Vue Macros Contributors',
+ },
+ editLink: {
+ pattern: `${githubLink}/edit/main/docs/:path`,
+ text: t('Edit this page on GitHub'),
+ },
+ }
+
+ if (lang === 'zh-CN') {
+ Object.assign(themeConfig, {
+ outline: {
+ label: '页面导航',
+ },
+ lastUpdatedText: '最后更新于',
+ darkModeSwitchLabel: '外观',
+ sidebarMenuLabel: '目录',
+ returnToTopLabel: '返回顶部',
+ langMenuLabel: '选择语言',
+ docFooter: {
+ prev: '上一页',
+ next: '下一页',
+ },
+ } satisfies DefaultTheme.Config)
+ }
+
+ const localeConfig: LocaleConfig
[string] = {
+ label: t('English'),
+ lang: t('en'),
+ title,
+ description,
+ head,
+ themeConfig,
+ }
+
+ return localeConfig
+}
diff --git a/docs/.vitepress/configs/icons.ts b/docs/.vitepress/configs/icons.ts
deleted file mode 100644
index 1b5ef2f77..000000000
--- a/docs/.vitepress/configs/icons.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-export const icons = [
- {
- src: '/favicon.svg',
- type: 'image/svg+xml',
- sizes: 'any',
- purpose: 'any',
- },
- {
- src: '/icons/16.png',
- sizes: '16x16',
- },
- {
- src: '/icons/32.png',
- sizes: '32x32',
- },
- {
- src: '/icons/64.png',
- sizes: '64x64',
- },
- {
- src: '/icons/72.png',
- sizes: '72x72',
- },
- {
- src: '/icons/100.png',
- sizes: '100x100',
- },
- {
- src: '/icons/128.png',
- sizes: '128x128',
- },
- {
- src: '/icons/144.png',
- sizes: '144x144',
- },
- {
- src: '/icons/180.png',
- sizes: '180x180',
- },
- {
- src: '/icons/192.png',
- sizes: '192x192',
- },
- {
- src: '/icons/256.png',
- sizes: '256x256',
- },
- {
- src: '/icons/512.png',
- sizes: '512x512',
- },
- {
- src: '/icons/1024.png',
- sizes: '1024x1024',
- },
-]
diff --git a/docs/.vitepress/configs/index.ts b/docs/.vitepress/configs/index.ts
deleted file mode 100644
index 0f4125077..000000000
--- a/docs/.vitepress/configs/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './meta'
-export * from './pwa'
diff --git a/docs/.vitepress/configs/meta.ts b/docs/.vitepress/configs/meta.ts
deleted file mode 100644
index db651a0e4..000000000
--- a/docs/.vitepress/configs/meta.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const webLink = 'https://vue-macros.sxzz.moe'
diff --git a/docs/.vitepress/configs/pwa.ts b/docs/.vitepress/configs/pwa.ts
deleted file mode 100644
index b5e2b9c9e..000000000
--- a/docs/.vitepress/configs/pwa.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-import { type PwaOptions } from '@vite-pwa/vitepress'
-import { icons } from './icons'
-
-export const pwa: PwaOptions = {
- outDir: '.vitepress/dist',
- manifest: {
- name: 'Vue Macros',
- short_name: 'Vue Macros',
- description: 'Explore more macros and syntax sugar to Vue.',
- theme_color: '#914796',
- id: '/',
- icons,
- },
- devOptions: {
- enabled: false,
- },
- registerType: 'autoUpdate',
- workbox: {
- globPatterns: ['**/*.{css,js,html,svg,png,ico,txt,woff2}'],
- runtimeCaching: [
- {
- urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
- handler: 'CacheFirst',
- options: {
- cacheName: 'google-fonts-cache',
- expiration: {
- maxEntries: 10,
- maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
- },
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
- handler: 'CacheFirst',
- options: {
- cacheName: 'gstatic-fonts-cache',
- expiration: {
- maxEntries: 10,
- maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
- },
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- urlPattern: /^https:\/\/cdn\.jsdelivr\.net\/.*/i,
- handler: 'NetworkFirst',
- options: {
- cacheName: 'jsdelivr-images-cache',
- expiration: {
- maxAgeSeconds: 60 * 60 * 24 * 7, // <== 7 days
- },
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- {
- // For `https://contrib.rocks/image?repo=vue-macros/vue-macros`
- urlPattern: /^https:\/\/contrib.rocks\/.*/i,
- handler: 'NetworkFirst',
- options: {
- cacheName: 'contrib-rocks-images-cache',
- expiration: {
- maxAgeSeconds: 60 * 60 * 24 * 7, // <== 7 days
- },
- cacheableResponse: {
- statuses: [0, 200],
- },
- },
- },
- ],
- },
-}
diff --git a/docs/.vitepress/i18n/composable.ts b/docs/.vitepress/i18n/composable.ts
new file mode 100644
index 000000000..f1b50e649
--- /dev/null
+++ b/docs/.vitepress/i18n/composable.ts
@@ -0,0 +1,7 @@
+import { useData } from 'vitepress'
+import { t } from './utils'
+
+export function useTranslate(lang?: string) {
+ const { lang: vpLang } = useData()
+ return (key: string) => t(key, lang || vpLang.value)
+}
diff --git a/docs/.vitepress/i18n/translate-map.ts b/docs/.vitepress/i18n/translate-map.ts
new file mode 100644
index 000000000..eb5e945d9
--- /dev/null
+++ b/docs/.vitepress/i18n/translate-map.ts
@@ -0,0 +1,48 @@
+export const zhCN = {
+ Guide: '指南',
+ Macros: '宏',
+ Features: '功能',
+ Official: '官方',
+ Stable: '稳定',
+ Experimental: '实验',
+
+ 'Explore more macros and syntax sugar to Vue.':
+ '探索更多宏和语法糖到 Vue 中。',
+
+ 'Getting Started': '入门指南',
+ 'Bundler Integration': '构建工具集成',
+ 'Nuxt Integration': 'Nuxt 集成',
+ 'Astro Integration': 'Astro 集成',
+ 'ESLint Integration': 'ESLint 集成',
+ Configurations: '配置',
+ 'All Macros': '全部宏',
+
+ official: '官方',
+ stable: '稳定',
+ experimental: '实验性',
+ 'Stability: ': '稳定性: ',
+ 'Experimental feature, use at your risk': '实验性功能,风险自负',
+
+ Author: '作者',
+ 'Kevin Deng': '三咲智子 Kevin Deng',
+ 'Team member': '团队成员',
+ 'Logo Designer': 'Logo 设计者',
+ 'Sponsored by': '赞助者',
+ 'Thanks to all the contributors!': '感谢所有的贡献者!',
+
+ 'Made with ❤️': '用 ❤️ 发电',
+ 'Edit this page on GitHub': '在 GitHub 上编辑此页面',
+
+ English: '简体中文',
+ en: 'zh-CN',
+
+ 'Loading...': '加载中…',
+ Example: '示例',
+ 'Interactive Example': '交互式示例',
+
+ 'Migration to v3': '迁移至 v3',
+}
+
+export const translateMap: Record> = {
+ 'zh-CN': zhCN,
+}
diff --git a/docs/.vitepress/i18n/utils.ts b/docs/.vitepress/i18n/utils.ts
new file mode 100644
index 000000000..4b4381731
--- /dev/null
+++ b/docs/.vitepress/i18n/utils.ts
@@ -0,0 +1,9 @@
+import { translateMap } from './translate-map'
+
+export function t(key: string, lang: string) {
+ return translateMap[lang]?.[key] || key
+}
+
+export function createTranslate(lang: string) {
+ return (key: string) => t(key, lang)
+}
diff --git a/docs/.vitepress/locales/common.ts b/docs/.vitepress/locales/common.ts
deleted file mode 100644
index c5b91ea4e..000000000
--- a/docs/.vitepress/locales/common.ts
+++ /dev/null
@@ -1,185 +0,0 @@
-import { type DefaultTheme, type HeadConfig } from 'vitepress'
-import { webLink } from '.vitepress/configs/meta'
-
-export const themeConfig = {
- logo: '/favicon.svg',
- socialLinks: [{ icon: 'github', link: 'https://github.com/vue-macros/vue-macros' }],
-} satisfies DefaultTheme.Config
-
-export const head: HeadConfig[] = [
- ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }],
- ['meta', { property: 'og:type', content: 'website' }],
- ['meta', { property: 'og:url', content: webLink }],
- ['meta', { name: 'theme-color', content: '#914796' }],
- [
- 'script',
- {
- async: '',
- src: 'https://www.googletagmanager.com/gtag/js?id=G-29NKGSL23C',
- },
- ],
- [
- 'script',
- {},
- `window.dataLayer = window.dataLayer || [];
-function gtag(){dataLayer.push(arguments);}
-gtag('js', new Date());
-gtag('config', 'G-29NKGSL23C');`,
- ],
-]
-
-export const sidebar = (lang: string): DefaultTheme.SidebarItem[] => {
- const urlPrefix = lang ? `/${lang}` : ''
- return [
- {
- text: 'Guide',
- items: [
- {
- text: 'Getting Started',
- link: `${urlPrefix}/guide/getting-started`,
- },
- {
- text: 'Bundler Integration',
- link: `${urlPrefix}/guide/bundler-integration`,
- },
- {
- text: 'Nuxt Integration',
- link: `${urlPrefix}/guide/nuxt-integration`,
- },
- {
- text: 'Configurations',
- link: `${urlPrefix}/guide/configurations`,
- },
- ],
- },
- {
- text: 'Macros',
- items: [
- {
- text: 'All Macros',
- link: `${urlPrefix}/macros/`,
- },
-
- {
- text: 'Official',
- items: [
- {
- text: 'defineOptions',
- link: `${urlPrefix}/macros/define-options`,
- },
- {
- text: 'defineSlots',
- link: `${urlPrefix}/macros/define-slots`,
- },
- {
- text: 'shortEmits',
- link: `${urlPrefix}/macros/short-emits`,
- },
- ],
- },
-
- {
- text: 'Stable',
- items: [
- {
- text: 'defineModels',
- link: `${urlPrefix}/macros/define-models`,
- },
- {
- text: 'defineProps',
- link: `${urlPrefix}/macros/define-props`,
- },
- {
- text: 'definePropsRefs',
- link: `${urlPrefix}/macros/define-props-refs`,
- },
- {
- text: 'defineRender',
- link: `${urlPrefix}/macros/define-render`,
- },
- {
- text: 'shortVmodel',
- link: `${urlPrefix}/macros/short-vmodel`,
- },
- ],
- },
-
- {
- text: 'Experimental',
- items: [
- {
- text: 'defineProp',
- link: `${urlPrefix}/macros/define-prop`,
- },
- {
- text: 'defineEmit',
- link: `${urlPrefix}/macros/define-emit`,
- },
- {
- text: 'setupComponent',
- link: `${urlPrefix}/macros/setup-component`,
- },
- {
- text: 'setupSFC',
- link: `${urlPrefix}/macros/setup-sfc`,
- },
- {
- text: 'chainCall',
- link: `${urlPrefix}/macros/chain-call`,
- },
- ],
- },
- ],
- },
- {
- text: 'Features',
- items: [
- {
- text: 'Official',
- items: [
- {
- text: 'hoistStatic',
- link: `${urlPrefix}/features/hoist-static`,
- },
- ],
- },
-
- {
- text: 'Stable',
- items: [
- {
- text: 'betterDefine',
- link: `${urlPrefix}/features/better-define`,
- },
- {
- text: 'reactivityTransform',
- link: `${urlPrefix}/features/reactivity-transform`,
- },
- ],
- },
-
- {
- text: 'Experimental',
- items: [
- {
- text: 'namedTemplate',
- link: `${urlPrefix}/features/named-template`,
- },
- {
- text: 'exportProps',
- link: `${urlPrefix}/features/export-props`,
- },
- {
- text: 'exportExpose',
- link: `${urlPrefix}/features/export-expose`,
- },
- {
- text: 'jsxDirective',
- link: `${urlPrefix}/features/jsx-directive`,
- },
- ],
- },
- ],
- },
- ]
-}
diff --git a/docs/.vitepress/locales/en.ts b/docs/.vitepress/locales/en.ts
deleted file mode 100644
index 0a6f8bbec..000000000
--- a/docs/.vitepress/locales/en.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import {
- type DefaultTheme,
- type HeadConfig,
- type LocaleConfig,
-} from 'vitepress'
-import * as common from './common'
-
-export const title = 'Vue Macros'
-export const description = 'Explore more macros and syntax sugar to Vue.'
-
-export const nav: DefaultTheme.NavItem[] = [
- { text: 'Guide', link: '/guide/getting-started', activeMatch: 'guide' },
- { text: 'Macros', link: '/macros/', activeMatch: 'macros' },
- { text: 'Features', link: '/features/hoist-static', activeMatch: 'features' },
-]
-
-export const sidebar = common.sidebar('')
-
-export const themeConfig: DefaultTheme.Config = {
- ...common.themeConfig,
-
- footer: {
- message: 'Made with ❤️',
- copyright:
- 'MIT License © 2022-PRESENT 三咲智子 Kevin Deng',
- },
- editLink: {
- pattern: 'https://github.com/vue-macros/vue-macros/edit/main/docs/:path',
- text: 'Edit this page on GitHub',
- },
- nav,
- sidebar,
-}
-
-export const head: HeadConfig[] = [
- ['meta', { property: 'og:title', content: title }],
- ['meta', { property: 'og:description', content: description }],
- ...common.head,
-]
-
-export const en: LocaleConfig[string] = {
- label: 'English',
- lang: 'en',
- title,
- description,
- head,
- themeConfig,
-}
diff --git a/docs/.vitepress/locales/zh-cn.ts b/docs/.vitepress/locales/zh-cn.ts
deleted file mode 100644
index 5c764c87d..000000000
--- a/docs/.vitepress/locales/zh-cn.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import {
- type DefaultTheme,
- type HeadConfig,
- type LocaleConfig,
-} from 'vitepress'
-import * as common from './common'
-
-export const title = 'Vue Macros'
-export const description = '探索更多宏和语法糖到 Vue 中。'
-
-export const nav: DefaultTheme.NavItem[] = [
- { text: '指南', link: '/zh-CN/guide/getting-started', activeMatch: 'guide' },
- { text: '宏', link: '/zh-CN/macros/', activeMatch: 'macros' },
- {
- text: '特性',
- link: '/zh-CN/features/hoist-static',
- activeMatch: 'features',
- },
-]
-
-export const sidebar = common.sidebar('zh-CN')
-
-const sidebarTitle: string[] = ['指南', '宏', '特性']
-const sidebarItem: string[][] = [
- ['入门', '打包器集成', 'Nuxt 集成', '配置'],
- ['全部宏'],
- [''],
-]
-sidebar.forEach((bar, i) => {
- bar.text = sidebarTitle[i]
- bar.items!.forEach((item, j) => {
- if (sidebarItem[i][j]) item.text = sidebarItem[i][j]
- })
-})
-
-export const themeConfig: DefaultTheme.Config = {
- ...common.themeConfig,
-
- outline: {
- label: '页面导航',
- },
- lastUpdatedText: '最后更新于',
- footer: {
- message: '用 ❤️ 发电',
- copyright:
- 'MIT License © 2022-PRESENT 三咲智子',
- },
- editLink: {
- pattern: 'https://github.com/vue-macros/vue-macros/edit/main/docs/:path',
- text: '在 GitHub 上编辑此页面',
- },
- nav,
- sidebar,
- darkModeSwitchLabel: '外观',
- sidebarMenuLabel: '目录',
- returnToTopLabel: '返回顶部',
- docFooter: {
- prev: '上一页',
- next: '下一页',
- },
-}
-
-export const head: HeadConfig[] = [
- ['meta', { property: 'og:title', content: title }],
- ['meta', { property: 'og:description', content: description }],
- ...common.head,
-]
-
-export const zhCN: LocaleConfig[string] = {
- label: '简体中文',
- lang: 'zh-CN',
- title,
- description,
- head,
- themeConfig,
-}
diff --git a/docs/.vitepress/theme/Layout.vue b/docs/.vitepress/theme/Layout.vue
new file mode 100644
index 000000000..e262a00ef
--- /dev/null
+++ b/docs/.vitepress/theme/Layout.vue
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts
index 353aa2aea..2a35e0165 100644
--- a/docs/.vitepress/theme/index.ts
+++ b/docs/.vitepress/theme/index.ts
@@ -1,21 +1,26 @@
-import { h } from 'vue'
-import { type EnhanceAppContext } from 'vitepress'
+import { NolebaseGitChangelogPlugin } from '@nolebase/vitepress-plugin-git-changelog/client'
+import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import Theme from 'vitepress/theme'
-import HomePage from '../components/HomePage.vue'
-import WarnBadge from '../components/WarnBadge.vue'
+import PackageVersion from '../components/PackageVersion.vue'
import StabilityLevel from '../components/StabilityLevel.vue'
-import 'uno.css'
+import WarnBadge from '../components/WarnBadge.vue'
+import Layout from './Layout.vue'
+import type { EnhanceAppContext } from 'vitepress'
import './style.css'
+import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
+import '@shikijs/vitepress-twoslash/style.css'
+import 'uno.css'
+import 'virtual:group-icons.css'
+
export default {
...Theme,
- Layout() {
- return h(Theme.Layout, null, {
- 'home-features-after': () => h(HomePage),
- })
- },
+ Layout,
enhanceApp({ app }: EnhanceAppContext) {
app.component('WarnBadge', WarnBadge)
app.component('StabilityLevel', StabilityLevel)
+ app.component('PackageVersion', PackageVersion)
+ app.use(NolebaseGitChangelogPlugin)
+ app.use(TwoslashFloatingVue)
},
}
diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css
index b44c55a24..940dd44a3 100644
--- a/docs/.vitepress/theme/style.css
+++ b/docs/.vitepress/theme/style.css
@@ -21,14 +21,12 @@
:root {
--vp-button-brand-border: var(--vp-c-brand-light);
- --vp-button-brand-text: var(--vp-c-text-dark-1);
--vp-button-brand-bg: var(--vp-c-brand);
--vp-button-brand-hover-border: var(--vp-c-brand-light);
- --vp-button-brand-hover-text: var(--vp-c-text-dark-1);
--vp-button-brand-hover-bg: var(--vp-c-brand-light);
--vp-button-brand-active-border: var(--vp-c-brand-light);
- --vp-button-brand-active-text: var(--vp-c-text-dark-1);
--vp-button-brand-active-bg: var(--vp-button-brand-bg);
+ --vp-button-brand-text: #eee;
}
/**
diff --git a/docs/assets/rsbuild.svg b/docs/assets/rsbuild.svg
new file mode 100644
index 000000000..ffbc91f31
--- /dev/null
+++ b/docs/assets/rsbuild.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/assets/rspack.svg b/docs/assets/rspack.svg
new file mode 100644
index 000000000..8ebaa61c8
--- /dev/null
+++ b/docs/assets/rspack.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/features/better-define.md b/docs/features/better-define.md
index 6f0a4f0cf..2e864e345 100644
--- a/docs/features/better-define.md
+++ b/docs/features/better-define.md
@@ -1,4 +1,4 @@
-# betterDefine
+# betterDefine
@@ -17,22 +17,27 @@ With enabling `betterDefine`, imported types are supported in `
```
-```ts [types.ts]
-export interface BaseProps {
- title: string
-}
-```
+<<< ./better-define.md#basic{ts} [types.ts]
:::
diff --git a/docs/features/boolean-prop.md b/docs/features/boolean-prop.md
new file mode 100644
index 000000000..f540d1ab9
--- /dev/null
+++ b/docs/features/boolean-prop.md
@@ -0,0 +1,73 @@
+# booleanProp
+
+
+
+Convert `` to ``.
+
+Convert `` to ``.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Vue 3 | :white_check_mark: |
+| Nuxt 3 | :white_check_mark: |
+| Vue 2 | :x: |
+| Volar Plugin | :white_check_mark: |
+
+## Options
+
+```ts
+interface Options {
+ /**
+ * @default '!'
+ */
+ negativePrefix?: string
+}
+```
+
+## Usage
+
+
+```vue twoslash
+
+
+
+
+ // ^?
+
+```
+
+
+```vue twoslash
+
+```
+
+## Volar Configuration
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "booleanProp": true,
+ },
+ },
+}
+```
diff --git a/docs/features/export-expose.md b/docs/features/export-expose.md
index a291e0cd6..8dad197a5 100644
--- a/docs/features/export-expose.md
+++ b/docs/features/export-expose.md
@@ -1,4 +1,4 @@
-# exportExpose
+# exportExpose
@@ -8,8 +8,8 @@ Transform export statement as `defineExpose` params in Vue SFC `script-setup`.
| :----------: | :----------------: |
| Vue 3 | :white_check_mark: |
| Nuxt 3 | ? |
-| Vue 2 | ? |
-| Volar Plugin | :x: |
+| Vue 2 | :white_check_mark: |
+| Volar Plugin | :white_check_mark: |
## Usage
@@ -23,12 +23,13 @@ Support these syntaxes:
### 1. local variable/function/class
-```vue
+```vue twoslash
```
::: details Compiled Code
-```vue
+```vue twoslash
```
+<<< ./export-expose.md#export-file{ts} [types.ts]
+
+:::
+
::: details Compiled Code
-```vue
+```vue twoslash
```
+```ts [types.ts]
+export const foo = 'foo'
+```
+
+:::
+
::: details Compiled Code
-```vue
+```vue twoslash
```
+
+## Volar Configuration
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "exportProps": true,
+ },
+ },
+}
+```
diff --git a/docs/features/export-render.md b/docs/features/export-render.md
new file mode 100644
index 000000000..faa8ce294
--- /dev/null
+++ b/docs/features/export-render.md
@@ -0,0 +1,43 @@
+# exportRender
+
+
+
+Transform the default export statement, in `
+```
+
+## Volar Configuration
+
+```jsonc {3,7} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "exportRender": true,
+ },
+ },
+}
+```
diff --git a/docs/features/hoist-static.md b/docs/features/hoist-static.md
index 3258ed9df..7ba38acd5 100644
--- a/docs/features/hoist-static.md
+++ b/docs/features/hoist-static.md
@@ -1,4 +1,4 @@
-# hoistStatic
+# hoistStatic
@@ -14,7 +14,7 @@ For Vue >= 3.3, this feature will be turned off by default.
## Basic Usage
-```vue
+```vue twoslash
+```
+
+### `v-for`
+
+```vue twoslash
+
+```
+
+### `v-slot`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-directive.md#v-slot{tsx} [Child.tsx]
+
+:::
+
+### `v-on`
+
+::: warning
+
+`v-on` only supports binding to an object of event / listener pairs without an argument.
+
+:::
+
+```tsx
+
+```
+
+## Dynamic Arguments
+
+It is also possible to use a variable in a directive argument by wrapping it with a pair of `$`:
+
+`v-model`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
```
+
+<<< ./jsx-directive.md#v-model{tsx} [Comp.tsx]
+
+:::
+
+`v-slot`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-directive.md#v-slot-dynamic{tsx} [Comp.tsx]
+
+:::
+
+## Modifiers
+
+Modifiers are special postfixes denoted by a `_`, which indicate that a directive should be bound in some special way.
+
+```tsx
+
+```
+
+## Volar Configuration
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/features/named-template.md b/docs/features/named-template.md
index b3f49beb4..9d43cb365 100644
--- a/docs/features/named-template.md
+++ b/docs/features/named-template.md
@@ -1,4 +1,4 @@
-# namedTemplate
+# namedTemplate
diff --git a/docs/features/reactivity-transform.md b/docs/features/reactivity-transform.md
index 64379825f..a125ba0f1 100644
--- a/docs/features/reactivity-transform.md
+++ b/docs/features/reactivity-transform.md
@@ -1,4 +1,4 @@
-# Reactivity Transform
+# Reactivity Transform
@@ -72,8 +72,7 @@ module.exports = {
### TypeScript Support
-```json
-// tsconfig.json
+```json [tsconfig.json]
{
"compilerOptions": {
// ...
@@ -88,7 +87,7 @@ Ever since the introduction of the Composition API, one of the primary unresolve
Reactivity Transform is a compile-time transform that allows us to write code like this:
-```vue
+```vue twoslash
```
The above will be compiled into the following runtime declaration equivalent:
-```js
-export default {
+```ts twoslash
+import { defineComponent, watchEffect } from 'vue'
+
+export default defineComponent({
props: {
msg: { type: String, required: true },
count: { type: Number, default: 1 },
@@ -227,7 +243,7 @@ export default {
console.log(props.msg, props.count, props.foo)
})
},
-}
+})
```
## Retaining Reactivity Across Function Boundaries {#retaining-reactivity-across-function-boundaries}
@@ -238,7 +254,9 @@ While reactive variables relieve us from having to use `.value` everywhere, it c
Given a function that expects a ref as an argument, e.g.:
-```ts
+```ts twoslash
+import { watch, type Ref } from 'vue'
+
function trackChange(x: Ref) {
watch(x, (x) => {
console.log('x changed!')
@@ -246,6 +264,7 @@ function trackChange(x: Ref) {
}
const count = $ref(0)
+// @errors: 2345
trackChange(count) // doesn't work!
```
@@ -279,7 +298,7 @@ As we can see, `$$()` is a macro that serves as an **escape hint**: reactive var
Reactivity can also be lost if reactive variables are used directly in a returned expression:
-```ts
+```ts twoslash
function useMouse() {
const x = $ref(0)
const y = $ref(0)
@@ -307,7 +326,7 @@ In order to retain reactivity, we should be returning the actual refs, not the c
Again, we can use `$$()` to fix this. In this case, `$$()` can be used directly on the returned object - any reference to reactive variables inside the `$$()` call will retain the reference to their underlying refs:
-```ts
+```ts twoslash
function useMouse() {
const x = $ref(0)
const y = $ref(0)
@@ -326,21 +345,36 @@ function useMouse() {
`$$()` works on destructured props since they are reactive variables as well. The compiler will convert it with `toRef` for efficiency:
-```ts
+```vue twoslash
+
```
compiles to:
-```js
-export default {
+```ts twoslash
+import { defineComponent, toRef, type Ref } from 'vue'
+function passAsRef(count: Ref) {
+ return count
+}
+// ---cut---
+export default defineComponent({
+ props: {
+ count: { type: Number, required: true },
+ },
setup(props) {
const __props_count = toRef(props, 'count')
passAsRef(__props_count)
},
-}
+})
```
## TypeScript Integration {#typescript-integration}
@@ -351,11 +385,11 @@ This also means the macros can work in any files where valid JS / TS are allowed
Since the macros are available globally, their types need to be explicitly referenced (e.g. in a `env.d.ts` file):
-```ts
-///
+```ts [env.d.ts]
+///
// or for standalone version:
///
```
-When explicitly importing the macros from `unplugin-vue-macros/macros` or `@vue-macros/reactivity-transform/macros-global`, the type will work without declaring the globals.
+When explicitly importing the macros from `vue-macros/macros` or `@vue-macros/reactivity-transform/macros-global`, the type will work without declaring the globals.
diff --git a/docs/features/script-lang.md b/docs/features/script-lang.md
new file mode 100644
index 000000000..d9fc842d2
--- /dev/null
+++ b/docs/features/script-lang.md
@@ -0,0 +1,52 @@
+# scriptLang
+
+
+
+Set the default language for `
+```
+
+## Volar Configuration
+
+```jsonc {3,5-7} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "scriptLang": {
+ "defaultLang": "ts",
+ },
+ },
+ },
+}
+```
diff --git a/docs/features/short-bind.md b/docs/features/short-bind.md
new file mode 100644
index 000000000..b1995c68b
--- /dev/null
+++ b/docs/features/short-bind.md
@@ -0,0 +1,54 @@
+# shortBind
+
+
+
+`:value` -> `:value="value"`
+
+Same-name shorthand for binding prop. If the attribute has the same name with the JavaScript value being bound, the syntax can be further shortened to omit the attribute value.
+
+For Vue >= 3.4, this feature will be turned off by default.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Vue 3 | :white_check_mark: |
+| Nuxt 3 | :white_check_mark: |
+| Vue 2 | :x: |
+| Volar Plugin | :white_check_mark: |
+
+## Usage
+
+### Basic Usage
+
+```vue twoslash
+
+
+
+
+
+
+```
+
+### With `shortVmodel`
+
+```vue
+
+
+
+
+
+
+
+
+```
+
+## Volar Configuration
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/guide/astro-integration.md b/docs/guide/astro-integration.md
new file mode 100644
index 000000000..c4a3651b9
--- /dev/null
+++ b/docs/guide/astro-integration.md
@@ -0,0 +1,46 @@
+# Astro Integration
+
+### Installation
+
+::: code-group
+
+```bash [npm]
+npm i -D @vue-macros/astro
+```
+
+```bash [yarn]
+yarn add -D @vue-macros/astro
+```
+
+```bash [pnpm]
+pnpm add -D @vue-macros/astro
+```
+
+:::
+
+## Configuration
+
+```ts [astro.config.mjs]
+import Vue from '@astrojs/vue'
+import Macros from '@vue-macros/astro'
+import { defineConfig } from 'astro/config'
+
+export default defineConfig({
+ integrations: [
+ Vue(),
+ Macros({
+ // overrides config options
+ }),
+ ],
+})
+```
+
+## TypeScript Support & Volar Support
+
+See the corresponding chapter on [Bundler Integration](./bundler-integration.md#typescript-support)
+
+---
+
+:tada: Congratulations! That's all.
+
+To learn more about the macros, please visit [All Macros](/macros/) :laughing:.
diff --git a/docs/guide/bundler-integration.md b/docs/guide/bundler-integration.md
index c023b0678..dd5138a20 100644
--- a/docs/guide/bundler-integration.md
+++ b/docs/guide/bundler-integration.md
@@ -1,30 +1,37 @@
-# Bundler Integration
+# Bundler Integration
-### Installation
+## Installation
+
+::: tip
+
+Vite and Rollup are fully supported, while other bundlers have limited support.
+
+:::
::: code-group
```bash [npm]
-npm i -D unplugin-vue-macros
+npm i -D vue-macros
```
```bash [yarn]
-yarn add -D unplugin-vue-macros
+yarn add -D vue-macros
```
```bash [pnpm]
-pnpm add -D unplugin-vue-macros
+pnpm add -D vue-macros
```
:::
::: code-group
-```ts [Vite (first-class support)]
+```ts [Vite]
// vite.config.ts
-import VueMacros from 'unplugin-vue-macros/vite'
import Vue from '@vitejs/plugin-vue'
+import VueMacros from 'vue-macros/vite'
// import VueJsx from '@vitejs/plugin-vue-jsx'
+// import VueRouter from 'unplugin-vue-router/vite'
export default defineConfig({
plugins: [
@@ -32,16 +39,21 @@ export default defineConfig({
plugins: {
vue: Vue(),
// vueJsx: VueJsx(), // if needed
+ // vueRouter: VueRouter({ // if needed
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // overrides plugin options
}),
],
})
```
-```ts [Rollup (first-class support)]
-// rollup.config.js
+```ts [Rollup]
+// rollup.config.js (Requires Rollup 3+)
import Vue from 'unplugin-vue/rollup'
-import VueMacros from 'unplugin-vue-macros/rollup'
+import VueMacros from 'vue-macros/rollup'
+// import VueRouter from 'unplugin-vue-router/rollup'
export default {
plugins: [
@@ -49,7 +61,11 @@ export default {
plugins: {
vue: Vue(),
// vueJsx: VueJsx(), // if needed
+ // vueRouter: VueRouter({ // if needed
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // overrides plugin options
}),
],
}
@@ -58,96 +74,142 @@ export default {
```js [esbuild]
// esbuild.config.js
import { build } from 'esbuild'
+// import VueRouter from 'unplugin-vue-router/esbuild'
build({
plugins: [
- require('unplugin-vue-macros/esbuild')({
+ require('vue-macros/esbuild')({
plugins: {
vue: require('unplugin-vue/esbuild')(),
// vueJsx: VueJsx(), // if needed
+ // vueRouter: VueRouter({ // if needed
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // overrides plugin options
}),
],
})
```
```js [Webpack]
-// webpack.config.js
+// webpack.config.js (Requires Webpack 5+)
module.exports = {
/* ... */
- plugins: [require('unplugin-vue-macros/webpack')({})],
+ plugins: [
+ require('vue-macros/webpack')({
+ // overrides plugin options
+ }),
+ ],
+}
+```
+
+```js [Rspack]
+// rspack.config.js
+module.exports = {
+ /* ... */
+ plugins: [
+ require('vue-macros/rspack')({
+ // overrides plugin options
+ }),
+ ],
+}
+```
+
+```js [Rsbuild]
+// rsbuild.config.js
+module.exports = {
+ // ...
+ tools: {
+ rspack: {
+ plugins: [
+ require('vue-macros/rspack')({
+ // overrides plugin options
+ }),
+ ],
+ },
+ },
}
```
```js [Vue CLI]
-// vue.config.js
+// vue.config.js (Requires Vue CLI 5+)
const { defineConfig } = require('@vue/cli-service')
-const VueMacros = require('unplugin-vue-macros/webpack')
+const VueMacros = require('vue-macros/webpack')
module.exports = defineConfig({
// ...
// ⚠️ IMPORTANT
parallel: false,
configureWebpack: {
- plugins: [VueMacros({})],
+ plugins: [
+ VueMacros({
+ // overrides plugin options
+ }),
+ ],
},
})
```
:::
-## TypeScript Support
+## Configuration
-::: code-group
+See the [Configurations](./configurations.md) for more details.
-```json {0} [Vue 3]
-// tsconfig.json
-{
- "compilerOptions": {
- // ...
- "types": ["unplugin-vue-macros/macros-global" /* ... */]
- }
-}
+```ts twoslash [vue-macros.config.ts]
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
+ // options
+})
```
-```json {0} [Vue 2]
+## TypeScript Support
+
+```json {0}
// tsconfig.json
{
"compilerOptions": {
// ...
- "types": ["unplugin-vue-macros/vue2-macros-global" /* ... */]
+ "types": ["vue-macros/macros-global" /* ... */]
}
}
```
-:::
-
## Volar Support
For detailed configuration, please refer to the description of the specific macro.
-```bash
-npm i -D @vue-macros/volar
-```
-
-```json
-// tsconfig.json
+```jsonc [tsconfig.json]
{
"vueCompilerOptions": {
- "plugins": [
- "@vue-macros/volar/define-options",
- "@vue-macros/volar/define-models",
- "@vue-macros/volar/define-props",
- "@vue-macros/volar/define-props-refs",
- "@vue-macros/volar/short-vmodel",
- "@vue-macros/volar/define-slots",
- "@vue-macros/volar/export-props"
- ]
- // ...
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
-:tada: Congratulations! You have successfully set up `unplugin-vue-macros`.
+### Scoped Plugins
+
+`exportExpose`, `exportProps`, and `exportRender` plugins cannot be used
+at the same time unless providing a scope.
+
+```ts twoslash [vue-macros.config.ts]
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
+ exportExpose: {
+ include: ['**/export-expose/**'],
+ },
+ exportProps: {
+ include: ['**/export-props/**'],
+ },
+ exportRender: {
+ include: ['**/export-render/**'],
+ },
+})
+```
+
+---
+
+:tada: Congratulations! You have successfully set up Vue Macros.
To learn more about the macros, please visit [All Macros](/macros/) :laughing:.
diff --git a/docs/guide/configurations.md b/docs/guide/configurations.md
index 7727aee8a..5041e2495 100644
--- a/docs/guide/configurations.md
+++ b/docs/guide/configurations.md
@@ -4,18 +4,28 @@
All features are enabled by default except the following.
-- `defineOptions` (Vue >= 3.3)
-- `defineSlots` (Vue >= 3.3)
-- `hoistStatic` (Vue >= 3.3)
-- `shortEmits` (Vue >= 3.3)
+#### Disabled by Default
+
- `exportExpose`
- `exportProps`
+- `exportRender`
- `setupSFC`
+- `booleanProp`
+- `shortBind`
+- `defineStyleX`
+
+#### Disabled by Default when Vue >= 3.3
+
+- `defineOptions`
+- `defineSlots`
+- `hoistStatic`
+- `shortEmits`
-You can disable them by setting the option to `false`.
+You can re-enable them by setting the option to `true`.
-```ts
-VueMacros({
+```ts twoslash [vue-macros.config.(ts,js,json)]
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
root: '/your-project-path',
/**
@@ -25,21 +35,14 @@ VueMacros({
*/
version: 3,
- plugins: {
- vue: Vue(),
- vueJsx: VueJsx(),
- },
-
- /** Defaults to true */
+ /** Defaults to true */
defineModels: {
- /**
- * Unified mode, only works for Vue 2
- *
- * Converts `modelValue` to `value`
- */
- unified: true,
+ // ...
},
+ // Enable features
+ defineOptions: true,
+
// Disable features
hoistStatic: false,
@@ -47,4 +50,4 @@ VueMacros({
})
```
-See the features page for options for each feature.
+Refer to the macros and features page for available options.
diff --git a/docs/guide/eslint-integration.md b/docs/guide/eslint-integration.md
new file mode 100644
index 000000000..2748e7ded
--- /dev/null
+++ b/docs/guide/eslint-integration.md
@@ -0,0 +1,42 @@
+# ESLint Integration
+
+## Installation
+
+::: code-group
+
+```bash [pnpm]
+pnpm add -D @vue-macros/eslint-config
+```
+
+```bash [yarn]
+yarn add -D @vue-macros/eslint-config
+```
+
+```bash [npm]
+npm i -D @vue-macros/eslint-config
+```
+
+:::
+
+## Configuration
+
+### Flat Configuration
+
+```js [eslint.config.js]
+import vueMacros from '@vue-macros/eslint-config/flat'
+export default [
+ vueMacros,
+ // ...your other configurations
+]
+```
+
+### Legacy Configuration
+
+```jsonc [.eslintrc]
+{
+ "extends": [
+ "@vue-macros/eslint-config",
+ // ...your other configurations
+ ],
+}
+```
diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md
index 1e101923d..17c2c65e2 100644
--- a/docs/guide/getting-started.md
+++ b/docs/guide/getting-started.md
@@ -1,30 +1,86 @@
+
+
# Getting Started
-Vue Macros is a library that implements proposals or ideas that have not been officially implemented by Vue. That means it will explore and extend more features and syntax sugar to Vue.
+Vue Macros is a library that implements unofficial proposals and ideas for Vue,
+exploring and extending its features and syntax.
We assume you are already familiar with the basic usages of Vue before you continue.
## Requirements
-- Node.js 16.14.0 or higher.
-- Vue >= 2.7 or Vue >= 3.0.
- - Some features need Vue >= 3.2.25.
-- VSCode with the **latest** [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) extension.
- - ❌ WebStorm is not supported.
+- Node.js `>= v20.18.0`.
+- Vue `>= v2.7` or Vue `>= v3.0`.
+ - Some features need Vue `>= v3.2.25`.
+- VSCode extension [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) and `vue-tsc` are v{{ version }}
+ - Vue Macros will continue to adapt to the latest version as soon as possible, older versions may not be supported.
+
+::: warning
+WebStorm is not supported.
+:::
+
+## Creating a Vue Macros Project
+
+### Installation
+
+::: code-group
+
+```bash [npm]
+npm i -g @vue-macros/cli
+```
+
+```bash [yarn]
+yarn global add @vue-macros/cli
+```
+
+```bash [pnpm]
+pnpm add -g @vue-macros/cli
+```
+
+:::
+
+This command will install [@vue-macros/cli](https://github.com/vue-macros/vue-macros-cli), the official Vue Macros scaffolding tool.
+
+### Initialization
+
+::: code-group
+
+```bash [npm]
+npm create vite@latest my-vue-macros -- --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+```bash [yarn]
+yarn create vite my-vue-macros --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+```bash [pnpm]
+pnpm create vite my-vue-macros --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+You will be presented with prompts for several optional experimental features.
+
+:::
-## Demos
+## Templates
-- [Vite + Vue 3](https://github.com/vue-macros/vite)
-- [Vite + Vue 2](https://github.com/vue-macros/vue-macros/tree/main/playground/vue2)
-- [Nuxt 3 + Vue 3](https://github.com/vue-macros/nuxt)
-- [Vue CLI + Vue 2](https://github.com/vue-macros/vue2-vue-cli)
+- [Vite](https://github.com/vue-macros/vite)
+- [Nuxt](https://github.com/vue-macros/nuxt)
+- [Rsbuild](https://github.com/vue-macros/vue3-rsbuild)
-🌟 More demos are welcome!
+🌟 More templates are welcome!
## Nuxt Integration
-If you're using [Nuxt 3](https://nuxt.com/), read the [Nuxt Integration](./nuxt-integration.md).
+If you're using [Nuxt](https://nuxt.com/), read the [Nuxt Integration](./nuxt-integration.md).
## Bundler Integrations
-If you're using [Vite](https://vitejs.dev/), [Rollup](https://rollupjs.org/), [esbuild](https://esbuild.github.io/), or [Webpack](https://webpack.js.org/), read the [Bundler Integration](./bundler-integration.md).
+If you're using [Vite](https://vitejs.dev/), [Rollup](https://rollupjs.org/), [esbuild](https://esbuild.github.io/), [Webpack](https://webpack.js.org/), or [Rspack](https://www.rspack.dev/), read the [Bundler Integration](./bundler-integration.md).
diff --git a/docs/guide/migration-v3.md b/docs/guide/migration-v3.md
new file mode 100644
index 000000000..e97c4bf9f
--- /dev/null
+++ b/docs/guide/migration-v3.md
@@ -0,0 +1,62 @@
+# Migration from v2 to v3
+
+## Unified Version Management
+
+Initially, we used [`changesets`](https://github.com/changesets/changesets) to
+manage the versions of all packages in the monorepo. However, after two years of experimentation,
+we decided to adopt a single-version strategy in v3,
+where all sub-packages share the same version number, similar to Vue and Babel.
+This decision stemmed from our observation that when a sub-package underwent a major change or minor update,
+the version number of the main package did not adequately reflect these changes.
+
+For example, when `@vue-macros/define-prop` introduced a breaking change,
+how should `unplugin-vue-macros` release a new version?
+Should it be a minor or a patch release? When users updated `unplugin-vue-macros`,
+they couldn’t easily determine whether the update was due to changes in `@vue-macros/define-prop`.
+
+Therefore, after Anthony proposed [Epoch Semantic Versioning](https://antfu.me/posts/epoch-semver),
+we decided to adopt a more frequent major version update strategy,
+with all packages sharing the same version number and maintaining a single unified changelog.
+
+## Main Package Rename
+
+We have renamed the main package from `unplugin-vue-macros` to **`vue-macros`**.
+After the official release of v3, `unplugin-vue-macros` will be marked as deprecated.
+
+As a result, you will need to update your `package.json` and the import statements for Vue Macros:
+
+```diff
+ // package.json
+ {
+ "devDependencies": {
+- "unplugin-vue-macros": "^2.14.5"
++ "vue-macros": "^3.0.0"
+ }
+ }
+```
+
+```diff
+- import { $ref } from 'unplugin-vue-macros/macros'
++ import { $ref } from 'vue-macros/macros'
+
+- import VueMacros from 'unplugin-vue-macros/vite'
++ import VueMacros from 'vue-macros/vite'
+```
+
+## Dropping Vue 2 Support
+
+Vue 2 reached its end of life (EOL) at the end of 2023, so we have decided to drop support for Vue 2 in v3.
+If you are still using Vue 2, we recommend continuing with v2 or
+considering our [paid support plan](https://github.com/vue-macros/vue-macros/issues/373).
+
+## Node.js Compatibility Changes
+
+In v3, we have dropped support for Node.js versions below 20.18.
+This means the minimum Node.js version requirement for v3 is `20.18.0`.
+Additionally, we have removed CommonJS (CJS) outputs and now only provide ECMAScript modules (ESM).
+
+## Dropping Webpack 4 Support
+
+Since Webpack 4 cannot run in Node.js 18 or later environments,
+we have also dropped support for Webpack 4 and Vue CLI 4.
+We recommend upgrading to modern build tools like Vite or Rspack.
diff --git a/docs/guide/nuxt-integration.md b/docs/guide/nuxt-integration.md
index 4e60bf0c3..643546afa 100644
--- a/docs/guide/nuxt-integration.md
+++ b/docs/guide/nuxt-integration.md
@@ -1,4 +1,4 @@
-# Nuxt Integration
+# Nuxt Integration
### Installation
@@ -20,19 +20,20 @@ pnpm add -D @vue-macros/nuxt
## Configuration
-```ts
-// nuxt.config.ts
+```ts [nuxt.config.ts]
export default {
modules: [
'@vue-macros/nuxt',
// ...
],
macros: {
- // configure plugin options, if needed
+ // overrides config options
},
}
```
+---
+
:tada: Congratulations! That's all.
To learn more about the macros, please visit [All Macros](/macros/) :laughing:.
diff --git a/docs/index.md b/docs/index.md
index 36608282e..c1c91e0a3 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -26,6 +26,6 @@ features:
title: Type Safe
details: Full TypeScript and Volar support.
- icon: ⚡️
- title: Multiple bundlers are supported
- details: Supports Vite, Nuxt, Webpack, Vue CLI, Rollup 3, esbuild and more, powered by unplugin.
+ title: Most bundlers are supported
+ details: Supports almost all bundlers powered by unplugin.
---
diff --git a/docs/interactive/InteractiveDemo.vue b/docs/interactive/InteractiveDemo.vue
new file mode 100644
index 000000000..d430fb801
--- /dev/null
+++ b/docs/interactive/InteractiveDemo.vue
@@ -0,0 +1,172 @@
+
+
+
+
+
{{ t('Interactive Example') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/interactive/InteractiveWrapper.vue b/docs/interactive/InteractiveWrapper.vue
new file mode 100644
index 000000000..2300d24ec
--- /dev/null
+++ b/docs/interactive/InteractiveWrapper.vue
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
{{ t('Loading...') }}
+
+
+
+
diff --git a/docs/interactive/index.md b/docs/interactive/index.md
new file mode 100644
index 000000000..e538ada84
--- /dev/null
+++ b/docs/interactive/index.md
@@ -0,0 +1,10 @@
+---
+layout: page
+gitChangelog: false
+---
+
+
+
+
diff --git a/docs/interactive/logic.ts b/docs/interactive/logic.ts
new file mode 100644
index 000000000..fa890c956
--- /dev/null
+++ b/docs/interactive/logic.ts
@@ -0,0 +1,146 @@
+type OptionsTemplate = Record<
+ string,
+ {
+ values: readonly string[]
+ default: string
+ label: string
+ }
+>
+
+export const options = {
+ defineComponents: {
+ values: ['Vue SFC', 'setupSFC', 'setupComponent'],
+ default: 'Vue SFC',
+ label: 'Define Component',
+ },
+ defineRender: {
+ values: ['', 'defineRender', 'exportRender'],
+ default: 'defineRender',
+ label: 'Define Render',
+ },
+ defineProps: {
+ values: [
+ 'defineProps',
+ 'prop destructure',
+ 'defineProp',
+ 'definePropsRefs',
+ 'chainCall',
+ 'exportProps',
+ ],
+ default: 'defineProps',
+ label: 'Define Props',
+ },
+ defineEmits: {
+ values: ['defineEmits', 'defineEmit'],
+ default: 'defineEmits',
+ label: 'Define Emits',
+ },
+} as const satisfies OptionsTemplate
+
+export type Options = typeof options
+export type OptionsKey = keyof Options
+export type DefineComponents = Options['defineComponents']['values'][number]
+export type DefineProps = Options['defineProps']['values'][number]
+export type DefineEmits = Options['defineEmits']['values'][number]
+export type DefineRender = Options['defineRender']['values'][number]
+
+const propsType = `{\n foo?: string, bar?: number }`
+export const processDefineProps: Record = {
+ defineProps: `
+ const props = withDefaults(
+ defineProps<${propsType}>(),
+ { bar: 0 }
+ )`,
+
+ 'prop destructure': `\nconst { foo, bar = 0 } = defineProps<${propsType}>()`,
+
+ definePropsRefs: `
+ const { foo, bar } = withDefaults(
+ definePropsRefs<${propsType}>(),
+ { bar: 0 }
+ )`,
+
+ defineProp: `
+ const foo = defineProp();
+ const bar = defineProp('bar', { default: 0 })`,
+
+ exportProps: `
+ export let foo: string
+ export const bar = 0`,
+
+ chainCall: `\nconst props = defineProps<${propsType}>().withDefaults({\n bar: 0 })`,
+}
+
+export const processDefineEmits: Record = {
+ defineEmits: `
+ const emit = defineEmits<{
+ increment: [value: number]
+ decrement: []
+ }>()
+ emit('increment', 1)
+ emit('decrement')
+ `,
+ defineEmit: `
+ const increment = defineEmit<[value: number]>()
+ const decrement = defineEmit<[]>()
+ increment(1)
+ decrement()
+ `,
+}
+
+type Lang = 'ts' | 'tsx' | 'vue'
+type Render = { code: string; setup: string; lang: Lang }
+
+export const processDefineRender: Record = {
+ '': {
+ code: `\n\n{{ count }}
`,
+ setup: '',
+ lang: 'ts',
+ },
+ defineRender: {
+ code: '',
+ setup: `defineRender({ count.value }
)`,
+ lang: 'tsx',
+ },
+ exportRender: {
+ code: '',
+ setup: 'export default () => { count.value }
',
+ lang: 'tsx',
+ },
+}
+
+export const processDefineComponent: Record<
+ DefineComponents,
+ (
+ setup: string,
+ render: Render,
+ topLevel: string,
+ ) => {
+ code: string
+ lang: Lang
+ filename: string
+ }
+> = {
+ 'Vue SFC': (setup, render, topLevel) => ({
+ code: `
```
:::
-Also support [props destructuring](/features/reactivity-transform.html) and JSX:
+Also support [props destructuring](../features/reactivity-transform.md) and JSX:
```vue
-
```
+
+## Volar Configuration
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "defineEmit": true,
+ },
+ },
+}
+```
diff --git a/docs/macros/define-models.md b/docs/macros/define-models.md
index a1935f9c6..c57b61e84 100644
--- a/docs/macros/define-models.md
+++ b/docs/macros/define-models.md
@@ -1,4 +1,4 @@
-# defineModels
+# defineModels
@@ -30,7 +30,7 @@ VueMacros({
Requires [`@vueuse/core`](https://www.npmjs.com/package/@vueuse/core), install it by yourself before using.
-```vue
+```vue twoslash
+
+
+
+
```
::: details Compiled Code
-```vue
+```vue twoslash
-
+
+
+
+
```
:::
## JSX in `
@@ -74,31 +61,39 @@ console.log(count.value)
### With Options
-```vue
-
```
### TypeScript
-```vue
+```vue twoslash
+```
+
+### With Reactivity Transform
+
+```vue twoslash
+
```
@@ -117,7 +112,7 @@ const propName = defineProp(defaultValue, required, rest)
### Basic Usage
```vue
-
```
@@ -147,11 +142,35 @@ const count = defineProp(0, false, {
```
+
+### With Reactivity Transform
+
+```vue
+
+```
+
+### Volar Configuration
+
+```jsonc {3,7} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "defineProp": {
+ // "kevinEdition" | "johnsonEdition"
+ "edition": "kevinEdition",
+ },
+ },
+ },
+}
+```
diff --git a/docs/macros/define-props-refs.md b/docs/macros/define-props-refs.md
index c55be5eac..91446b135 100644
--- a/docs/macros/define-props-refs.md
+++ b/docs/macros/define-props-refs.md
@@ -1,4 +1,4 @@
-# definePropsRefs
+# definePropsRefs
@@ -15,46 +15,43 @@ Returns refs from `defineProps` instead of a reactive object. It can be destruct
## Basic Usage
-```vue {2-3,8}
+```vue twoslash {2-3,8}
```
## With Default Value
-```vue {2-3,8}
+```vue twoslash {2-3,8}
```
## Volar Configuration
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3,
- "plugins": [
- "@vue-macros/volar/define-props-refs"
- // ...more feature
- ]
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
diff --git a/docs/macros/define-props.md b/docs/macros/define-props.md
index e912ea64e..fc6f8667f 100644
--- a/docs/macros/define-props.md
+++ b/docs/macros/define-props.md
@@ -1,4 +1,4 @@
-# defineProps
+# defineProps
@@ -15,35 +15,30 @@ See also [Vue issue](https://github.com/vuejs/core/issues/6876), [Reactivity Tra
::: warning
-[Reactivity Transform](https://vuejs.org/guide/extras/reactivity-transform.html) is required. You should enable it first.
+[Reactivity Transform](../features/reactivity-transform.md) is required. You should enable it first.
:::
## Basic Usage
-```vue
+```vue twoslash
```
## Volar Configuration
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3,
- "plugins": [
- "@vue-macros/volar/define-props"
- // ...more feature
- ]
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
diff --git a/docs/macros/define-render.md b/docs/macros/define-render.md
index 65cf5c955..1bf37f042 100644
--- a/docs/macros/define-render.md
+++ b/docs/macros/define-render.md
@@ -1,4 +1,4 @@
-# defineRender
+# defineRender
@@ -11,15 +11,17 @@ Defining render function in `
```
+### Full Syntax (Official Version)
+
+```vue twoslash
+
+```
+
## Volar Configuration
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3, // or 2.7 is not supported by Volar.
- "plugins": [
- "@vue-macros/volar/define-slots"
- // ...more feature
- ]
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
diff --git a/docs/macros/define-stylex.md b/docs/macros/define-stylex.md
new file mode 100644
index 000000000..3c4fd463b
--- /dev/null
+++ b/docs/macros/define-stylex.md
@@ -0,0 +1,139 @@
+# defineStyleX
+
+
+
+Define and consume [StyleX](https://stylexjs.com/) styles in `
+
+
+ Red
+
+```
+
+:::details Compiled Code (with some simplifications)
+
+```vue [App.vue] twoslash
+
+
+
+
+
+ Red
+
+```
+
+:::
+
+## Conditional Styles
+
+Optional and multiple rules are supported.
+
+```vue [App.vue] twoslash
+
+
+
+ Red
+
+```
+
+:::details Compiled Code (with some simplifications)
+
+```vue [App.vue] twoslash
+
+
+
+
+
+ Red
+
+```
+
+:::
diff --git a/docs/macros/index.md b/docs/macros/index.md
index ab1762e77..332c662a4 100644
--- a/docs/macros/index.md
+++ b/docs/macros/index.md
@@ -2,26 +2,27 @@
List of all available macros.
-Please make sure `unplugin-vue-macros` is set up correctly. If you haven't yet, read [Getting Started](/guide/getting-started) first.
+Please make sure `vue-macros` is set up correctly. If you haven't yet, read [Getting Started](../guide/getting-started.md) first.
## Implemented by Vue 3.3
-- [defineOptions](/macros/define-options)
-- [defineSlots](/macros/define-slots)
-- [shortEmits](/macros/short-emits)
+- [defineOptions](./define-options.md)
+- [defineSlots](./define-slots.md)
+- [shortEmits](./short-emits.md)
## Stable Features
-- [defineModels](/macros/define-models)
-- [defineProps](/macros/define-props)
-- [definePropsRefs](/macros/define-props-refs)
-- [defineRender](/macros/define-render)
-- [shortVmodel](/macros/short-vmodel)
+- [defineModels](./define-models.md)
+- [defineProps](./define-props.md)
+- [definePropsRefs](./define-props-refs.md)
+- [defineRender](./define-render.md)
+- [shortVmodel](./short-vmodel.md)
## Experimental Features
-- [defineProp](/macros/define-prop)
-- [defineEmit](/macros/define-emit)
-- [setupComponent](/macros/setup-component)
-- [setupSFC](/macros/setup-sfc)
-- [chainCall](/macros/chain-call)
+- [defineProp](./define-prop.md)
+- [defineEmit](./define-emit.md)
+- [setupComponent](./setup-component.md)
+- [setupSFC](./setup-sfc.md)
+- [chainCall](./chain-call.md)
+- [defineStyleX](./define-stylex.md)
diff --git a/docs/macros/setup-component.md b/docs/macros/setup-component.md
index da79e7733..92347516c 100644
--- a/docs/macros/setup-component.md
+++ b/docs/macros/setup-component.md
@@ -1,16 +1,16 @@
-# setupComponent
+# setupComponent
::: tip
-If you're using `setupComponent`, then `defineRender` cannot be disabled.
+`defineRender` cannot be disabled when using `setupComponent`.
-Files in `node_modules` will not be ignored by default.
+Files in `node_modules` will be ignored by default.
:::
-With `defineSetupComponent`, `
```
+Using type `ShortEmits` or for short `SE`.
+
+```vue twoslash
+
+```
+
## Difference with Official Version
- function style of declaration is not supported by official version.
diff --git a/docs/macros/short-vmodel.md b/docs/macros/short-vmodel.md
index ce3488113..d2c8bae98 100644
--- a/docs/macros/short-vmodel.md
+++ b/docs/macros/short-vmodel.md
@@ -1,4 +1,4 @@
-# shortVmodel
+# shortVmodel
@@ -15,42 +15,16 @@ If you have any questions about this feature, you can comment on [RFC Discussion
| Vue 2 | :x: |
| Volar Plugin | :white_check_mark: |
-## Setup
-
-### Installation
-
-```bash
-npm i @vue-macros/short-vmodel
-```
-
-### Vite Integration
-
-```ts {9-17}
-// vite.config.ts
-import { defineConfig } from 'vite'
-import Vue from '@vitejs/plugin-vue'
-import { transformShortVmodel } from '@vue-macros/short-vmodel'
-
-export default defineConfig({
- plugins: [
- Vue({
- template: {
- compilerOptions: {
- nodeTransforms: [
- transformShortVmodel({
- prefix: '$',
- }),
- ],
- },
- },
- }),
- ],
-})
-```
-
## Options
-`prefix`: `'::' | '$' | '*'`, defaults to `'$'`
+```ts
+interface Options {
+ /**
+ * @default '$'
+ */
+ prefix?: '::' | '$' | '*'
+}
+```
## Usage
@@ -90,23 +64,19 @@ export default defineConfig({
## Volar Configuration
-```jsonc {5,9}
-// tsconfig.json
+```jsonc {3,5-7} [tsconfig.json]
{
"vueCompilerOptions": {
- "plugins": [
- "@vue-macros/volar/short-vmodel"
- // ...
- ],
+ "plugins": ["vue-macros/volar"],
"vueMacros": {
"shortVmodel": {
- "prefix": "$"
- }
- }
- }
+ "prefix": "$",
+ },
+ },
+ },
}
```
## Known Issues
-- Prettier will format `::=` to `:=`, prettier-ignore is required if prefix is `::`.
+- Prettier will format `::=` to `:=` (e.g. `` -> ``). The comment `` is required if prefix is `::`.
diff --git a/docs/package.json b/docs/package.json
index 2912992f8..3b2c697a8 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -1,21 +1,33 @@
{
"name": "docs",
- "version": "0.0.0",
"private": true,
+ "type": "module",
"scripts": {
"dev": "vitepress dev",
"build": "vitepress build",
- "preview": "vitepress serve"
+ "preview": "vitepress preview",
+ "clean": "rimraf dist .vitepress/cache .vitepress/dist"
+ },
+ "dependencies": {
+ "prettier": "catalog:",
+ "shiki": "catalog:"
},
"devDependencies": {
- "@vite-pwa/vitepress": "^0.2.0",
- "@vitejs/plugin-vue-jsx": "^3.0.1",
- "markdown-it": "^13.0.1",
- "markdown-it-container": "^3.0.0",
- "unocss": "^0.53.6",
- "vite-plugin-pwa": "^0.16.4",
- "vitepress": "1.0.0-beta.6",
- "vue": "^3.3.4",
- "workbox-window": "^7.0.0"
+ "@iconify-json/logos": "catalog:",
+ "@iconify-json/ri": "catalog:",
+ "@nolebase/vitepress-plugin-enhanced-mark": "catalog:",
+ "@nolebase/vitepress-plugin-enhanced-readabilities": "catalog:",
+ "@nolebase/vitepress-plugin-git-changelog": "catalog:",
+ "@nolebase/vitepress-plugin-highlight-targeted-heading": "catalog:",
+ "@shikijs/vitepress-twoslash": "catalog:",
+ "@stylexjs/stylex": "catalog:",
+ "@vitejs/plugin-vue-jsx": "catalog:",
+ "@vueuse/core": "catalog:",
+ "vite-plugin-vue-devtools": "catalog:",
+ "vitepress": "catalog:",
+ "vitepress-plugin-group-icons": "catalog:",
+ "vitepress-plugin-llms": "catalog:",
+ "vue": "catalog:",
+ "vue-macros": "workspace:*"
}
}
diff --git a/docs/public/logo.svg b/docs/public/logo.svg
index 14d55f99d..3f3210a04 100644
--- a/docs/public/logo.svg
+++ b/docs/public/logo.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/docs/public/og.png b/docs/public/og.png
new file mode 100644
index 000000000..d54845923
Binary files /dev/null and b/docs/public/og.png differ
diff --git a/docs/tsconfig.json b/docs/tsconfig.json
index 4e707729d..2b830fe92 100644
--- a/docs/tsconfig.json
+++ b/docs/tsconfig.json
@@ -1,25 +1,28 @@
{
"compilerOptions": {
- "baseUrl": ".",
- "module": "esnext",
+ "incremental": true,
+ "tsBuildInfoFile": "dist/.tsbuildinfo",
"target": "esnext",
- "lib": ["DOM", "ESNext"],
- "strict": true,
"jsx": "preserve",
- "esModuleInterop": true,
- "skipLibCheck": true,
+ "lib": ["DOM", "ESNext"],
+ "baseUrl": ".",
+ "customConditions": ["dev"],
+ "module": "esnext",
"moduleResolution": "bundler",
+ "paths": {
+ "~/*": ["src/*"],
+ "#macros": ["../macros/index.ts"]
+ },
"resolveJsonModule": true,
- "noUnusedLocals": true,
+ "types": ["vite/client", "vitepress"],
+ "strict": true,
"strictNullChecks": true,
+ "noUnusedLocals": true,
+ "esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
- "types": ["vite/client", "vitepress", "vite-plugin-pwa/client"],
- "paths": {
- "~/*": ["src/*"]
- },
- "customConditions": ["dev"]
+ "skipLibCheck": true
},
"vueCompilerOptions": {},
- "include": ["**/*", "./.*/**/*", "../packages/shim.d.ts"],
+ "include": ["**/*", "./.*/**/*", "../**/shim.d.ts"],
"exclude": ["dist", "node_modules"]
}
diff --git a/docs/vercel.json b/docs/vercel.json
index 14e221781..21988e7c7 100644
--- a/docs/vercel.json
+++ b/docs/vercel.json
@@ -1,6 +1,9 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
- "github": {
- "silent": true
- }
+ "rewrites": [
+ {
+ "source": "/:path*",
+ "destination": "/:path*.html"
+ }
+ ]
}
diff --git a/docs/vite.config.ts b/docs/vite.config.ts
index 9ef781b84..ae4b5e43e 100644
--- a/docs/vite.config.ts
+++ b/docs/vite.config.ts
@@ -1,12 +1,60 @@
-import { defineConfig } from 'vite'
-import Unocss from 'unocss/vite'
+import {
+ GitChangelog,
+ GitChangelogMarkdownSection,
+} from '@nolebase/vitepress-plugin-git-changelog/vite'
import VueJsx from '@vitejs/plugin-vue-jsx'
+import Unocss from 'unocss/vite'
+import { defineConfig } from 'vite'
+import Devtools from 'vite-plugin-vue-devtools'
+import {
+ groupIconVitePlugin,
+ localIconLoader,
+} from 'vitepress-plugin-group-icons'
+import llmstxt from 'vitepress-plugin-llms'
+import { githubLink } from '../macros/repo'
export default defineConfig({
- build: {
- ssr: false,
- ssrManifest: false,
- manifest: false,
+ plugins: [
+ llmstxt({
+ ignoreFiles: ['interactive/**/*', 'zh-CN/**/*', 'index.md'],
+ }),
+ VueJsx(),
+ Unocss(),
+ Devtools(),
+ GitChangelog({
+ repoURL: githubLink,
+ mapAuthors: [
+ {
+ name: 'Kevin Deng',
+ username: 'sxzz',
+ mapByEmailAliases: ['sxzz@sxzz.moe'],
+ },
+ {
+ name: 'zhiyuanzmj',
+ username: 'zhiyuanzmj',
+ mapByEmailAliases: ['260480378@qq.com'],
+ },
+ ],
+ }),
+ GitChangelogMarkdownSection(),
+ groupIconVitePlugin({
+ customIcon: {
+ rspack: localIconLoader(import.meta.url, './assets/rspack.svg'),
+ rsbuild: localIconLoader(import.meta.url, './assets/rsbuild.svg'),
+ 'vue-macros': localIconLoader(import.meta.url, './public/logo.svg'),
+ },
+ }),
+ ],
+ optimizeDeps: {
+ exclude: [
+ '@nolebase/vitepress-plugin-enhanced-readabilities/client',
+ 'vitepress',
+ ],
+ },
+ ssr: {
+ noExternal: [
+ '@nolebase/vitepress-plugin-enhanced-readabilities',
+ '@nolebase/vitepress-plugin-highlight-targeted-heading',
+ ],
},
- plugins: [VueJsx(), Unocss()],
})
diff --git a/docs/volar/define-generic.md b/docs/volar/define-generic.md
new file mode 100644
index 000000000..52bbdb5e5
--- /dev/null
+++ b/docs/volar/define-generic.md
@@ -0,0 +1,46 @@
+# defineGeneric
+
+
+
+Declare single generic one by one using `DefineGeneric`.
+
+> Especially useful for `setup-sfc`.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## Basic Usage
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+
+
+
+
+```
+
+:::
+
+## Volar Configuration
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/volar/jsx-ref.md b/docs/volar/jsx-ref.md
new file mode 100644
index 000000000..5ad316156
--- /dev/null
+++ b/docs/volar/jsx-ref.md
@@ -0,0 +1,99 @@
+# jsxRef
+
+
+
+Automatically infer type for `useRef`.
+
+| Features | Supported |
+| :------: | :----------------: |
+| Volar | :white_check_mark: |
+
+## Setup Auto Import
+
+::: code-group
+
+```ts [vite.config.ts]
+import AutoImport from 'unplugin-auto-import/vite'
+
+export default defineConfig({
+ plugins: [
+ AutoImport({
+ imports: [
+ {
+ from: 'vue',
+ imports: [['shallowRef', 'useRef']],
+ },
+ ],
+ }),
+ ],
+})
+```
+
+```ts [nuxt.config.ts]
+export default defineNuxtConfig({
+ imports: {
+ presets: [
+ {
+ from: 'vue',
+ imports: [['shallowRef', 'useRef']],
+ },
+ ],
+ },
+})
+```
+
+:::
+
+## Basic Usage
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-ref.md#comp{ts} [Comp.ts]
+
+:::
+
+## Volar Configuration
+
+```jsonc [tsconfig.json] {3,6}
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "jsxRef": {
+ "alias": ["useRef"],
+ },
+ },
+ },
+}
+```
diff --git a/docs/volar/script-sfc.md b/docs/volar/script-sfc.md
new file mode 100644
index 000000000..5031ca31e
--- /dev/null
+++ b/docs/volar/script-sfc.md
@@ -0,0 +1,37 @@
+# scriptSFC
+
+
+
+Enabled Volar support for `.ts` | `.tsx` files.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## Basic Usage
+
+### With `jsxDirective`
+
+::: code-group
+
+```tsx [App.tsx]
+export default ({ foo }: { foo: number }) => (
+ {foo}
+ // ^ will be inferred as 1
+)
+```
+
+:::
+
+## Volar Configuration
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["@vue-macros/volar"],
+ "vueMacros": {
+ "scriptSFC": true,
+ },
+ },
+}
+```
diff --git a/docs/volar/setup-jsdoc.md b/docs/volar/setup-jsdoc.md
new file mode 100644
index 000000000..4742f416a
--- /dev/null
+++ b/docs/volar/setup-jsdoc.md
@@ -0,0 +1,84 @@
+# setupJsdoc
+
+
+
+Define the component's JSDoc in the script setup block.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## Basic Usage
+
+````vue twoslash
+
+
+
+
+
+````
+
+### There are two places to define
+
+1. The first line of the script setup block.
+
+````vue
+
+````
+
+2. Above the `export default` expression.
+
+::: tip
+
+This feature depends on `exportRender`, and make sure `exportRender` is not disabled.
+
+:::
+
+````vue
+
+````
+
+## Volar Configuration
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/volar/template-ref.md b/docs/volar/template-ref.md
new file mode 100644
index 000000000..f9e361bc6
--- /dev/null
+++ b/docs/volar/template-ref.md
@@ -0,0 +1,55 @@
+# templateRef
+
+
+
+Automatically infer type for `templateRef` (from [VueUse](https://vueuse.org/core/templateRef/))
+and `useTemplateRef` (Vue 3.5+).
+
+::: warning
+
+This feature is officially supported since Volar (`vue-tsc`) v2.1.0.
+Vue Macros is no longer offering this feature as a plugin.
+
+:::
+
+| Features | Supported |
+| :------: | :----------------: |
+| Volar | :white_check_mark: |
+
+## Basic Usage
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+
+
+
+
+```
+
+<<< ./template-ref.md#comp{ts} [Comp.ts]
+
+:::
+
+## Volar Configuration
+
+No configuration required.
diff --git a/docs/vue-macros.config.ts b/docs/vue-macros.config.ts
new file mode 100644
index 000000000..7ad446f61
--- /dev/null
+++ b/docs/vue-macros.config.ts
@@ -0,0 +1,12 @@
+import { defineConfig } from 'vue-macros'
+
+export default defineConfig({
+ booleanProp: true,
+ defineEmit: true,
+ defineProp: true,
+ defineStyleX: true,
+ exportRender: true,
+ jsxRef: true,
+ scriptLang: true,
+ setupSFC: true,
+})
diff --git a/docs/zh-CN/features/better-define.md b/docs/zh-CN/features/better-define.md
index f3f6f0ed3..90229320b 100644
--- a/docs/zh-CN/features/better-define.md
+++ b/docs/zh-CN/features/better-define.md
@@ -1,4 +1,4 @@
-# betterDefine
+# betterDefine
@@ -17,22 +17,27 @@
::: code-group
-```vue [App.vue]
+```vue twoslash [App.vue]
```
-```ts [types.ts]
-export interface BaseProps {
- title: string
-}
-```
+<<< ./better-define.md#basic{ts} [types.ts]
:::
diff --git a/docs/zh-CN/features/boolean-prop.md b/docs/zh-CN/features/boolean-prop.md
new file mode 100644
index 000000000..c7d2b2bc1
--- /dev/null
+++ b/docs/zh-CN/features/boolean-prop.md
@@ -0,0 +1,73 @@
+# booleanProp
+
+
+
+把 `` 转换为 ``。
+
+把 `` 转换为 ``。
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Vue 3 | :white_check_mark: |
+| Nuxt 3 | :white_check_mark: |
+| Vue 2 | :x: |
+| Volar Plugin | :white_check_mark: |
+
+## 选项
+
+```ts
+interface Options {
+ /**
+ * @default '!'
+ */
+ negativePrefix?: string
+}
+```
+
+## 基本用法
+
+
+```vue twoslash
+
+
+
+
+ // ^?
+
+```
+
+
+```vue twoslash
+
+```
+
+## Volar 配置
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "booleanProp": true,
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/features/export-expose.md b/docs/zh-CN/features/export-expose.md
index 969c4df67..27ebfaea8 100644
--- a/docs/zh-CN/features/export-expose.md
+++ b/docs/zh-CN/features/export-expose.md
@@ -1,4 +1,4 @@
-# exportExpose
+# exportExpose
@@ -8,8 +8,8 @@
| :----------: | :----------------: |
| Vue 3 | :white_check_mark: |
| Nuxt 3 | ? |
-| Vue 2 | ? |
-| Volar Plugin | :x: |
+| Vue 2 | :white_check_mark: |
+| Volar Plugin | :white_check_mark: |
## 用法
@@ -23,12 +23,13 @@
### 1. 局部变量/函数/类
-```vue
+```vue twoslash
```
::: details 编译后代码
-```vue
+```vue twoslash
```
+<<< ./export-expose.md#export-file{ts} [types.ts]
+
+:::
+
::: details 编译后代码
-```vue
+```vue twoslash
```
+```ts [types.ts]
+export const foo = 'foo'
+```
+
+:::
+
::: details 编译后代码
-```vue
+```vue twoslash
```
+
+## Volar 配置
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+ "vueMacros": {
+ "exportProps": true,
+ },
+}
+```
diff --git a/docs/zh-CN/features/export-render.md b/docs/zh-CN/features/export-render.md
new file mode 100644
index 000000000..c3cb756a0
--- /dev/null
+++ b/docs/zh-CN/features/export-render.md
@@ -0,0 +1,43 @@
+# exportRender
+
+
+
+在 Vue SFC 的 `
+```
+
+## Volar 配置
+
+```jsonc {3,7} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "exportRender": true,
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/features/hoist-static.md b/docs/zh-CN/features/hoist-static.md
index a6f1c9920..c02900618 100644
--- a/docs/zh-CN/features/hoist-static.md
+++ b/docs/zh-CN/features/hoist-static.md
@@ -1,4 +1,4 @@
-# hoistStatic
+# hoistStatic
@@ -14,7 +14,7 @@
## 基本用法
-```vue
+```vue twoslash
+```
+
+### `v-for`
+
+```vue twoslash
+
+```
+
+### `v-slot`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-directive.md#v-slot{tsx} [Child.tsx]
+
+:::
+
+### `v-on`
+
+::: warning
+
+`v-on` 仅支持绑定不带参数的事件/监听器对的对象。
+
+:::
+
+```tsx
+
+```
+
+## 动态参数
+
+在指令参数上也可以使用一个变量,需要包含在一对 `$` 内:
+
+`v-model`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
```
+
+<<< ./jsx-directive.md#v-model{tsx} [Comp.tsx]
+
+:::
+
+`v-slot`
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-directive.md#v-slot-dynamic{tsx} [Comp.tsx]
+
+:::
+
+## 修饰符
+
+修饰符是以 `_` 开头的特殊后缀,表明指令需要以一些特殊的方式被绑定。
+
+```tsx
+
+```
+
+## Volar 配置
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/zh-CN/features/named-template.md b/docs/zh-CN/features/named-template.md
index e740aa405..29b756c2a 100644
--- a/docs/zh-CN/features/named-template.md
+++ b/docs/zh-CN/features/named-template.md
@@ -1,4 +1,4 @@
-# namedTemplate
+# namedTemplate
diff --git a/docs/zh-CN/features/reactivity-transform.md b/docs/zh-CN/features/reactivity-transform.md
index 5ef16b714..395f8acf3 100644
--- a/docs/zh-CN/features/reactivity-transform.md
+++ b/docs/zh-CN/features/reactivity-transform.md
@@ -1,4 +1,4 @@
-# Reactivity Transform
+# Reactivity Transform
@@ -72,8 +72,7 @@ module.exports = {
### TypeScript 支持
-```json
-// tsconfig.json
+```json [tsconfig.json]
{
"compilerOptions": {
// ...
@@ -88,7 +87,7 @@ module.exports = {
响应性语法糖是一个编译时的转换步骤,让我们可以像这样书写代码:
-```vue
+```vue twoslash
```
上面的代码将被编译成下面这样的运行时声明:
-```js
-export default {
+```ts twoslash
+import { defineComponent, watchEffect } from 'vue'
+
+export default defineComponent({
props: {
msg: { type: String, required: true },
count: { type: Number, default: 1 },
@@ -227,7 +243,7 @@ export default {
console.log(props.msg, props.count, props.foo)
})
},
-}
+})
```
## 保持在函数间传递时的响应性 {#retaining-reactivity-across-function-boundaries}
@@ -238,7 +254,9 @@ export default {
假设有一个期望接收一个 ref 对象为参数的函数:
-```ts
+```ts twoslash
+import { watch, type Ref } from 'vue'
+
function trackChange(x: Ref) {
watch(x, (x) => {
console.log('x 改变了!')
@@ -246,6 +264,7 @@ function trackChange(x: Ref) {
}
const count = $ref(0)
+// @errors: 2345
trackChange(count) // 无效!
```
@@ -279,7 +298,7 @@ trackChange(count)
如果将响应式变量直接放在返回值表达式中会丢失掉响应性:
-```ts
+```ts twoslash
function useMouse() {
const x = $ref(0)
const y = $ref(0)
@@ -307,7 +326,7 @@ return {
我们还是可以使用 `$$()` 来解决这个问题。在这个例子中,`$$()` 可以直接用在要返回的对象上,`$$()` 调用时任何对响应式变量的引用都会保留为对相应 ref 的引用:
-```ts
+```ts twoslash
function useMouse() {
const x = $ref(0)
const y = $ref(0)
@@ -326,21 +345,36 @@ function useMouse() {
`$$()` 也适用于已解构的 props,因为它们也是响应式的变量。编译器会高效地通过 `toRef` 来做转换:
-```ts
+```vue twoslash
+
```
编译结果为:
-```js
-export default {
+```ts twoslash
+import { defineComponent, toRef, type Ref } from 'vue'
+function passAsRef(count: Ref) {
+ return count
+}
+// ---cut---
+export default defineComponent({
+ props: {
+ count: { type: Number, required: true },
+ },
setup(props) {
const __props_count = toRef(props, 'count')
passAsRef(__props_count)
},
-}
+})
```
## TypeScript 集成 {#typescript-integration}
@@ -351,11 +385,11 @@ Vue 为这些宏函数都提供了类型声明 (全局可用),因此类型推
因为这些宏函数都是全局可用的,它们的类型需要被显式地引用 (例如,在 `env.d.ts` 文件中):
-```ts
-///
+```ts [env.d.ts]
+///
// 或适用于独立版本:
///
```
-若你是从 `unplugin-vue-macros/macros` 或 `@vue-macros/reactivity-transform/macros-global` 中显式引入宏函数时,则不需要像这样全局声明。
+若你是从 `vue-macros/macros` 或 `@vue-macros/reactivity-transform/macros-global` 中显式引入宏函数时,则不需要像这样全局声明。
diff --git a/docs/zh-CN/features/script-lang.md b/docs/zh-CN/features/script-lang.md
new file mode 100644
index 000000000..8958115b4
--- /dev/null
+++ b/docs/zh-CN/features/script-lang.md
@@ -0,0 +1,52 @@
+# scriptLang
+
+
+
+为 `
+```
+
+## Volar Configuration
+
+```jsonc {3,5-7} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "scriptLang": {
+ "defaultLang": "ts",
+ },
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/features/short-bind.md b/docs/zh-CN/features/short-bind.md
new file mode 100644
index 000000000..e838a9639
--- /dev/null
+++ b/docs/zh-CN/features/short-bind.md
@@ -0,0 +1,54 @@
+# shortBind
+
+
+
+`:value` -> `:value="value"`
+
+同名简写绑定 prop 。如果 prop 与要绑定的 JavaScript 值同名,则可以进一步缩短语法以省略 prop 值。
+
+对于 Vue >= 3.4,此功能将默认关闭。
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Vue 3 | :white_check_mark: |
+| Nuxt 3 | :white_check_mark: |
+| Vue 2 | :x: |
+| Volar Plugin | :white_check_mark: |
+
+## 用法
+
+### 基本用法
+
+```vue twoslash
+
+
+
+
+
+
+```
+
+### 和 `shortVmodel` 一起使用
+
+```vue
+
+
+
+
+
+
+
+
+```
+
+## Volar 配置
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/zh-CN/guide/astro-integration.md b/docs/zh-CN/guide/astro-integration.md
new file mode 100644
index 000000000..e95395952
--- /dev/null
+++ b/docs/zh-CN/guide/astro-integration.md
@@ -0,0 +1,46 @@
+# Astro 集成
+
+### 安装
+
+::: code-group
+
+```bash [npm]
+npm i -D @vue-macros/astro
+```
+
+```bash [yarn]
+yarn add -D @vue-macros/astro
+```
+
+```bash [pnpm]
+pnpm add -D @vue-macros/astro
+```
+
+:::
+
+## 配置
+
+```ts [astro.config.mjs]
+import Vue from '@astrojs/vue'
+import Macros from '@vue-macros/astro'
+import { defineConfig } from 'astro/config'
+
+export default defineConfig({
+ integrations: [
+ Vue(),
+ Macros({
+ // 覆盖配置选项
+ }),
+ ],
+})
+```
+
+## TypeScript 支持 和 Volar 支持
+
+参见 [构建工具集成](./bundler-integration.md#typescript-support) 的对应章节。
+
+---
+
+:tada: 恭喜你! 现在已经成功完成了对 Astro 的集成过程。
+
+如果你还想要了解有关宏的更多信息, 请访问 [全部宏](/zh-CN/macros/) :laughing:。
diff --git a/docs/zh-CN/guide/bundler-integration.md b/docs/zh-CN/guide/bundler-integration.md
index 4cb7e9ffa..d67f6f777 100644
--- a/docs/zh-CN/guide/bundler-integration.md
+++ b/docs/zh-CN/guide/bundler-integration.md
@@ -1,55 +1,71 @@
-# 打包器集成
+# 构建工具集成
-### 安装
+## 安装
+
+::: tip
+
+完全支持 Vite 和 Rollup,其他构建工具支持有限。
+
+:::
::: code-group
```bash [npm]
-npm i -D unplugin-vue-macros
+npm i -D vue-macros
```
```bash [yarn]
-yarn add -D unplugin-vue-macros
+yarn add -D vue-macros
```
```bash [pnpm]
-pnpm add -D unplugin-vue-macros
+pnpm add -D vue-macros
```
:::
::: code-group
-```ts [Vite (first-class support)]
+```ts [Vite]
// vite.config.ts
-import VueMacros from 'unplugin-vue-macros/vite'
import Vue from '@vitejs/plugin-vue'
+import VueMacros from 'vue-macros/vite'
// import VueJsx from '@vitejs/plugin-vue-jsx'
+// import VueRouter from 'unplugin-vue-router/vite'
export default defineConfig({
plugins: [
VueMacros({
plugins: {
vue: Vue(),
- // vueJsx: VueJsx(), // 如果需要
+ // vueJsx: VueJsx(), // 如有需要
+ // vueRouter: VueRouter({ // 如有需要
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // 覆盖插件选项
}),
],
})
```
-```ts [Rollup (first-class support)]
-// rollup.config.js
+```ts [Rollup]
import Vue from 'unplugin-vue/rollup'
-import VueMacros from 'unplugin-vue-macros/rollup'
+// rollup.config.js
+import VueMacros from 'vue-macros/rollup'
+// import VueRouter from 'unplugin-vue-router/rollup'
export default {
plugins: [
VueMacros({
plugins: {
vue: Vue(),
- // vueJsx: VueJsx(), // 如果需要
+ // vueJsx: VueJsx(), // 如有需要
+ // vueRouter: VueRouter({ // 如有需要
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // 覆盖插件选项
}),
],
}
@@ -58,14 +74,19 @@ export default {
```js [esbuild]
// esbuild.config.js
import { build } from 'esbuild'
+// import VueRouter from 'unplugin-vue-router/esbuild'
build({
plugins: [
- require('unplugin-vue-macros/esbuild')({
+ require('vue-macros/esbuild')({
plugins: {
vue: require('unplugin-vue/esbuild')(),
- // vueJsx: VueJsx(), // 如果需要
+ // vueJsx: VueJsx(), // 如有需要
+ // vueRouter: VueRouter({ // 如有需要
+ // extensions: ['.vue', '.setup.tsx']
+ // })
},
+ // 覆盖插件选项
}),
],
})
@@ -75,79 +96,119 @@ build({
// webpack.config.js
module.exports = {
/* ... */
- plugins: [require('unplugin-vue-macros/webpack')({})],
+ plugins: [
+ require('vue-macros/webpack')({
+ // 覆盖插件选项
+ }),
+ ],
+}
+```
+
+```js [Rspack]
+// rspack.config.js
+module.exports = {
+ /* ... */
+ plugins: [
+ require('vue-macros/rspack')({
+ // 覆盖插件选项
+ }),
+ ],
+}
+```
+
+```js [Rsbuild]
+// rsbuild.config.js
+module.exports = {
+ // ...
+ tools: {
+ rspack: {
+ plugins: [
+ require('vue-macros/rspack')({
+ // 覆盖插件选项
+ }),
+ ],
+ },
+ },
}
```
```js [Vue CLI]
// vue.config.js
const { defineConfig } = require('@vue/cli-service')
-const VueMacros = require('unplugin-vue-macros/webpack')
+const VueMacros = require('vue-macros/webpack')
module.exports = defineConfig({
// ...
// ⚠️ 重要
parallel: false,
configureWebpack: {
- plugins: [VueMacros({})],
+ plugins: [
+ VueMacros({
+ // 覆盖插件选项
+ }),
+ ],
},
})
```
:::
-## TypeScript 支持
+## 配置
-::: code-group
+详情请参阅 [配置](./configurations.md)。
-```json {0} [Vue 3]
-// tsconfig.json
-{
- "compilerOptions": {
- // ...
- "types": ["unplugin-vue-macros/macros-global" /* ... */]
- }
-}
+```ts twoslash [vue-macros.config.ts]
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
+ // 选项
+})
```
-```json {0} [Vue 2]
+## TypeScript 支持
+
+```json {0}
// tsconfig.json
{
"compilerOptions": {
// ...
- "types": ["unplugin-vue-macros/vue2-macros-global" /* ... */]
+ "types": ["vue-macros/macros-global" /* ... */]
}
}
```
-:::
-
## Volar 支持
-有关宏的详细配置请参考每个宏的具体说明。
+详细配置请参阅具体宏的描述。
-```bash
-npm i -D @vue-macros/volar
-```
-
-```json
-// tsconfig.json
+```jsonc [tsconfig.json]
{
"vueCompilerOptions": {
- "plugins": [
- "@vue-macros/volar/define-options",
- "@vue-macros/volar/define-models",
- "@vue-macros/volar/define-props",
- "@vue-macros/volar/define-props-refs",
- "@vue-macros/volar/short-vmodel",
- "@vue-macros/volar/define-slots",
- "@vue-macros/volar/export-props"
- ]
- // ...
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
-:tada: 恭喜你! 目前你已经成功将 `unplugin-vue-macros` 设置完成。
+### 作用域插件
+
+`exportExpose`、`exportProps` 和 `exportRender` 插件不能同时使用,除非提供作用域。
+
+```ts twoslash [vue-macros.config.ts]
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
+ exportExpose: {
+ include: ['**/export-expose/**'],
+ },
+ exportProps: {
+ include: ['**/export-props/**'],
+ },
+ exportRender: {
+ include: ['**/export-render/**'],
+ },
+})
+```
+
+---
+
+:tada: 恭喜!你已成功设置 Vue Macros。
-如果你还想要了解有关宏的更多信息, 请访问 [全部宏](/zh-CN/macros/) :laughing:。
+想了解更多关于宏的信息,请访问 [所有宏](/macros/) :laughing:.
diff --git a/docs/zh-CN/guide/configurations.md b/docs/zh-CN/guide/configurations.md
index 9639d2c9b..f5b52a84e 100644
--- a/docs/zh-CN/guide/configurations.md
+++ b/docs/zh-CN/guide/configurations.md
@@ -2,49 +2,53 @@
## 插件选项
-默认情况下启用所有功能,但以下功能除外。
+以下功能除外,默认情况下将启用所有功能。
+
+#### 默认关闭
-- `defineOptions` (Vue >= 3.3)
-- `defineSlots` (Vue >= 3.3)
-- `hoistStatic` (Vue >= 3.3)
-- `shortEmits` (Vue >= 3.3)
- `exportExpose`
- `exportProps`
+- `exportRender`
- `setupSFC`
+- `booleanProp`
+- `shortBind`
+
+#### Vue >= 3.3 默认关闭
+
+- `defineOptions`
+- `defineSlots`
+- `hoistStatic`
+- `shortEmits`
+
+你可以通过将选项设置为 `true` 来重新启用它们。
-您可以通过将选项设置为 `false` 来禁用它们。
+```ts twoslash [vue-macros.config.ts(js|ts|json)]
+// vue-macros.config.[js,ts,json]
-```ts
-VueMacros({
+import { defineConfig } from 'vue-macros'
+export default defineConfig({
root: '/your-project-path',
/**
- * Vue 版本,2 或 3
+ * Vue 版本,2, 3, 3.3 等。
*
* 可选,自动检测版本
*/
version: 3,
- plugins: {
- vue: Vue(),
- vueJsx: VueJsx(),
- },
-
- /** 默认是 true */
+ /** 默认 true */
defineModels: {
- /**
- * unified 模式,仅在 Vue 2 有效
- *
- * 将 `modelValue` 转换为 `value`
- */
- unified: true,
+ // ...
},
- // 禁用特性
+ // 开启功能
+ defineOptions: true,
+
+ // 关闭功能
hoistStatic: false,
- // ...更多
+ // ...更多功能
})
```
-有关每个宏的配置选项,请参考对应宏的页面。
+有关每个功能的配置选项,请参考对应的页面。
diff --git a/docs/zh-CN/guide/eslint-integration.md b/docs/zh-CN/guide/eslint-integration.md
new file mode 100644
index 000000000..b28237e54
--- /dev/null
+++ b/docs/zh-CN/guide/eslint-integration.md
@@ -0,0 +1,42 @@
+# ESLint 集成
+
+## 安装
+
+::: code-group
+
+```bash [pnpm]
+pnpm add -D @vue-macros/eslint-config
+```
+
+```bash [yarn]
+yarn add -D @vue-macros/eslint-config
+```
+
+```bash [npm]
+npm i -D @vue-macros/eslint-config
+```
+
+:::
+
+## 配置
+
+### Flat 风格配置
+
+```js [eslint.config.js]
+import vueMacros from '@vue-macros/eslint-config/flat'
+export default [
+ vueMacros,
+ // ...其他配置
+]
+```
+
+### 传统风格配置
+
+```jsonc [.eslintrc]
+{
+ "extends": [
+ "@vue-macros/eslint-config",
+ // ...其他配置
+ ],
+}
+```
diff --git a/docs/zh-CN/guide/getting-started.md b/docs/zh-CN/guide/getting-started.md
index c2babc733..2ae96a454 100644
--- a/docs/zh-CN/guide/getting-started.md
+++ b/docs/zh-CN/guide/getting-started.md
@@ -1,30 +1,85 @@
-# 入门
+
-Vue Macros 是一个库,用于实现尚未被 Vue 正式实现的提案或想法。这意味着它将探索更多宏和语法糖到 Vue 中。
+# 入门指南
+
+Vue Macros 是一个实现 Vue 非官方提案和想法的库,探索并扩展了其功能和语法。
在继续之前,我们假设你已经熟悉 Vue 的基本用法。
## 要求
-- Node.js 16.14.0 或更高
-- Vue >= 2.7 或 Vue >= 3.0
- - 某些功能需要 Vue >= 3.2.25
-- VSCode 安装了 [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) 扩展
- - ❌ 不支持 WebStorm
+- Node.js `>= v20.18.0`
+- Vue `>= v2.7` 或 Vue `>= v3.0`
+ - 某些功能需要 Vue `>= v3.2.25`
+- VSCode 扩展 [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) 和 `vue-tsc` 为 v{{ version }}
+ - Vue Macros 会持续尽快适配最新版本,旧版本可能不受支持
+
+::: warning
+不支持 WebStorm。
+:::
+
+## 创建 Vue Macros 项目
+
+### 安装
+
+::: code-group
+
+```bash [npm]
+npm i -g @vue-macros/cli
+```
+
+```bash [yarn]
+yarn global add @vue-macros/cli
+```
+
+```bash [pnpm]
+pnpm add -g @vue-macros/cli
+```
+
+:::
+
+此命令将安装 [@vue-macros/cli](https://github.com/vue-macros/vue-macros-cli),这是官方的 Vue Macros 脚手架工具。
+
+### 初始化
+
+::: code-group
+
+```bash [npm]
+npm create vite@latest my-vue-macros -- --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+```bash [yarn]
+yarn create vite my-vue-macros --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+```bash [pnpm]
+pnpm create vite my-vue-macros --template vue-ts
+cd my-vue-macros
+vue-macros init
+```
+
+你将会看到一些可选的实验性功能提示。
+
+:::
-## 示例
+## 模板
-- [Vite + Vue 3](https://github.com/vue-macros/vue-macros/tree/main/playground/vue3)
-- [Vite + Vue 2](https://github.com/vue-macros/vue-macros/tree/main/playground/vue2)
-- [Nuxt 3 + Vue 3](https://github.com/vue-macros/nuxt)
-- [Vue CLI + Vue 2](https://github.com/vue-macros/vue2-vue-cli)
+- [Vite](https://github.com/vue-macros/vite)
+- [Nuxt](https://github.com/vue-macros/nuxt)
+- [Rsbuild](https://github.com/vue-macros/vue3-rsbuild)
-🌟 欢迎提供更多示例!
+🌟 欢迎更多模板!
## Nuxt 集成
-如果你使用的是 [Nuxt 3](https://nuxt.com/),请阅读 [Nuxt 集成](./nuxt-integration.md)。
+如果你使用 [Nuxt](https://nuxt.com/),请阅读 [Nuxt 集成](./nuxt-integration.md)。
-## 打包器集成
+## 构建工具集成
-如果你使用的是 [Vite](https://vitejs.dev/)、[Rollup](https://rollupjs.org/)、[esbuild](https://esbuild.github.io/),或 [Webpack](https://webpack.js.org/) 此类打包器,请阅读 [打包器集成](./bundler-integration.md)。
+如果你使用 [Vite](https://vitejs.dev/)、[Rollup](https://rollupjs.org/)、[esbuild](https://esbuild.github.io/)、[Webpack](https://webpack.js.org/)、或 [Rspack](https://www.rspack.dev/),请阅读 [构建工具集成](./bundler-integration.md)。
diff --git a/docs/zh-CN/guide/migration-v3.md b/docs/zh-CN/guide/migration-v3.md
new file mode 100644
index 000000000..60cf2c480
--- /dev/null
+++ b/docs/zh-CN/guide/migration-v3.md
@@ -0,0 +1,53 @@
+# 从 v2 迁移到 v3
+
+## 统一版本管理
+
+最初,我们使用 [`changesets`](https://github.com/changesets/changesets) 来管理 monorepo 中所有包的版本
+然而,经过两年的实践,我们决定在 v3 中采用单一版本策略,即所有子包共享相同的版本号,类似于 Vue 和 Babel 的做法。
+这一决策源于我们发现,当某个子包进行重大变更或次要更新时,主包的版本号未能充分反映这些变化。
+
+例如,当 `@vue-macros/define-prop` 发生重大变更时,`unplugin-vue-macros` 应如何发布新版本?是发布次要版本还是补丁版本?
+用户在更新 `unplugin-vue-macros` 时,也无法直观了解这一更新是否源于 `@vue-macros/define-prop` 的变更。
+
+因此,在 Anthony 提出 [Epoch Semantic Versioning](https://antfu.me/posts/epoch-semver) 后,
+我们决定采用更频繁的主版本更新策略,所有包共享相同的版本号,并仅维护一个统一的变更日志。
+
+## 主包名称变更
+
+我们将主包名称从 `unplugin-vue-macros` 更改为 **`vue-macros`**。
+v3 正式发布后,`unplugin-vue-macros` 将被标记为已弃用。
+
+因此,您需要更新 `package.json` 和导入 Vue Macros 的语句:
+
+```diff
+ // package.json
+ {
+ "devDependencies": {
+- "unplugin-vue-macros": "^2.14.5"
++ "vue-macros": "^3.0.0"
+ }
+ }
+```
+
+```diff
+- import { $ref } from 'unplugin-vue-macros/macros'
++ import { $ref } from 'vue-macros/macros'
+
+- import VueMacros from 'unplugin-vue-macros/vite'
++ import VueMacros from 'vue-macros/vite'
+```
+
+## 移除 Vue 2 支持
+
+Vue 2 已于 2023 年底进入终止支持阶段(EOL),因此我们决定在 v3 中移除对 Vue 2 的支持。
+如果您仍在使用 Vue 2,建议您继续使用 v2 版本,或考虑我们的[付费支持计划](https://github.com/vue-macros/vue-macros/issues/373)。
+
+## Node.js 兼容性调整
+
+在 v3 中,我们移除了对 Node.js 20.18 以下版本的支持。这意味着 v3 的最低 Node.js 版本要求为 `20.18.0`。
+同时,我们移除了 CommonJS(CJS)产物,仅提供 ECMAScript 模块(ESM)。
+
+## 移除 Webpack 4 支持
+
+由于 Webpack 4 无法在 Node.js 18 及以上环境中运行,我们移除了对 Webpack 4 和 Vue CLI 4 的支持。
+建议您升级至 Vite 或 Rspack 等现代构建工具。
diff --git a/docs/zh-CN/guide/nuxt-integration.md b/docs/zh-CN/guide/nuxt-integration.md
index d766228ae..95de5d622 100644
--- a/docs/zh-CN/guide/nuxt-integration.md
+++ b/docs/zh-CN/guide/nuxt-integration.md
@@ -1,4 +1,4 @@
-# Nuxt 集成
+# Nuxt 集成
### 安装
@@ -20,19 +20,20 @@ pnpm add -D @vue-macros/nuxt
## 配置
-```ts
-// nuxt.config.ts
+```ts [nuxt.config.ts]
export default {
modules: [
'@vue-macros/nuxt',
// ...
],
macros: {
- // 如果需要,在这里配置插件
+ // 覆盖配置选项
},
}
```
+---
+
:tada: 恭喜你! 现在已经成功完成了对 Nuxt 的集成过程。
如果你还想要了解有关宏的更多信息, 请访问 [全部宏](/zh-CN/macros/) :laughing:。
diff --git a/docs/zh-CN/index.md b/docs/zh-CN/index.md
index ef38f23f5..1823e6845 100644
--- a/docs/zh-CN/index.md
+++ b/docs/zh-CN/index.md
@@ -26,6 +26,6 @@ features:
title: 类型安全
details: 完整的 TypeScript 和 Volar 支持。
- icon: ⚡️
- title: 支持多个打包器
- details: 由 unplugin 驱动,支持 Vite、Nuxt、Webpack、Vue CLI、Rollup 3、esbuild 等。
+ title: 支持大多数打包工具
+ details: 由 unplugin 驱动,几乎支持所有的打包工具。
---
diff --git a/docs/zh-CN/interactive/index.md b/docs/zh-CN/interactive/index.md
new file mode 100644
index 000000000..e135e6f5b
--- /dev/null
+++ b/docs/zh-CN/interactive/index.md
@@ -0,0 +1,10 @@
+---
+layout: page
+gitChangelog: false
+---
+
+
+
+
diff --git a/docs/zh-CN/macros/chain-call.md b/docs/zh-CN/macros/chain-call.md
index 47492f51a..e75029d6a 100644
--- a/docs/zh-CN/macros/chain-call.md
+++ b/docs/zh-CN/macros/chain-call.md
@@ -1,4 +1,4 @@
-# chainCall
+# chainCall
@@ -15,7 +15,7 @@
::: tip
- `chainCall` 不支持 `definePropsRefs`。
-- 你需要从 `unplugin-vue-macros/macros` 中导入此宏以获取更好的类型检查。
+- 你需要从 `vue-macros/macros` 中导入此宏以获取更好的类型检查。
:::
@@ -36,7 +36,7 @@ const props = defineProps<{
::: details 编译后的代码
-```vue
+```vue twoslash
```
:::
-也支持 [props 解构](/features/reactivity-transform.html) 和 JSX:
+也支持 [props 解构](../features/reactivity-transform.md) 和 JSX:
```vue
-
```
-## With Validation
+## 带验证的用法
-```vue
+```vue twoslash
```
## TypeScript
-```vue
+```vue twoslash
```
+
+## Volar 配置
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "defineEmit": true,
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/macros/define-models.md b/docs/zh-CN/macros/define-models.md
index 9de1b15c8..8b94ec7e7 100644
--- a/docs/zh-CN/macros/define-models.md
+++ b/docs/zh-CN/macros/define-models.md
@@ -1,4 +1,4 @@
-# defineModels
+# defineModels
@@ -30,7 +30,7 @@ VueMacros({
在开始之前,请先自行安装 [`@vueuse/core`](https://www.npmjs.com/package/@vueuse/core)
-```vue
+```vue twoslash
+
+
+
+
```
::: details 编译后的代码
-```vue
+```vue twoslash
-
+
+
+
+
```
:::
## `
```
-### With Options
+### 选项
-```vue
-
```
### TypeScript
-```vue
+```vue twoslash
```
-## Johnson's Edition
+### 响应性语法糖
+
+```vue twoslash
+
+```
+
+## Johnson 的版本
+
+### API 参考
```ts
-// the prop name will be inferred from variable name
+// 从变量名中推断出 prop 名称
const propName = defineProp()
const propName = defineProp(defaultValue)
const propName = defineProp(defaultValue, required)
const propName = defineProp(defaultValue, required, rest)
```
-### Basic Usage
+### 基本用法
```vue
-
```
-### With Options
+### 选项
```vue
-
```
@@ -117,25 +128,35 @@ const count = defineProp(0, false, {
```
-## Volar Configuration
+### 响应性语法糖
+
+```vue
+
+```
-**Require Volar >= `1.3.12`**
+## Volar 配置
-```jsonc
-// tsconfig.json
+```jsonc {3,7} [tsconfig.json]
{
- // ...
"vueCompilerOptions": {
- // "kevinEdition" | "johnsonEdition" | false
- "experimentalDefinePropProposal": "kevinEdition"
- }
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "defineProp": {
+ // "kevinEdition" | "johnsonEdition"
+ "edition": "kevinEdition",
+ },
+ },
+ },
}
```
diff --git a/docs/zh-CN/macros/define-props-refs.md b/docs/zh-CN/macros/define-props-refs.md
index cf97b69b5..5e0f6b1aa 100644
--- a/docs/zh-CN/macros/define-props-refs.md
+++ b/docs/zh-CN/macros/define-props-refs.md
@@ -1,4 +1,4 @@
-# definePropsRefs
+# definePropsRefs
@@ -15,46 +15,43 @@
## 基本用法
-```vue {2-3,8}
+```vue twoslash {2-3,8}
```
## 默认值
-```vue {2-3,8}
+```vue twoslash {2-3,8}
```
## Volar 配置
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3,
- "plugins": [
- "@vue-macros/volar/define-props-refs"
- // ...更多功能
- ]
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
diff --git a/docs/zh-CN/macros/define-props.md b/docs/zh-CN/macros/define-props.md
index 6122f8779..394ba9bc9 100644
--- a/docs/zh-CN/macros/define-props.md
+++ b/docs/zh-CN/macros/define-props.md
@@ -1,4 +1,4 @@
-# defineProps
+# defineProps
@@ -15,35 +15,30 @@
::: warning
-在开始之前,你必须先开启 [响应性语法糖](https://cn.vuejs.org/guide/extras/reactivity-transform.html)
+在开始之前,你必须先开启 [响应性语法糖](../features/reactivity-transform.md)
:::
## 基本用法
-```vue
+```vue twoslash
```
## Volar 配置
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3,
- "plugins": [
- "@vue-macros/volar/define-props"
- // ...更多功能
- ]
- }
+ "plugins": ["@vue-macros/volar/define-props"],
+ },
}
```
diff --git a/docs/zh-CN/macros/define-render.md b/docs/zh-CN/macros/define-render.md
index 6b7be43b1..28e7eb7ea 100644
--- a/docs/zh-CN/macros/define-render.md
+++ b/docs/zh-CN/macros/define-render.md
@@ -1,4 +1,4 @@
-# defineRender
+# defineRender
@@ -11,15 +11,17 @@
| Vue 2 | :white_check_mark: |
| TypeScript | :white_check_mark: |
+在 [RFC 讨论](https://github.com/vuejs/rfcs/discussions/585) 中,我们需要更多的反馈!
+
## 基本用法
-```vue
+```vue twoslash
```
+### 完整语法(官方版本)
+
+```vue twoslash
+
+```
+
## Volar 配置
-```jsonc {6}
-// tsconfig.json
+```jsonc {3} [tsconfig.json]
{
"vueCompilerOptions": {
- "target": 3, // Volar 暂不支持 2.7 版本
- "plugins": [
- "@vue-macros/volar/define-slots"
- // ...更多功能
- ]
- }
+ "plugins": ["vue-macros/volar"],
+ },
}
```
diff --git a/docs/zh-CN/macros/define-stylex.md b/docs/zh-CN/macros/define-stylex.md
new file mode 100644
index 000000000..d39acac89
--- /dev/null
+++ b/docs/zh-CN/macros/define-stylex.md
@@ -0,0 +1,139 @@
+# defineStyleX
+
+
+
+在 `
+
+
+ Red
+
+```
+
+:::details 编译结果(有所简化)
+
+```vue [App.vue] twoslash
+
+
+
+
+
+ Red
+
+```
+
+:::
+
+## 条件样式
+
+你可以应用多个样式,也可以根据条件应用样式。
+
+```vue [App.vue] twoslash
+
+
+
+ Red
+
+```
+
+:::details 编译结果(有所简化)
+
+```vue [App.vue] twoslash
+
+
+
+
+
+ Red
+
+```
+
+:::
diff --git a/docs/zh-CN/macros/index.md b/docs/zh-CN/macros/index.md
index 9ae7f590a..c75fc1206 100644
--- a/docs/zh-CN/macros/index.md
+++ b/docs/zh-CN/macros/index.md
@@ -2,26 +2,27 @@
以下是所有可用宏的列表。
-在开始之前,请确保 `unplugin-vue-macros` 设置正确。如果你还没有设置,请先阅读 [入门](/zh-CN/guide/getting-started)
+在开始之前,请确保 `vue-macros` 设置正确。如果你还没有设置,请先阅读 [入门](../guide/getting-started.md)
## 被 Vue 3.3 官方支持
-- [defineOptions](/zh-CN/macros/define-options)
-- [defineSlots](/zh-CN/macros/define-slots)
-- [shortEmits](/zh-CN/macros/short-emits)
+- [defineOptions](./define-options.md)
+- [defineSlots](./define-slots.md)
+- [shortEmits](./short-emits.md)
## 稳定功能
-- [defineModels](/zh-CN/macros/define-models)
-- [defineProps](/zh-CN/macros/define-props)
-- [definePropsRefs](/zh-CN/macros/define-props-refs)
-- [defineRender](/zh-CN/macros/define-render)
-- [shortVmodel](/zh-CN/macros/short-vmodel)
+- [defineModels](./define-models.md)
+- [defineProps](./define-props.md)
+- [definePropsRefs](./define-props-refs.md)
+- [defineRender](./define-render.md)
+- [shortVmodel](./short-vmodel.md)
## 实验性功能
-- [defineProp](/zh-CN/macros/define-prop)
-- [defineEmit](/zh-CN/macros/define-emit)
-- [setupComponent](/zh-CN/macros/setup-component)
-- [setupSFC](/zh-CN/macros/setup-sfc)
-- [chainCall](/macros/chain-call)
+- [defineProp](./define-prop.md)
+- [defineEmit](./define-emit.md)
+- [setupComponent](./setup-component.md)
+- [setupSFC](./setup-sfc.md)
+- [chainCall](./chain-call.md)
+- [defineStyleX](./define-stylex.md)
diff --git a/docs/zh-CN/macros/setup-component.md b/docs/zh-CN/macros/setup-component.md
index 0ed6c16fb..d9ada79c7 100644
--- a/docs/zh-CN/macros/setup-component.md
+++ b/docs/zh-CN/macros/setup-component.md
@@ -1,18 +1,16 @@
-# setupComponent
+# setupComponent
::: tip
-如果你使用的是 `setupComponent`,则不能禁用 `defineRender`。
+如果使用 `setupComponent` 时,不能禁用 `defineRender`。
-默认情况下不会忽略 `node_modules` 中的文件。
+默认情况下将会忽略 `node_modules` 中的文件。
:::
-
-
-使用 `defineSetupComponent`, 可以将 `
```
-## Difference with Official Version
+使用 `ShortEmits` 或简写为 `SE`,可以使用元组或方法定义。
+
+```vue twoslash
+
+```
+
+## 和官方版本不同的是
-- function style of declaration is not supported by official version.
+- 官方版本不支持函数式的声明风格。
diff --git a/docs/zh-CN/macros/short-vmodel.md b/docs/zh-CN/macros/short-vmodel.md
index a7808b3ec..250639b29 100644
--- a/docs/zh-CN/macros/short-vmodel.md
+++ b/docs/zh-CN/macros/short-vmodel.md
@@ -1,4 +1,4 @@
-# shortVmodel
+# shortVmodel
@@ -15,42 +15,16 @@
| Vue 2 | :x: |
| Volar Plugin | :white_check_mark: |
-## 设置
-
-### 安装
-
-```bash
-npm i @vue-macros/short-vmodel
-```
-
-### Vite 集成
-
-```ts {9-17}
-// vite.config.ts
-import { defineConfig } from 'vite'
-import Vue from '@vitejs/plugin-vue'
-import { transformShortVmodel } from '@vue-macros/short-vmodel'
-
-export default defineConfig({
- plugins: [
- Vue({
- template: {
- compilerOptions: {
- nodeTransforms: [
- transformShortVmodel({
- prefix: '$',
- }),
- ],
- },
- },
- }),
- ],
-})
-```
-
## 选项
-`prefix`: `'::' | '$' | '*'`,默认为 `'$'`
+```ts
+interface Options {
+ /**
+ * @default '$'
+ */
+ prefix?: '::' | '$' | '*'
+}
+```
## 用法
@@ -90,23 +64,19 @@ export default defineConfig({
## Volar 配置
-```jsonc {5,9}
-// tsconfig.json
+```jsonc {3,5-7} [tsconfig.json]
{
"vueCompilerOptions": {
- "plugins": [
- "@vue-macros/volar/short-vmodel"
- // ...
- ],
+ "plugins": ["vue-macros/volar"],
"vueMacros": {
"shortVmodel": {
- "prefix": "$"
- }
- }
- }
+ "prefix": "$",
+ },
+ },
+ },
}
```
-## 已知的问题
+## 已知问题
-- Prettier 会将 `::=` 格式化为 `:=`,如果 prefix 为 `::`,则需要 prettier-ignore
+- Prettier 会将 `::=` 格式化为 `:=`(例如 `` -> ``)。如果 prefix 为 `::`,则需要添加注释 ``
diff --git a/docs/zh-CN/volar/define-generic.md b/docs/zh-CN/volar/define-generic.md
new file mode 100644
index 000000000..8a2c5914b
--- /dev/null
+++ b/docs/zh-CN/volar/define-generic.md
@@ -0,0 +1,46 @@
+# defineGeneric
+
+
+
+使用 `DefineGeneric` 逐个声明单个范型。
+
+> 对于 `setup-sfc` 特别有用。
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## 基本用法
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+
+
+
+
+```
+
+:::
+
+## Volar 配置
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/zh-CN/volar/jsx-ref.md b/docs/zh-CN/volar/jsx-ref.md
new file mode 100644
index 000000000..5cf64bc13
--- /dev/null
+++ b/docs/zh-CN/volar/jsx-ref.md
@@ -0,0 +1,99 @@
+# jsxRef
+
+
+
+自动推断 `useRef` 的类型.
+
+| Features | Supported |
+| :------: | :----------------: |
+| Volar | :white_check_mark: |
+
+## 设置自动引入
+
+::: code-group
+
+```ts [vite.config.ts]
+import AutoImport from 'unplugin-auto-import/vite'
+
+export default defineConfig({
+ plugins: [
+ AutoImport({
+ imports: [
+ {
+ from: 'vue',
+ imports: [['shallowRef', 'useRef']],
+ },
+ ],
+ }),
+ ],
+})
+```
+
+```ts [nuxt.config.ts]
+export default defineNuxtConfig({
+ imports: {
+ presets: [
+ {
+ from: 'vue',
+ imports: [['shallowRef', 'useRef']],
+ },
+ ],
+ },
+})
+```
+
+:::
+
+## Basic Usage
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+```
+
+<<< ./jsx-ref.md#comp{ts} [Comp.ts]
+
+:::
+
+## Volar Configuration
+
+```jsonc [tsconfig.json] {3,6}
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ "vueMacros": {
+ "jsxRef": {
+ "alias": ["useRef"],
+ },
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/volar/script-sfc.md b/docs/zh-CN/volar/script-sfc.md
new file mode 100644
index 000000000..268930e16
--- /dev/null
+++ b/docs/zh-CN/volar/script-sfc.md
@@ -0,0 +1,37 @@
+# scriptSFC
+
+
+
+为 `.ts` 和 `.tsx` 文件提供 Volar 支持.
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## 基本用法
+
+### 和 `jsxDirective` 一起使用
+
+::: code-group
+
+```tsx [App.tsx]
+export default ({ foo }: { foo: number }) => (
+ {foo}
+ // ^ 将被推断为 1
+)
+```
+
+:::
+
+## Volar 配置
+
+```jsonc {3,5} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["@vue-macros/volar"],
+ "vueMacros": {
+ "scriptSFC": true,
+ },
+ },
+}
+```
diff --git a/docs/zh-CN/volar/setup-jsdoc.md b/docs/zh-CN/volar/setup-jsdoc.md
new file mode 100644
index 000000000..2c009a9e2
--- /dev/null
+++ b/docs/zh-CN/volar/setup-jsdoc.md
@@ -0,0 +1,84 @@
+# setupJsdoc
+
+
+
+在 `script setup` 块里定义组件的 `JSDoc`。
+
+| Features | Supported |
+| :----------: | :----------------: |
+| Volar Plugin | :white_check_mark: |
+
+## 基本用法
+
+````vue twoslash
+
+
+
+
+
+````
+
+### 有两个地方可以去定义
+
+1. `script setup` 代码块的第一行.
+
+````vue
+
+````
+
+2. 在 `export default` 表达式的上面.
+
+::: tip
+
+这个特性依赖于 `exportRender`,并确保 `exportRender` 没有被禁用。
+
+:::
+
+````vue
+
+````
+
+## Volar 配置
+
+```jsonc {3} [tsconfig.json]
+{
+ "vueCompilerOptions": {
+ "plugins": ["vue-macros/volar"],
+ },
+}
+```
diff --git a/docs/zh-CN/volar/template-ref.md b/docs/zh-CN/volar/template-ref.md
new file mode 100644
index 000000000..32b3f86d7
--- /dev/null
+++ b/docs/zh-CN/volar/template-ref.md
@@ -0,0 +1,54 @@
+# templateRef
+
+
+
+自动推断 `templateRef` (来自 [VueUse](https://vueuse.org/core/templateRef/)) 和 `useTemplateRef` (Vue 3.5+) 的类型。
+
+::: warning
+
+此功能自 Volar (`vue-tsc`) v2.1.0 起已得到官方支持。
+Vue Macros 不再提供此功能作为插件。
+
+:::
+
+| 特性 | 支持 |
+| :---: | :----------------: |
+| Volar | :white_check_mark: |
+
+## Basic Usage
+
+::: code-group
+
+```vue [App.vue] twoslash
+
+
+
+
+
+```
+
+<<< ./template-ref.md#comp{ts} [Comp.ts]
+
+:::
+
+## Volar 配置
+
+无需额外配置
diff --git a/eslint.config.js b/eslint.config.js
deleted file mode 100644
index 15ca3dc5c..000000000
--- a/eslint.config.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import { sxzz } from '@sxzz/eslint-config'
-
-export default sxzz([
- {
- ignores: ['playground/vue2', 'playground/nuxt'],
- },
-
- {
- files: ['**/*.vue'],
- rules: {
- 'vue/valid-attribute-name': 'off',
- 'vue/no-export-in-script-setup': 'off',
- 'vue/no-dupe-keys': 'off',
- },
- },
- {
- files: ['**/*.md/*.{js,ts,vue}'],
- rules: {
- 'no-var': 'off',
- 'import/no-mutable-exports': 'off',
- '@typescript-eslint/no-inferrable-types': 'off',
- '@typescript-eslint/no-empty-function': 'off',
- },
- },
- {
- files: ['playground/vue3/**'],
- rules: {
- 'no-debugger': 'off',
- 'no-console': 'off',
- 'vue/require-prop-types': 'off',
- 'vue/valid-define-props': 'off',
- 'vue/valid-attribute-name': 'off',
- 'import/no-default-export': 'off',
- },
- },
- {
- files: ['packages/volar/**'],
- rules: {
- 'import/no-default-export': 'off',
- },
- },
- {
- rules: {
- '@typescript-eslint/no-dynamic-delete': 'off',
- },
- },
-])
diff --git a/eslint.config.ts b/eslint.config.ts
new file mode 100644
index 000000000..4842e9924
--- /dev/null
+++ b/eslint.config.ts
@@ -0,0 +1,51 @@
+// @ts-check
+import { sxzz } from '@sxzz/eslint-config'
+import vueMacros from './packages/eslint-config/src/index.ts'
+
+export default sxzz({
+ pnpm: true,
+})
+ .removeRules('vue/valid-define-options')
+ .append([
+ vueMacros,
+ {
+ name: 'global-ignores',
+ ignores: ['playground/nuxt', 'playground/astro'],
+ },
+ {
+ name: 'markdown',
+ files: ['**/*.md/*.{js,ts,vue}'],
+ rules: {
+ 'no-var': 'off',
+ 'import/no-mutable-exports': 'off',
+ 'import/first': 'off',
+ },
+ },
+ {
+ name: 'playground/vue3',
+ files: ['playground/vue3/**'],
+ rules: {
+ 'no-debugger': 'off',
+ 'no-console': 'off',
+ },
+ },
+ {
+ name: 'allow-default-export',
+ files: [
+ '**/helper/*',
+ 'playground/vue3/**',
+ 'packages/{volar,eslint-config}/**',
+ '**/raw.ts',
+ ],
+ rules: {
+ 'import/no-default-export': 'off',
+ },
+ },
+ {
+ name: 'sort-config',
+ files: ['**/vue-macros.config.ts'],
+ rules: {
+ 'perfectionist/sort-objects': 'error',
+ },
+ },
+ ])
diff --git a/macros/index.ts b/macros/index.ts
new file mode 100644
index 000000000..96b424e57
--- /dev/null
+++ b/macros/index.ts
@@ -0,0 +1,18 @@
+import path from 'node:path'
+
+import { defineMacro } from 'unplugin-macros/api'
+
+export * from './repo'
+
+const root = path.resolve(__dirname, '..')
+
+function getPkgName(filePath: string) {
+ const relative = path.relative(root, filePath)
+ const [, pkgName] = relative.split(path.sep)
+ return pkgName
+}
+
+export const generatePluginName: () => string = defineMacro(function () {
+ const pkgName = getPkgName(this.id)
+ return `unplugin-vue-${pkgName}`
+})
diff --git a/macros/repo.ts b/macros/repo.ts
new file mode 100644
index 000000000..7593fb4e4
--- /dev/null
+++ b/macros/repo.ts
@@ -0,0 +1,3 @@
+export const docsLink = 'https://vue-macros.dev'
+export const githubRepo = 'vue-macros/vue-macros'
+export const githubLink: 'https://github.com/vue-macros/vue-macros' = `https://github.com/${githubRepo}`
diff --git a/monoman.config.ts b/monoman.config.ts
index a7c7e88db..737c8fe24 100644
--- a/monoman.config.ts
+++ b/monoman.config.ts
@@ -1,38 +1,53 @@
+import { readdir, readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
-import { readFile } from 'node:fs/promises'
-import { existsSync } from 'node:fs'
-import { defineConfig } from 'monoman'
-import { type Options } from 'tsup'
-import fg from 'fast-glob'
+import { camelCase } from 'change-case'
+import {
+ defineConfig,
+ noDuplicatedDeps,
+ noDuplicatedPnpmLockfile,
+} from 'monoman'
+import { docsLink, githubLink } from './macros/repo'
+import type { PackageJson } from 'pkg-types'
-function getPkgName(filepath: string) {
- const relative = path.relative(process.cwd(), filepath)
+/// keep-sorted
+const descriptions: Record = {
+ 'define-options': 'Add defineOptions macro for Vue "
@@ -173,7 +173,7 @@ exports[`analyzeSFC > defineProps > addProp should work 1`] = `
`;
exports[`analyzeSFC > defineProps > addProp should work 2`] = `
-""
@@ -474,7 +474,7 @@ exports[`analyzeSFC > defineProps > setProp should work > set property prop 1`]
`;
exports[`analyzeSFC > defineProps > setProp should work > set property prop 2`] = `
-""
@@ -499,7 +499,7 @@ exports[`analyzeSFC > defineProps > setProp should work > set props added by API
`;
exports[`analyzeSFC > defineProps > setProp should work > set props added by API 2`] = `
-""
`;
diff --git a/packages/api/tests/_util.ts b/packages/api/tests/_util.ts
index 1a4cc162b..15e468d30 100644
--- a/packages/api/tests/_util.ts
+++ b/packages/api/tests/_util.ts
@@ -9,7 +9,7 @@ export function hideAstLocation(ast: T): T {
(typeof value === 'object' && 'type' in value && 'loc' in value)
? `${value.type}...`
: value
- })
+ }),
)
}
diff --git a/packages/api/tests/analyzeSFC.test.ts b/packages/api/tests/analyze-sfc.test.ts
similarity index 87%
rename from packages/api/tests/analyzeSFC.test.ts
rename to packages/api/tests/analyze-sfc.test.ts
index b34306acd..c36ba2aa2 100644
--- a/packages/api/tests/analyzeSFC.test.ts
+++ b/packages/api/tests/analyze-sfc.test.ts
@@ -1,19 +1,22 @@
-import { MagicString, parseSFC } from '@vue-macros/common'
+import { MagicStringAST, parseSFC } from '@vue-macros/common'
import { describe, expect, test } from 'vitest'
-import { DefinitionKind, analyzeSFC } from '../src/vue'
+import { analyzeSFC, DefinitionKind } from '../src/vue'
import { hideAstLocation, snapshot } from './_util'
-async function complie(code: string) {
+async function compile(code: string) {
const str = ``
- const s = new MagicString(str)
+ const s = new MagicStringAST(str)
const sfc = parseSFC(str, 'test.vue')
- return { ...(await analyzeSFC(s, sfc)), s }
+ return {
+ ...(await analyzeSFC(s, sfc))._unsafeUnwrap({ withStackTrace: true }),
+ s,
+ }
}
describe('analyzeSFC', () => {
describe('defineProps', () => {
test('definitions should be correct', async () => {
- const { props } = await complie(`defineProps<{
+ const { props } = await compile(`defineProps<{
foo: string
bar(): void
baz: string | number
@@ -34,34 +37,34 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
expect(hideAstLocation(props!.definitions.bar)).toEqual(
expect.objectContaining({
type: 'method',
methods: [{ ast: 'TSMethodSignature...', code: 'bar(): void' }],
- })
+ }),
)
expect(hideAstLocation(props!.definitions.baz)).toEqual(
expect.objectContaining({
type: 'property',
value: { ast: 'TSUnionType...', code: 'string | number' },
- })
+ }),
)
expect(hideAstLocation(props!.definitions.qux)).toEqual(
expect.objectContaining({
type: 'property',
optional: true,
- })
+ }),
)
snapshot(hideAstLocation(props!.definitions))
})
test('should resolve referenced type', async () => {
- const { props } = await complie(
+ const { props } = await compile(
`type Foo = string
- defineProps<{ foo: Foo }>()`
+ defineProps<{ foo: Foo }>()`,
)
expect(hideAstLocation(props!.definitions.foo)).toEqual(
expect.objectContaining({
@@ -76,13 +79,13 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
snapshot(hideAstLocation(props!.definitions))
})
test('should resolve interface extends', async () => {
- const { props } = await complie(
+ const { props } = await compile(
`interface Base {
base: boolean
foo: number
@@ -91,7 +94,7 @@ describe('analyzeSFC', () => {
// override
foo: string
}
- defineProps()`
+ defineProps()`,
)
expect(Object.keys(hideAstLocation(props!.definitions))).toEqual([
'base',
@@ -104,13 +107,13 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
snapshot(hideAstLocation(props!.definitions))
})
test('should resolve intersection', async () => {
- const { props } = await complie(
+ const { props } = await compile(
`interface Base {
base: boolean
foo: number
@@ -119,7 +122,7 @@ describe('analyzeSFC', () => {
// override
foo: string
}
- defineProps()`
+ defineProps()`,
)
expect(Object.keys(hideAstLocation(props!.definitions))).toEqual([
'base',
@@ -132,13 +135,13 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
snapshot(hideAstLocation(props!.definitions))
})
test('addProp should work', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
foo: string
}>()`)
expect(props!.addProp('newProp', 'number | string')).toBe(true)
@@ -155,7 +158,7 @@ describe('analyzeSFC', () => {
ast: 'TSUnionType...',
code: 'number | string',
},
- })
+ }),
)
expect(props!.addProp('newProp2', 'string', true)).toBe(true)
@@ -168,7 +171,7 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
snapshot(hideAstLocation(props!.definitions))
@@ -176,7 +179,7 @@ describe('analyzeSFC', () => {
})
test('addProp should work in intersection', async () => {
- const { props, s } = await complie(`
+ const { props, s } = await compile(`
type Foo = { foo: string }
type Bar = { bar: number }
defineProps()`)
@@ -189,7 +192,7 @@ describe('analyzeSFC', () => {
describe('removeProp should work', () => {
test('remove property prop', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
foo: string
bar: number
}>()`)
@@ -203,7 +206,7 @@ describe('analyzeSFC', () => {
})
test('remove method prop', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
foo(): void
bar: number
}>()`)
@@ -216,7 +219,7 @@ describe('analyzeSFC', () => {
})
test('remove props added by API', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
foo: string
}>()`)
@@ -234,7 +237,7 @@ describe('analyzeSFC', () => {
describe('setProp should work', () => {
test('set property prop', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
foo: string
}>()`)
@@ -247,15 +250,15 @@ describe('analyzeSFC', () => {
})
test('set method prop', async () => {
- const { props, s } = await complie(`defineProps<{
+ const { props, s } = await compile(`defineProps<{
onClick(): void; onClick(param: string): string
}>()`)
expect(props!.setProp('onClick', '() => OverwroteMethodProp')).toBe(
- true
+ true,
)
expect(s.toString()).not.toContain(
- `onClick(): void; onClick(param: string): string`
+ `onClick(): void; onClick(param: string): string`,
)
expect(s.toString()).toContain(`onClick: () => OverwroteMethodProp`)
@@ -264,7 +267,7 @@ describe('analyzeSFC', () => {
})
test('set props added by API', async () => {
- const { props, s } = await complie(`defineProps<{}>()`)
+ const { props, s } = await compile(`defineProps<{}>()`)
expect(props!.addProp('foo', 'number | string')).toBe(true)
expect(props!.setProp('foo', 'string')).toBe(true)
@@ -277,7 +280,7 @@ describe('analyzeSFC', () => {
ast: 'TSStringKeyword...',
code: 'string',
},
- })
+ }),
)
// should be not updated in source code.
@@ -289,7 +292,7 @@ describe('analyzeSFC', () => {
})
test('getRuntimeProps', async () => {
- const { props } = await complie(`
+ const { props } = await compile(`
type AliasString1 = string
type AliasString2 = AliasString1
@@ -304,7 +307,7 @@ describe('analyzeSFC', () => {
onClick(param: string): any
}>()`)
- expect(await props!.getRuntimeDefinitions()).toEqual({
+ expect((await props!.getRuntimeDefinitions())._unsafeUnwrap()).toEqual({
bar: {
type: ['String'],
required: true,
@@ -336,7 +339,7 @@ describe('analyzeSFC', () => {
})
test('defineProps w/ withDefaults (static)', async () => {
- const { props } = await complie(`withDefaults(defineProps<{
+ const { props } = await compile(`withDefaults(defineProps<{
foo: string
bar?(): void
baz: string | number
@@ -357,7 +360,7 @@ describe('analyzeSFC', () => {
'fred',
'unknown',
])
- const defaults = await props!.getRuntimeDefinitions()
+ const defaults = (await props!.getRuntimeDefinitions())._unsafeUnwrap()
for (const k of Object.keys(defaults)) {
if (defaults[k].default) {
defaults[k].default = defaults[k].default!() as any
@@ -398,13 +401,13 @@ describe('analyzeSFC', () => {
})
test('defineProps w/ withDefaults (dynamic)', async () => {
- const { props } = await complie(`withDefaults(defineProps<{
+ const { props } = await compile(`withDefaults(defineProps<{
foo: string
bar?: number
}>(), {
['b' + 'ar']: 'bar'
})`)
- const defaults = await props!.getRuntimeDefinitions()
+ const defaults = (await props!.getRuntimeDefinitions())._unsafeUnwrap()
expect(defaults.bar.default).toBeUndefined()
expect(props!.defaults).toBeUndefined()
})
@@ -412,7 +415,7 @@ describe('analyzeSFC', () => {
describe('defineEmits', () => {
test('definitions should be correct', async () => {
- const { emits } = await complie(`defineEmits<{
+ const { emits } = await compile(`defineEmits<{
(evt: 'click'): void
(evt: 'click', param: string): void
(evt: 'change', param: string): void
@@ -442,9 +445,9 @@ describe('analyzeSFC', () => {
})
test('should resolve referenced type', async () => {
- const { emits } = await complie(
+ const { emits } = await compile(
`type Foo = 'foo'
- defineEmits<{ (evt: Foo): void }>()`
+ defineEmits<{ (evt: Foo): void }>()`,
)
expect(hideAstLocation(emits!.definitions.foo)).toEqual([
{
@@ -456,14 +459,14 @@ describe('analyzeSFC', () => {
})
test('should resolve interface extends', async () => {
- const { emits } = await complie(
+ const { emits } = await compile(
`interface Base {
(evt: 'foo'): void
}
interface Emits extends Base {
(evt: 'foo', param?: string): void
}
- defineEmits()`
+ defineEmits()`,
)
expect(Object.keys(hideAstLocation(emits!.definitions))).toEqual(['foo'])
expect(hideAstLocation(emits!.definitions.foo)).toEqual([
@@ -480,14 +483,14 @@ describe('analyzeSFC', () => {
})
test('should resolve intersection', async () => {
- const { emits } = await complie(
+ const { emits } = await compile(
`interface Base {
(evt: 'foo'): void
}
interface Emits {
(evt: 'foo', param?: string): void
}
- defineEmits()`
+ defineEmits()`,
)
expect(Object.keys(hideAstLocation(emits!.definitions))).toEqual(['foo'])
expect(hideAstLocation(emits!.definitions.foo)).toEqual([
@@ -504,7 +507,7 @@ describe('analyzeSFC', () => {
})
test('addEmit should work', async () => {
- const { emits, s } = await complie(`defineEmits<{
+ const { emits, s } = await compile(`defineEmits<{
(evt: 'click'): void
}>()`)
emits!.addEmit('change', `(evt: 'change'): void`)
@@ -534,7 +537,7 @@ describe('analyzeSFC', () => {
})
test('addEmit should work in intersection', async () => {
- const { emits, s } = await complie(`defineEmits<{
+ const { emits, s } = await compile(`defineEmits<{
(evt: 'click'): void
} & { (evt: 'change'): void }>()`)
emits!.addEmit('update', `(evt: 'update'): void`)
@@ -566,7 +569,7 @@ describe('analyzeSFC', () => {
})
test('no define macro', async () => {
- const result = await complie(`console.log('test')`)
+ const result = await compile(`console.log('test')`)
expect(result.props).toBeUndefined()
expect(result.emits).toBeUndefined()
})
diff --git a/packages/api/tests/fixtures/basic/folder/index.ts b/packages/api/tests/fixtures/basic/folder/index.ts
new file mode 100644
index 000000000..1a6498881
--- /dev/null
+++ b/packages/api/tests/fixtures/basic/folder/index.ts
@@ -0,0 +1 @@
+export type Folder = true
diff --git a/packages/api/tests/fixtures/basic/index.ts b/packages/api/tests/fixtures/basic/index.ts
index 62698d847..912547c49 100644
--- a/packages/api/tests/fixtures/basic/index.ts
+++ b/packages/api/tests/fixtures/basic/index.ts
@@ -6,7 +6,7 @@ export type { Str as StrAlias }
export type Num = number
-export interface Inferface extends Base1, Base2 {
+export interface Interface extends Base1, Base2 {
foo: 'foo'
}
@@ -14,3 +14,4 @@ export { Foo }
export type { Foo as FooAlias }
export { Test as OuterTest } from './export-all'
export * from './export-all'
+export * from './folder'
diff --git a/packages/api/tests/ts.test.ts b/packages/api/tests/ts.test.ts
index fbfe09c4e..f7be650d5 100644
--- a/packages/api/tests/ts.test.ts
+++ b/packages/api/tests/ts.test.ts
@@ -2,18 +2,18 @@ import path from 'node:path'
import { babelParse } from '@vue-macros/common'
import { describe, expect, test } from 'vitest'
import {
- type TSInterfaceDeclaration,
- type TSIntersectionType,
- type TSTypeAliasDeclaration,
-} from '@babel/types'
-import {
- type TSFile,
getTSFile,
resolveTSNamespace,
resolveTSProperties,
resolveTSReferencedType,
+ type TSFile,
} from '../src'
import { hideAstLocation } from './_util'
+import type {
+ TSInterfaceDeclaration,
+ TSIntersectionType,
+ TSTypeAliasDeclaration,
+} from '@babel/types'
const fixtures = path.resolve(__dirname, 'fixtures')
@@ -64,12 +64,14 @@ type Base2 = {
itShouldBeNumber: boolean
(): string
}
-`
+`,
)
- const interfaceProperties = await resolveTSProperties({
- scope: file,
- type: file.ast![0] as TSInterfaceDeclaration,
- })
+ const interfaceProperties = (
+ await resolveTSProperties({
+ scope: file,
+ type: file.ast![0] as TSInterfaceDeclaration,
+ })
+ )._unsafeUnwrap()
expect(hideAstLocation(interfaceProperties)).toMatchInlineSnapshot(`
{
@@ -148,17 +150,19 @@ type Base2 = {
hideAstLocation(
(
await resolveTSReferencedType(
- interfaceProperties.properties.bar.value!
+ interfaceProperties.properties.bar.value!,
)
- )?.type
- )
+ )._unsafeUnwrap()?.type,
+ ),
).toMatchInlineSnapshot('"TSStringKeyword..."')
- const intersectionProperties = await resolveTSProperties({
- scope: file,
- type: (file.ast![1] as TSTypeAliasDeclaration)
- .typeAnnotation as TSIntersectionType,
- })
+ const intersectionProperties = (
+ await resolveTSProperties({
+ scope: file,
+ type: (file.ast![1] as TSTypeAliasDeclaration)
+ .typeAnnotation as TSIntersectionType,
+ })
+ )._unsafeUnwrap()
expect(hideAstLocation(intersectionProperties)).toMatchInlineSnapshot(`
{
"callSignatures": [
@@ -199,33 +203,38 @@ type Base2 = {
const file = mockTSFile(
`export type AliasString1 = string
type AliasString2 = AliasString1
-type Foo = AliasString`
+type Foo = AliasString`,
)
const node = file.ast![1] as TSTypeAliasDeclaration
- const result = (await resolveTSReferencedType({
- scope: file,
- type: node.typeAnnotation,
- }))!
+ const result = (
+ await resolveTSReferencedType({
+ scope: file,
+ type: node.typeAnnotation,
+ })
+ )._unsafeUnwrap()!
expect(result.type!.type).toBe('TSStringKeyword')
})
describe('resolveTSFileExports', () => {
test('basic', async () => {
const file = await getTSFile(path.resolve(fixtures, 'basic/index.ts'))
- await resolveTSNamespace(file)
+ ;(await resolveTSNamespace(file))._unsafeUnwrap()
const exports = file.exports!
expect(hideAstLocation(exports)).toMatchInlineSnapshot(`
{
"ExportAll": {
"type": "TSLiteralType...",
},
+ "Folder": {
+ "type": "TSLiteralType...",
+ },
"Foo": {
"type": "TSLiteralType...",
},
"FooAlias": {
"type": "TSLiteralType...",
},
- "Inferface": {
+ "Interface": {
"type": "TSInterfaceDeclaration...",
},
"Num": {
@@ -248,11 +257,13 @@ type Foo = AliasString`
expect(
hideAstLocation(
- await resolveTSProperties({
- scope: file,
- type: exports.Inferface?.type as any,
- })
- )
+ (
+ await resolveTSProperties({
+ scope: file,
+ type: exports.Interface?.type as any,
+ })
+ )._unsafeUnwrap(),
+ ),
).toMatchInlineSnapshot(`
{
"callSignatures": [],
@@ -293,9 +304,9 @@ type Foo = AliasString`
test('circular referencing', async () => {
const file = await getTSFile(
- path.resolve(fixtures, 'circular-referencing/foo.ts')
+ path.resolve(fixtures, 'circular-referencing/foo.ts'),
)
- await resolveTSNamespace(file)
+ ;(await resolveTSNamespace(file))._unsafeUnwrap()
const exports = file.exports!
expect(hideAstLocation(exports)).toMatchInlineSnapshot(`
{
@@ -317,7 +328,7 @@ type Foo = AliasString`
test('namespace', async () => {
const file = await getTSFile(path.resolve(fixtures, 'namespace/index.ts'))
- await resolveTSNamespace(file)
+ ;(await resolveTSNamespace(file))._unsafeUnwrap()
const exports = file.exports!
expect(hideAstLocation(exports)).toMatchInlineSnapshot(`
{
diff --git a/packages/api/tsdown.config.ts b/packages/api/tsdown.config.ts
new file mode 100644
index 000000000..b84b0006e
--- /dev/null
+++ b/packages/api/tsdown.config.ts
@@ -0,0 +1,6 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ entry: ['./src/index.ts'],
+ platform: 'node',
+})
diff --git a/packages/api/tsup.config.ts b/packages/api/tsup.config.ts
deleted file mode 100644
index 8ec97581c..000000000
--- a/packages/api/tsup.config.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import config from '../../tsup.config.js'
-
-export default {
- ...config,
- entry: ['./src/index.ts'],
-}
diff --git a/packages/astro/README.md b/packages/astro/README.md
new file mode 100644
index 000000000..a69243c45
--- /dev/null
+++ b/packages/astro/README.md
@@ -0,0 +1,3 @@
+# @vue-macros/astro [](https://npmjs.com/package/@vue-macros/astro)
+
+Please refer to [README.md](https://github.com/vue-macros/vue-macros#readme)
diff --git a/packages/astro/package.json b/packages/astro/package.json
new file mode 100644
index 000000000..328e37a29
--- /dev/null
+++ b/packages/astro/package.json
@@ -0,0 +1,65 @@
+{
+ "name": "@vue-macros/astro",
+ "version": "3.0.0-beta.21",
+ "description": "Astro integration of Vue Macros.",
+ "type": "module",
+ "keywords": [
+ "vue-macros",
+ "macros",
+ "vue",
+ "sfc",
+ "setup",
+ "script-setup",
+ "astro"
+ ],
+ "license": "MIT",
+ "homepage": "https://vue-macros.dev",
+ "bugs": {
+ "url": "https://github.com/vue-macros/vue-macros/issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/vue-macros/vue-macros.git",
+ "directory": "packages/astro"
+ },
+ "author": "三咲智子 Kevin Deng ",
+ "contributors": [
+ "alexzhang1030 "
+ ],
+ "funding": "https://github.com/sponsors/vue-macros",
+ "files": [
+ "dist"
+ ],
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "exports": {
+ ".": {
+ "dev": "./src/index.ts",
+ "default": "./dist/index.js"
+ },
+ "./*": "./*"
+ },
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./*": "./*"
+ },
+ "tag": "next"
+ },
+ "scripts": {},
+ "peerDependencies": {
+ "astro": "^2.0.0 || ^3.0.0 || ^4.0.0"
+ },
+ "dependencies": {
+ "vue-macros": "workspace:*"
+ },
+ "devDependencies": {
+ "@vitejs/plugin-vue": "catalog:",
+ "astro": "catalog:"
+ },
+ "engines": {
+ "node": ">=20.18.0"
+ }
+}
diff --git a/packages/astro/src/index.ts b/packages/astro/src/index.ts
new file mode 100644
index 000000000..83c2fdb8e
--- /dev/null
+++ b/packages/astro/src/index.ts
@@ -0,0 +1,40 @@
+import { resolveOptions, type Options } from 'vue-macros'
+import VueMacros from 'vue-macros/vite'
+import type { AstroIntegration, ViteUserConfig } from 'astro'
+import type { Plugin } from 'vite'
+
+function findPluginAndRemove(
+ name: string,
+ plugins: ViteUserConfig['plugins'],
+): Plugin | undefined {
+ const idx = plugins!.findIndex(
+ (plugin) => plugin && 'name' in plugin && plugin.name === name,
+ )
+ if (idx === -1) return
+ const plugin = plugins![idx]
+ plugins!.splice(idx, 1)
+ return plugin as any
+}
+
+export default function (options?: Options): AstroIntegration {
+ return {
+ name: '@vue-macros/astro',
+ hooks: {
+ 'astro:config:setup': async ({ config }) => {
+ const resolvedOptions = await resolveOptions(options || {})
+ const vue = findPluginAndRemove('vite:vue', config.vite.plugins)
+ const vueJsx = findPluginAndRemove('vite:vue-jsx', config.vite.plugins)
+
+ const vueMacrosPlugins = await VueMacros({
+ ...resolvedOptions,
+ plugins: {
+ vue,
+ vueJsx,
+ },
+ })
+ config.vite.plugins ||= []
+ config.vite.plugins.push(...vueMacrosPlugins)
+ },
+ },
+ }
+}
diff --git a/packages/astro/tsdown.config.ts b/packages/astro/tsdown.config.ts
new file mode 100644
index 000000000..31cab43a9
--- /dev/null
+++ b/packages/astro/tsdown.config.ts
@@ -0,0 +1,5 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ entry: ['./src/index.ts'],
+})
diff --git a/packages/better-define/CHANGELOG.md b/packages/better-define/CHANGELOG.md
deleted file mode 100644
index 1c701fb8c..000000000
--- a/packages/better-define/CHANGELOG.md
+++ /dev/null
@@ -1,420 +0,0 @@
-# @vue-macros/better-define
-
-## 1.6.6
-
-### Patch Changes
-
-- [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb) Thanks [@sxzz](https://github.com/sxzz)! - simplify resolve identifiers
-
-- Updated dependencies [[`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741), [`20367274`](https://github.com/vue-macros/vue-macros/commit/2036727443c659eb84037eae85c5ac565521dd3e), [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb)]:
- - @vue-macros/common@1.6.0
- - @vue-macros/api@0.8.0
-
-## 1.6.5
-
-### Patch Changes
-
-- Updated dependencies [[`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779)]:
- - @vue-macros/common@1.5.0
- - @vue-macros/api@0.7.4
-
-## 1.6.4
-
-### Patch Changes
-
-- [`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4) Thanks [@sxzz](https://github.com/sxzz)! - add types for both esm and cjs
-
-- Updated dependencies [[`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4)]:
- - @vue-macros/common@1.4.1
- - @vue-macros/api@0.7.3
-
-## 1.6.3
-
-### Patch Changes
-
-- [`14bda40b`](https://github.com/vue-macros/vue-macros/commit/14bda40b21bf41ecedb7dd674f3e0c5828ae0414) Thanks [@sxzz](https://github.com/sxzz)! - add type fallback for all TS versions
-
-## 1.6.2
-
-### Patch Changes
-
-- [`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219) Thanks [@sxzz](https://github.com/sxzz)! - Switch to ast-kit
-
-- Updated dependencies [[`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219), [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88), [`ee4e093`](https://github.com/vue-macros/vue-macros/commit/ee4e093ec07931da9d24ded155a153e3496b4c7b)]:
- - @vue-macros/common@1.4.0
- - @vue-macros/api@0.7.2
-
-## 1.6.1
-
-### Patch Changes
-
-- [`34be70e`](https://github.com/vue-macros/vue-macros/commit/34be70e5b3e37615b563da02bff5ae89de63b713) Thanks [@sxzz](https://github.com/sxzz)! - resolve json file
-
-- Updated dependencies [[`34be70e`](https://github.com/vue-macros/vue-macros/commit/34be70e5b3e37615b563da02bff5ae89de63b713)]:
- - @vue-macros/common@1.3.3
- - @vue-macros/api@0.7.1
-
-## 1.6.0
-
-### Minor Changes
-
-- [#372](https://github.com/vue-macros/vue-macros/pull/372) [`65a04b2`](https://github.com/vue-macros/vue-macros/commit/65a04b2c7d0c71fd696cf80370fc78405c621a42) Thanks [@sxzz](https://github.com/sxzz)! - rewrite TypeScript resolver
-
-### Patch Changes
-
-- Updated dependencies [[`65a04b2`](https://github.com/vue-macros/vue-macros/commit/65a04b2c7d0c71fd696cf80370fc78405c621a42), [`39c72ff`](https://github.com/vue-macros/vue-macros/commit/39c72ff0f351b9b2d7eb5ad22e2a8b98f7a263a0)]:
- - @vue-macros/api@0.7.0
- - @vue-macros/common@1.3.2
-
-## 1.5.5
-
-### Patch Changes
-
-- [`90a1862`](https://github.com/vue-macros/vue-macros/commit/90a186263021114924c35bae537bb463fb3a4c32) Thanks [@sxzz](https://github.com/sxzz)! - add `skipCheck` for prop
-
-- Updated dependencies [[`90a1862`](https://github.com/vue-macros/vue-macros/commit/90a186263021114924c35bae537bb463fb3a4c32)]:
- - @vue-macros/api@0.6.3
-
-## 1.5.4
-
-### Patch Changes
-
-- Updated dependencies [[`ed7ca8c`](https://github.com/vue-macros/vue-macros/commit/ed7ca8cd1fc334fb3cf5b96ee6b64e55c7390d61)]:
- - @vue-macros/common@1.3.1
- - @vue-macros/api@0.6.2
-
-## 1.5.3
-
-### Patch Changes
-
-- [`791b2f3`](https://github.com/vue-macros/vue-macros/commit/791b2f31684c4156c4d3f26a4b22e06ab2c678f7) Thanks [@sxzz](https://github.com/sxzz)! - keep string type when boolean exist
-
-- Updated dependencies [[`791b2f3`](https://github.com/vue-macros/vue-macros/commit/791b2f31684c4156c4d3f26a4b22e06ab2c678f7)]:
- - @vue-macros/api@0.6.1
-
-## 1.5.2
-
-### Patch Changes
-
-- [`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f) Thanks [@sxzz](https://github.com/sxzz)! - separate `defineProp` and `defineEmit`
-
-- [#347](https://github.com/vue-macros/vue-macros/pull/347) [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1) Thanks [@kekexunxun](https://github.com/kekexunxun)! - fix include regex
-
-- [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d) Thanks [@sxzz](https://github.com/sxzz)! - simplify import helper function
-
-- Updated dependencies [[`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f), [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1), [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d)]:
- - @vue-macros/api@0.6.0
- - @vue-macros/common@1.3.0
-
-## 1.5.1
-
-### Patch Changes
-
-- [`14d7886`](https://github.com/vue-macros/vue-macros/commit/14d7886dc7db11eddad4b47b3f50a11fb6eff5fe) Thanks [@sxzz](https://github.com/sxzz)! - resolve TS function type
-
-- Updated dependencies [[`2cd0c5b`](https://github.com/vue-macros/vue-macros/commit/2cd0c5b332ee2040250dea832d9883f0b598df8c), [`5d65f5b`](https://github.com/vue-macros/vue-macros/commit/5d65f5b5a4d774c02346965ed8020425fa3a0986), [`14d7886`](https://github.com/vue-macros/vue-macros/commit/14d7886dc7db11eddad4b47b3f50a11fb6eff5fe)]:
- - @vue-macros/common@1.2.0
- - @vue-macros/api@0.5.1
-
-## 1.5.0
-
-### Minor Changes
-
-- [`9335bfd`](https://github.com/vue-macros/vue-macros/commit/9335bfdec453b27f16558b3fd277633b3f8e2ef4) Thanks [@sxzz](https://github.com/sxzz)! - support union key (TSMappedType)
-
-### Patch Changes
-
-- [`d944bb0`](https://github.com/vue-macros/vue-macros/commit/d944bb0e57bbf3a742f72a4776d582f52410a71f) Thanks [@sxzz](https://github.com/sxzz)! - tidy virtual module id
-
-- Updated dependencies [[`9335bfd`](https://github.com/vue-macros/vue-macros/commit/9335bfdec453b27f16558b3fd277633b3f8e2ef4)]:
- - @vue-macros/api@0.5.0
-
-## 1.4.2
-
-### Patch Changes
-
-- [`f2df923`](https://github.com/vue-macros/vue-macros/commit/f2df923d4c10a70d38c54fef8fd27964eff2a6f4) Thanks [@sxzz](https://github.com/sxzz)! - resolve union event name for `api` and `betterDefine`, fix https://github.com/vuejs/core/issues/7943
-
-- Updated dependencies [[`f2df923`](https://github.com/vue-macros/vue-macros/commit/f2df923d4c10a70d38c54fef8fd27964eff2a6f4), [`e06c3d1`](https://github.com/vue-macros/vue-macros/commit/e06c3d18062c6052cff97b59a6e98215581d5808)]:
- - @vue-macros/api@0.4.10
- - @vue-macros/common@1.1.4
-
-## 1.4.1
-
-### Patch Changes
-
-- Updated dependencies [[`ceb4fba`](https://github.com/vue-macros/vue-macros/commit/ceb4fbae7e2a90d3421b1357159d3d6f632947f1)]:
- - @vue-macros/common@1.1.3
- - @vue-macros/api@0.4.9
-
-## 1.4.0
-
-### Minor Changes
-
-- [`e5c4f66`](https://github.com/vue-macros/vue-macros/commit/e5c4f66e9a3f2382c50cb9f083413303a0a582e3) Thanks [@sxzz](https://github.com/sxzz)! - export all apis
-
-### Patch Changes
-
-- [`c3190f1`](https://github.com/vue-macros/vue-macros/commit/c3190f1011aaca57651d86c1121c7a48ac72d812) Thanks [@sxzz](https://github.com/sxzz)! - exports all files
-
-- [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425) Thanks [@sxzz](https://github.com/sxzz)! - simplify plugin options
-
-- Updated dependencies [[`40ecab4`](https://github.com/vue-macros/vue-macros/commit/40ecab454b6db796e316e3c591b3c21777ea56d3), [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425)]:
- - @vue-macros/common@1.1.2
- - @vue-macros/api@0.4.8
-
-## 1.3.7
-
-### Patch Changes
-
-- [`2dff8b2`](https://github.com/vue-macros/vue-macros/commit/2dff8b27b3ab05a73a28c247bd339f3f9fef3104) Thanks [@sxzz](https://github.com/sxzz)! - fix rollup resolve
-
-- [`82494e5`](https://github.com/vue-macros/vue-macros/commit/82494e58b6eb972257913d3cb8cebe2eb2881736) Thanks [@sxzz](https://github.com/sxzz)! - fallback to null when cannot resolve
-
-- Updated dependencies [[`2dff8b2`](https://github.com/vue-macros/vue-macros/commit/2dff8b27b3ab05a73a28c247bd339f3f9fef3104), [`82494e5`](https://github.com/vue-macros/vue-macros/commit/82494e58b6eb972257913d3cb8cebe2eb2881736)]:
- - @vue-macros/api@0.4.7
-
-## 1.3.6
-
-### Patch Changes
-
-- [`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480) Thanks [@sxzz](https://github.com/sxzz)! - rename helper name
-
-- Updated dependencies [[`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480)]:
- - @vue-macros/common@1.1.1
- - @vue-macros/api@0.4.6
-
-## 1.3.5
-
-### Patch Changes
-
-- [`8d919f8`](https://github.com/vue-macros/vue-macros/commit/8d919f81f99b7f4855b52f1a5edd7f3cee117d77) Thanks [@sxzz](https://github.com/sxzz)! - infer TS `Extract` and `Exclude` runtime type
-
-- Updated dependencies [[`8d919f8`](https://github.com/vue-macros/vue-macros/commit/8d919f81f99b7f4855b52f1a5edd7f3cee117d77)]:
- - @vue-macros/api@0.4.5
-
-## 1.3.4
-
-### Patch Changes
-
-- [`f40d270`](https://github.com/vue-macros/vue-macros/commit/f40d2701239967cfc288def57bc8b32ef57fad7e) Thanks [@sxzz](https://github.com/sxzz)! - resolve pkg typing entry
- support dts file parsing
-- Updated dependencies [[`f40d270`](https://github.com/vue-macros/vue-macros/commit/f40d2701239967cfc288def57bc8b32ef57fad7e)]:
- - @vue-macros/common@1.1.0
- - @vue-macros/api@0.4.4
-
-## 1.3.3
-
-### Patch Changes
-
-- [`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242) Thanks [@sxzz](https://github.com/sxzz)! - tidy package manifests
-
-- Updated dependencies [[`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242)]:
- - @vue-macros/common@1.0.1
- - @vue-macros/api@0.4.3
-
-## 1.3.2
-
-### Patch Changes
-
-- [`4844ebd`](https://github.com/vue-macros/vue-macros/commit/4844ebd8a8846682ee7c3717426fdeaae85fd39f) Thanks [@sxzz](https://github.com/sxzz)! - support mixed setup blocks for `better-define`
-
-- Updated dependencies [[`4844ebd`](https://github.com/vue-macros/vue-macros/commit/4844ebd8a8846682ee7c3717426fdeaae85fd39f)]:
- - @vue-macros/api@0.4.2
-
-## 1.3.1
-
-### Patch Changes
-
-- [`66d7c24`](https://github.com/vue-macros/vue-macros/commit/66d7c2472aa969d80e00218ee84858c255f549f5) Thanks [@sxzz](https://github.com/sxzz)! - resolve interface declarations
-
-- Updated dependencies [[`66d7c24`](https://github.com/vue-macros/vue-macros/commit/66d7c2472aa969d80e00218ee84858c255f549f5)]:
- - @vue-macros/api@0.4.1
-
-## 1.3.0
-
-### Minor Changes
-
-- [`37f4fd3`](https://github.com/vue-macros/vue-macros/commit/37f4fd3637f40d1734a49f044a06bddc52cf9a07) Thanks [@sxzz](https://github.com/sxzz)! - support union types
-
-### Patch Changes
-
-- [`2a6e990`](https://github.com/vue-macros/vue-macros/commit/2a6e990be6fc523c4b43f21a1773250ce8c88273) Thanks [@sxzz](https://github.com/sxzz)! - support union & intersection mixed types for betterDefine
-
-- Updated dependencies [[`2a6e990`](https://github.com/vue-macros/vue-macros/commit/2a6e990be6fc523c4b43f21a1773250ce8c88273), [`37f4fd3`](https://github.com/vue-macros/vue-macros/commit/37f4fd3637f40d1734a49f044a06bddc52cf9a07)]:
- - @vue-macros/api@0.4.0
-
-## 1.2.0
-
-### Minor Changes
-
-- [`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862) Thanks [@sxzz](https://github.com/sxzz)! - support TypeScript 5.0
-
-### Patch Changes
-
-- Updated dependencies [[`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862), [`c91cb0f`](https://github.com/vue-macros/vue-macros/commit/c91cb0f761a06d0b5e6b7ef662824773cb4a2e61)]:
- - @vue-macros/common@1.0.0
- - @vue-macros/api@0.3.0
-
-## 1.1.11
-
-### Patch Changes
-
-- Updated dependencies [[`75bda71`](https://github.com/vue-macros/vue-macros/commit/75bda71e3bc5b82e2f88234563cfefe535fceb88)]:
- - @vue-macros/common@0.15.0
- - @vue-macros/api@0.2.8
-
-## 1.1.10
-
-### Patch Changes
-
-- [`a24f0d3`](https://github.com/vue-macros/vue-macros/commit/a24f0d398cf0c6dd0bd9d0706f89fae52d5bc620) Thanks [@sxzz](https://github.com/sxzz)! - optional method props
-
-- Updated dependencies [[`a24f0d3`](https://github.com/vue-macros/vue-macros/commit/a24f0d398cf0c6dd0bd9d0706f89fae52d5bc620)]:
- - @vue-macros/api@0.2.7
-
-## 1.1.9
-
-### Patch Changes
-
-- [`0ec95df`](https://github.com/vue-macros/vue-macros/commit/0ec95df76457c21da07e38af6d2123d95cc2903b) Thanks [@sxzz](https://github.com/sxzz)! - fix cycle imports on HMR
-
-## 1.1.8
-
-### Patch Changes
-
-- [`9432d0d`](https://github.com/vue-macros/vue-macros/commit/9432d0d9521278e318cff0f793c3f054d173e764) Thanks [@sxzz](https://github.com/sxzz)! - escape prop key
-
-## 1.1.7
-
-### Patch Changes
-
-- Updated dependencies [[`af45741`](https://github.com/vue-macros/vue-macros/commit/af4574121dd43957343669fdc4051fb452a23e6b)]:
- - @vue-macros/common@0.14.0
- - @vue-macros/api@0.2.6
-
-## 1.1.6
-
-### Patch Changes
-
-- [`ca7e5b0`](https://github.com/vue-macros/vue-macros/commit/ca7e5b01f32b6211204c9ea72131059414172104) Thanks [@sxzz](https://github.com/sxzz)! - catch errors when resolve failed
-
-## 1.1.5
-
-### Patch Changes
-
-- [#210](https://github.com/vue-macros/vue-macros/pull/210) [`a673932`](https://github.com/vue-macros/vue-macros/commit/a673932d712f235c6ba98b38222306a7695ef1d7) Thanks [@alexzhang1030](https://github.com/alexzhang1030)! - fix cannot import type from vue file
-
-- Updated dependencies [[`a673932`](https://github.com/vue-macros/vue-macros/commit/a673932d712f235c6ba98b38222306a7695ef1d7)]:
- - @vue-macros/api@0.2.5
- - @vue-macros/common@0.13.8
-
-## 1.1.4
-
-### Patch Changes
-
-- Updated dependencies [[`7829161`](https://github.com/vue-macros/vue-macros/commit/7829161929733ce4e094d5c567ef8fbba9675168), [`3010b1e`](https://github.com/vue-macros/vue-macros/commit/3010b1ea9bc81bb7e09b5155f4b1695c6457a2db)]:
- - @vue-macros/common@0.13.7
- - @vue-macros/api@0.2.4
-
-## 1.1.3
-
-### Patch Changes
-
-- Updated dependencies [[`b9218d4`](https://github.com/vue-macros/vue-macros/commit/b9218d45db8845a8ea44b1e825cdd97c7adb7a7d), [`af9978b`](https://github.com/vue-macros/vue-macros/commit/af9978bac81a9fa8e5fb09feefea704d6cde5ecf), [`fa6b968`](https://github.com/vue-macros/vue-macros/commit/fa6b9682f33812c99117515ea98471e534b28da4)]:
- - @vue-macros/common@0.13.6
- - @vue-macros/api@0.2.3
-
-## 1.1.2
-
-### Patch Changes
-
-- [`7776ab0`](https://github.com/vue-macros/vue-macros/commit/7776ab0706715c9f67dc255e56446a2d049c620b) Thanks [@sxzz](https://github.com/sxzz)! - support resolving dts file
-
-- Updated dependencies [[`7776ab0`](https://github.com/vue-macros/vue-macros/commit/7776ab0706715c9f67dc255e56446a2d049c620b)]:
- - @vue-macros/api@0.2.2
-
-## 1.1.1
-
-### Patch Changes
-
-- Updated dependencies [[`d81825a`](https://github.com/vue-macros/vue-macros/commit/d81825a9bbe003f5af4ee3858241cc5bdb8f264f)]:
- - @vue-macros/common@0.13.5
- - @vue-macros/api@0.2.1
-
-## 1.1.0
-
-### Minor Changes
-
-- [#177](https://github.com/vue-macros/vue-macros/pull/177) [`934d5f8`](https://github.com/vue-macros/vue-macros/commit/934d5f8e935fc6ee0a4b3846e183b6611e10c571) Thanks [@sxzz](https://github.com/sxzz)! - Support Vite 4
- Drop Rollup 2
-
-## 1.0.0
-
-### Major Changes
-
-- [`15f3d42`](https://github.com/vue-macros/vue-macros/commit/15f3d42db5219c849f1248a881db8329e5b4b87c) Thanks [@sxzz](https://github.com/sxzz)! - make it stable. NOTHING changed.
-
-## 0.2.1
-
-### Patch Changes
-
-- [`2fa0808`](https://github.com/vue-macros/vue-macros/commit/2fa080844d4b6ecb0e3c346d6f490a7484c530cd) Thanks [@sxzz](https://github.com/sxzz)! - fix HMR
-
-## 0.2.0
-
-### Minor Changes
-
-- [`c7a60bf`](https://github.com/vue-macros/vue-macros/commit/c7a60bfd35f3123390c702a6ac754ebbd6750b1f) Thanks [@sxzz](https://github.com/sxzz)! - support vite hmr
-
-- [`419d2d2`](https://github.com/vue-macros/vue-macros/commit/419d2d21e0e01108abb6f628b4546c1c29077002) Thanks [@sxzz](https://github.com/sxzz)! - improve production mode
-
-### Patch Changes
-
-- Updated dependencies [[`419d2d2`](https://github.com/vue-macros/vue-macros/commit/419d2d21e0e01108abb6f628b4546c1c29077002)]:
- - @vue-macros/api@0.2.0
- - @vue-macros/common@0.13.4
-
-## 0.1.0
-
-### Minor Changes
-
-- [`43f7e6b`](https://github.com/vue-macros/vue-macros/commit/43f7e6bf3dc3164c7da54174abc225f973ba8460) Thanks [@sxzz](https://github.com/sxzz)! - support vite resolve alias for betterDefine
-
-## 0.0.4
-
-### Patch Changes
-
-- Updated dependencies [[`b7998af`](https://github.com/vue-macros/vue-macros/commit/b7998afd69a0c8f8a619fab9a379c15ba4ad889f), [`d889b02`](https://github.com/vue-macros/vue-macros/commit/d889b028adb80ef02a2c17b7b7d687688cb5d5e5)]:
- - @vue-macros/common@0.13.3
- - @vue-macros/api@0.1.2
-
-## 0.0.3
-
-### Patch Changes
-
-- [`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137) Thanks [@sxzz](https://github.com/sxzz)! - support context in setupComponent
-
-- Updated dependencies [[`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137)]:
- - @vue-macros/api@0.1.1
- - @vue-macros/common@0.13.2
-
-## 0.0.2
-
-### Patch Changes
-
-- [`b5fa188`](https://github.com/vue-macros/vue-macros/commit/b5fa18833b2262e9e416af7e96f83391efc877bb) Thanks [@sxzz](https://github.com/sxzz)! - support dynamic default definitions of props
-
-- Updated dependencies [[`e1f7bdc`](https://github.com/vue-macros/vue-macros/commit/e1f7bdca122b07a64d2da0227b7ed7450cc9d8d0), [`385d9bb`](https://github.com/vue-macros/vue-macros/commit/385d9bbea219192d69ffc7396a7f288182de7813), [`91dfbff`](https://github.com/vue-macros/vue-macros/commit/91dfbff9918c7289f744cdd00e4b14a7fec2ee98), [`b5fa188`](https://github.com/vue-macros/vue-macros/commit/b5fa18833b2262e9e416af7e96f83391efc877bb)]:
- - @vue-macros/api@0.1.0
- - @vue-macros/common@0.13.1
-
-## 0.0.1
-
-### Patch Changes
-
-- [#126](https://github.com/vue-macros/vue-macros/pull/126) [`d88fe67`](https://github.com/vue-macros/vue-macros/commit/d88fe674258c2d9d418d5b2e56aea6f70a199776) Thanks [@sxzz](https://github.com/sxzz)! - add better define
-
-- Updated dependencies [[`d88fe67`](https://github.com/vue-macros/vue-macros/commit/d88fe674258c2d9d418d5b2e56aea6f70a199776)]:
- - @vue-macros/common@0.13.0
- - @vue-macros/api@0.0.1
diff --git a/packages/better-define/package.json b/packages/better-define/package.json
index 7cfb99bbf..578e11955 100644
--- a/packages/better-define/package.json
+++ b/packages/better-define/package.json
@@ -1,8 +1,8 @@
{
"name": "@vue-macros/better-define",
- "version": "1.6.6",
- "packageManager": "pnpm@8.6.10",
- "description": "better-define feature from Vue Macros.",
+ "version": "3.0.0-beta.21",
+ "description": "betterDefine feature from Vue Macros.",
+ "type": "module",
"keywords": [
"vue-macros",
"macros",
@@ -14,7 +14,7 @@
"unplugin"
],
"license": "MIT",
- "homepage": "https://github.com/vue-macros/vue-macros#readme",
+ "homepage": "https://vue-macros.dev",
"bugs": {
"url": "https://github.com/vue-macros/vue-macros/issues"
},
@@ -23,72 +23,48 @@
"url": "git+https://github.com/vue-macros/vue-macros.git",
"directory": "packages/better-define"
},
- "author": "三咲智子 ",
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
"files": [
"dist"
],
- "main": "dist/index.js",
- "module": "dist/index.mjs",
- "types": "dist/index.d.ts",
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
"exports": {
".": {
"dev": "./src/index.ts",
- "types": {
- "require": "./dist/index.d.ts",
- "import": "./dist/index.d.mts"
- },
- "require": "./dist/index.js",
- "import": "./dist/index.mjs"
+ "default": "./dist/index.js"
},
"./api": {
"dev": "./src/api.ts",
- "types": {
- "require": "./dist/api.d.ts",
- "import": "./dist/api.d.mts"
- },
- "require": "./dist/api.js",
- "import": "./dist/api.mjs"
+ "default": "./dist/api.js"
},
"./esbuild": {
"dev": "./src/esbuild.ts",
- "types": {
- "require": "./dist/esbuild.d.ts",
- "import": "./dist/esbuild.d.mts"
- },
- "require": "./dist/esbuild.js",
- "import": "./dist/esbuild.mjs"
+ "default": "./dist/esbuild.js"
+ },
+ "./rolldown": {
+ "dev": "./src/rolldown.ts",
+ "default": "./dist/rolldown.js"
},
"./rollup": {
"dev": "./src/rollup.ts",
- "types": {
- "require": "./dist/rollup.d.ts",
- "import": "./dist/rollup.d.mts"
- },
- "require": "./dist/rollup.js",
- "import": "./dist/rollup.mjs"
+ "default": "./dist/rollup.js"
+ },
+ "./rspack": {
+ "dev": "./src/rspack.ts",
+ "default": "./dist/rspack.js"
},
"./vite": {
"dev": "./src/vite.ts",
- "types": {
- "require": "./dist/vite.d.ts",
- "import": "./dist/vite.d.mts"
- },
- "require": "./dist/vite.js",
- "import": "./dist/vite.mjs"
+ "default": "./dist/vite.js"
},
"./webpack": {
"dev": "./src/webpack.ts",
- "types": {
- "require": "./dist/webpack.d.ts",
- "import": "./dist/webpack.d.mts"
- },
- "require": "./dist/webpack.js",
- "import": "./dist/webpack.mjs"
+ "default": "./dist/webpack.js"
},
- "./*": [
- "./*",
- "./*.d.ts"
- ]
+ "./*": "./*"
},
"typesVersions": {
"*": {
@@ -98,19 +74,29 @@
]
}
},
- "scripts": {
- "build": "tsup && tsx ../../scripts/postbuild.ts",
- "dev": "DEV=true tsup"
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./api": "./dist/api.js",
+ "./esbuild": "./dist/esbuild.js",
+ "./rolldown": "./dist/rolldown.js",
+ "./rollup": "./dist/rollup.js",
+ "./rspack": "./dist/rspack.js",
+ "./vite": "./dist/vite.js",
+ "./webpack": "./dist/webpack.js",
+ "./*": "./*"
+ },
+ "tag": "next"
},
+ "scripts": {},
"dependencies": {
"@vue-macros/api": "workspace:*",
"@vue-macros/common": "workspace:*",
- "unplugin": "^1.4.0"
- },
- "devDependencies": {
- "rollup": "^3.26.3"
+ "neverthrow": "catalog:",
+ "unplugin": "catalog:"
},
"engines": {
- "node": ">=16.14.0"
+ "node": ">=20.18.0"
}
}
diff --git a/packages/better-define/src/core/index.ts b/packages/better-define/src/core/index.ts
index db7cbfdfc..c86d1955a 100644
--- a/packages/better-define/src/core/index.ts
+++ b/packages/better-define/src/core/index.ts
@@ -1,83 +1,94 @@
+import {
+ analyzeSFC,
+ genRuntimePropDefinition,
+ type ResultAsync,
+ type TSEmits,
+ type TSProps,
+} from '@vue-macros/api'
import {
DEFINE_EMITS,
- MagicString,
escapeKey,
- getTransformResult,
+ generateTransform,
importHelperFn,
+ MagicStringAST,
parseSFC,
+ type CodeTransform,
} from '@vue-macros/common'
-import {
- type TSEmits,
- type TSProps,
- analyzeSFC,
- genRuntimePropDefinition,
-} from '@vue-macros/api'
+import { ok, safeTry } from 'neverthrow'
-export async function transformBetterDefine(
+export function transformBetterDefine(
code: string,
id: string,
- isProduction = false
-) {
- const s = new MagicString(code)
- const sfc = parseSFC(code, id)
- if (!sfc.scriptSetup) return
+ isProduction = false,
+): ResultAsync {
+ return safeTry(async function* () {
+ const s = new MagicStringAST(code)
+ const sfc = parseSFC(code, id)
+ if (!sfc.scriptSetup) return ok()
- const offset = sfc.scriptSetup.loc.start.offset
- const result = await analyzeSFC(s, sfc)
- if (result.props) {
- await processProps(result.props)
- }
- if (result.emits) {
- processEmits(result.emits)
- }
+ const offset = sfc.scriptSetup.loc.start.offset
+ const result = yield* analyzeSFC(s, sfc)
+ if (result.props) {
+ yield* processProps(result.props)
+ }
+ if (result.emits) {
+ processEmits(result.emits)
+ }
- return getTransformResult(s, id)
+ return ok(generateTransform(s, id))
- async function processProps(props: TSProps) {
- const runtimeDefs = await props.getRuntimeDefinitions()
+ function processProps(props: TSProps) {
+ return safeTry(async function* () {
+ const runtimeDefs = yield* props.getRuntimeDefinitions()
- const runtimeDecls = `{\n ${Object.entries(runtimeDefs)
- .map(([key, { type, required, default: defaultDecl }]) => {
- let defaultString = ''
- if (defaultDecl) defaultString = defaultDecl('default')
+ const runtimeDecls = `{\n ${Object.entries(runtimeDefs)
+ .map(([key, { type, required, default: defaultDecl }]) => {
+ let defaultString = ''
+ if (defaultDecl) defaultString = defaultDecl('default')
- const properties: string[] = []
- if (!isProduction) properties.push(`required: ${required}`)
- if (defaultString) properties.push(defaultString)
+ const properties: string[] = []
+ if (!isProduction) properties.push(`required: ${required}`)
+ if (defaultString) properties.push(defaultString)
- return `${escapeKey(key)}: ${genRuntimePropDefinition(
- type,
- isProduction,
- properties
- )}`
- })
- .join(',\n ')}\n}`
+ return `${escapeKey(key)}: ${genRuntimePropDefinition(
+ type,
+ isProduction,
+ properties,
+ )}`
+ })
+ .join(',\n ')}\n}`
- let decl = runtimeDecls
- if (props.withDefaultsAst && !props.defaults) {
- // dynamic defaults
- decl = `${importHelperFn(
- s,
- offset,
- 'mergeDefaults'
- )}(${decl}, ${s.sliceNode(props.withDefaultsAst.arguments[1], {
- offset,
- })})`
- // add helper
- }
- decl = `defineProps(${decl})`
+ let decl = runtimeDecls
+ if (props.withDefaultsAst && !props.defaults) {
+ // dynamic defaults
+ decl = `${importHelperFn(
+ s,
+ offset,
+ 'mergeDefaults',
+ )}(${decl}, ${s.sliceNode(props.withDefaultsAst.arguments[1], {
+ offset,
+ })})`
+ // add helper
+ }
+ decl = `defineProps(${decl})`
- s.overwriteNode(props.withDefaultsAst || props.definePropsAst, decl, {
- offset,
- })
- }
+ s.overwriteNode(props.withDefaultsAst || props.definePropsAst, decl, {
+ offset,
+ })
- function processEmits(emits: TSEmits) {
- const runtimeDecls = `[${Object.keys(emits.definitions)
- .map((name) => JSON.stringify(name))
- .join(', ')}]`
- s.overwriteNode(emits.defineEmitsAst, `${DEFINE_EMITS}(${runtimeDecls})`, {
- offset,
- })
- }
+ return ok()
+ })
+ }
+
+ function processEmits(emits: TSEmits) {
+ const runtimeDecls = `[${Object.keys(emits.definitions)
+ .map((name) => JSON.stringify(name))
+ .join(', ')}]`
+ s.overwriteNode(
+ emits.defineEmitsAst,
+ `${DEFINE_EMITS}(${runtimeDecls})`,
+ { offset },
+ )
+ }
+ })
}
diff --git a/packages/better-define/src/esbuild.ts b/packages/better-define/src/esbuild.ts
index 71f1e0952..e8c6460dd 100644
--- a/packages/better-define/src/esbuild.ts
+++ b/packages/better-define/src/esbuild.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.esbuild
+export default unplugin.esbuild as typeof unplugin.esbuild
diff --git a/packages/better-define/src/index.ts b/packages/better-define/src/index.ts
index 5e5e0b663..faf9c6eb9 100644
--- a/packages/better-define/src/index.ts
+++ b/packages/better-define/src/index.ts
@@ -1,76 +1,74 @@
-import { createUnplugin } from 'unplugin'
+import process from 'node:process'
+import { resolveDtsHMR } from '@vue-macros/api'
import {
- type BaseOptions,
- type MarkRequired,
- REGEX_SETUP_SFC,
- REGEX_VUE_SFC,
- REGEX_VUE_SUB,
createFilter,
detectVueVersion,
+ FilterFileType,
+ getFilterPattern,
+ type BaseOptions,
+ type MarkRequired,
} from '@vue-macros/common'
-import { RollupResolve, setResolveTSFileIdImpl } from '@vue-macros/api'
-import { type PluginContext } from 'rollup'
+import { generatePluginName } from '#macros' with { type: 'macro' }
+import {
+ createUnplugin,
+ type UnpluginContextMeta,
+ type UnpluginInstance,
+} from 'unplugin'
import { transformBetterDefine } from './core'
-export interface Options extends BaseOptions {
- isProduction?: boolean
-}
-
+export type Options = BaseOptions
export type OptionsResolved = MarkRequired<
Options,
'include' | 'version' | 'isProduction'
>
-function resolveOptions(options: Options): OptionsResolved {
+function resolveOptions(
+ options: Options,
+ framework: UnpluginContextMeta['framework'],
+): OptionsResolved {
const version = options.version || detectVueVersion()
-
+ const include = getFilterPattern(
+ [FilterFileType.VUE_SFC_WITH_SETUP, FilterFileType.SETUP_SFC],
+ framework,
+ )
return {
- include: [REGEX_VUE_SFC, REGEX_SETUP_SFC, REGEX_VUE_SUB],
+ include,
isProduction: process.env.NODE_ENV === 'production',
...options,
version,
}
}
-const name = 'unplugin-vue-better-define'
+const name = generatePluginName()
-export default createUnplugin(
+const plugin: UnpluginInstance = createUnplugin(
(userOptions = {}, { framework }) => {
- const options = resolveOptions(userOptions)
+ const options = resolveOptions(userOptions, framework)
const filter = createFilter(options)
- const { resolve, handleHotUpdate } = RollupResolve()
-
return {
name,
enforce: 'pre',
- buildStart() {
- if (framework === 'rollup' || framework === 'vite') {
- setResolveTSFileIdImpl(resolve(this as PluginContext))
- }
- },
-
- transformInclude(id) {
- return filter(id)
- },
-
- async transform(code, id) {
- try {
- return await transformBetterDefine(code, id, options.isProduction)
- } catch (err: unknown) {
- this.warn(`${name} ${err}`)
- console.warn(err)
- }
+ transformInclude: filter,
+ transform(code, id) {
+ return transformBetterDefine(code, id, options.isProduction).match(
+ (res) => res,
+ (error) => {
+ this.warn(`${name} ${error}`)
+ console.warn(error)
+ },
+ )
},
vite: {
configResolved(config) {
- options.isProduction = config.isProduction
+ options.isProduction ??= config.isProduction
},
- handleHotUpdate,
+ handleHotUpdate: resolveDtsHMR,
},
}
- }
+ },
)
+export default plugin
diff --git a/packages/better-define/src/rolldown.ts b/packages/better-define/src/rolldown.ts
new file mode 100644
index 000000000..082a55c18
--- /dev/null
+++ b/packages/better-define/src/rolldown.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rolldown as typeof unplugin.rolldown
diff --git a/packages/better-define/src/rollup.ts b/packages/better-define/src/rollup.ts
index ed6909cd3..45545feb1 100644
--- a/packages/better-define/src/rollup.ts
+++ b/packages/better-define/src/rollup.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.rollup
+export default unplugin.rollup as typeof unplugin.rollup
diff --git a/packages/better-define/src/rspack.ts b/packages/better-define/src/rspack.ts
new file mode 100644
index 000000000..6df8a0299
--- /dev/null
+++ b/packages/better-define/src/rspack.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rspack as typeof unplugin.rspack
diff --git a/packages/better-define/src/vite.ts b/packages/better-define/src/vite.ts
index 589f4b964..a7c5db2c1 100644
--- a/packages/better-define/src/vite.ts
+++ b/packages/better-define/src/vite.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.vite
+export default unplugin.vite as typeof unplugin.vite
diff --git a/packages/better-define/src/webpack.ts b/packages/better-define/src/webpack.ts
index 83091ee31..74c1c9020 100644
--- a/packages/better-define/src/webpack.ts
+++ b/packages/better-define/src/webpack.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.webpack
+export default unplugin.webpack as typeof unplugin.webpack
diff --git a/packages/better-define/tests/__snapshots__/fixtures.test.ts.snap b/packages/better-define/tests/__snapshots__/fixtures.test.ts.snap
index ffaec1dd9..317d06727 100644
--- a/packages/better-define/tests/__snapshots__/fixtures.test.ts.snap
+++ b/packages/better-define/tests/__snapshots__/fixtures.test.ts.snap
@@ -1,76 +1,125 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`fixtures > tests/fixtures/basic.vue > isProduction = false 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// basic.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"basic\\",
- props: {
- base: { type: String, required: true },
- str: { type: String, required: true },
- num: { type: Number, required: true },
- map: { type: Map, required: true },
- arr: { type: Array, required: true },
- union: { type: [String, Number], required: true }
- },
- emits: [\\"click\\", \\"change\\"],
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "basic",
+ props: {
+ base: {
+ type: String,
+ required: true
+ },
+ str: {
+ type: String,
+ required: true
+ },
+ num: {
+ type: Number,
+ required: true
+ },
+ map: {
+ type: Map,
+ required: true
+ },
+ arr: {
+ type: Array,
+ required: true
+ },
+ union: {
+ type: [String, Number],
+ required: true
+ }
+ },
+ emits: ["click", "change"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var basic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var basic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { basic as default };
"
`;
exports[`fixtures > tests/fixtures/basic.vue > isProduction = true 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// basic.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"basic\\",
- props: {
- base: null,
- str: null,
- num: null,
- map: null,
- arr: null,
- union: null
- },
- emits: [\\"click\\", \\"change\\"],
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "basic",
+ props: {
+ base: null,
+ str: null,
+ num: null,
+ map: null,
+ arr: null,
+ union: null
+ },
+ emits: ["click", "change"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var basic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var basic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { basic as default };
"
`;
exports[`fixtures > tests/fixtures/built-in.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// built-in.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"built-in\\",
- props: {
- optional: { type: Number, required: false },
- required: { type: Boolean, required: true },
- readonly: { type: String, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "built-in",
+ props: {
+ optional: {
+ type: Number,
+ required: false
+ },
+ required: {
+ type: Boolean,
+ required: true
+ },
+ readonly: {
+ type: String,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var builtIn = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -80,20 +129,26 @@ export { builtIn as default };
`;
exports[`fixtures > tests/fixtures/built-in.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// built-in.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"built-in\\",
- props: {
- optional: null,
- required: { type: Boolean },
- readonly: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "built-in",
+ props: {
+ optional: null,
+ required: { type: Boolean },
+ readonly: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var builtIn = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -103,130 +158,234 @@ export { builtIn as default };
`;
exports[`fixtures > tests/fixtures/defaults-dynamic.vue > isProduction = false 1`] = `
-"import { defineComponent, mergeDefaults, openBlock, createElementBlock } from 'vue';
+"// defaults-dynamic.js
+import { defineComponent, mergeDefaults, createElementBlock, openBlock } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"defaults-dynamic\\",
- props: mergeDefaults({
- foo: { type: String, required: false }
- }, {
- [\\"foo\\"]: \\"foo\\"
- }),
- setup(__props) {
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(\\"div\\");
- };
- }
+ __name: "defaults-dynamic",
+ props: mergeDefaults({ foo: {
+ type: String,
+ required: false
+ } }, { ["f" + "oo"]: "foo" }),
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var defaultsDynamic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("div");
+}
+var defaultsDynamic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { defaultsDynamic as default };
"
`;
exports[`fixtures > tests/fixtures/defaults-dynamic.vue > isProduction = true 1`] = `
-"import { defineComponent, mergeDefaults, openBlock, createElementBlock } from 'vue';
+"// defaults-dynamic.js
+import { defineComponent, mergeDefaults, createElementBlock, openBlock } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"defaults-dynamic\\",
- props: mergeDefaults({
- foo: null
- }, {
- [\\"foo\\"]: \\"foo\\"
- }),
- setup(__props) {
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(\\"div\\");
- };
- }
+ __name: "defaults-dynamic",
+ props: mergeDefaults({ foo: null }, { ["f" + "oo"]: "foo" }),
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var defaultsDynamic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("div");
+}
+var defaultsDynamic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { defaultsDynamic as default };
"
`;
exports[`fixtures > tests/fixtures/defaults-static.vue > isProduction = false 1`] = `
-"import { defineComponent, openBlock, createElementBlock } from 'vue';
+"// defaults-static.js
+import { defineComponent, createElementBlock, openBlock } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"defaults-static\\",
- props: {
- foo: { type: String, required: false, default: \\"foo\\" },
- bar: { type: Number, required: false, get default() {
- return 10;
- } },
- baz: { type: Promise, required: false, async default() {
- return 10;
- } },
- qux: { type: Function, required: false, default: () => {
- } },
- quux: { required: false, default: abc }
- },
- setup(__props) {
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(\\"div\\");
- };
- }
+ __name: "defaults-static",
+ props: {
+ foo: {
+ type: String,
+ required: false,
+ default: "foo"
+ },
+ bar: {
+ type: Number,
+ required: false,
+ get default() {
+ return 10;
+ }
+ },
+ baz: {
+ type: Promise,
+ required: false,
+ async default() {
+ return 10;
+ }
+ },
+ qux: {
+ type: Function,
+ required: false,
+ default: () => {}
+ },
+ quux: {
+ required: false,
+ default: abc
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var defaultsStatic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("div");
+}
+var defaultsStatic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { defaultsStatic as default };
"
`;
exports[`fixtures > tests/fixtures/defaults-static.vue > isProduction = true 1`] = `
-"import { defineComponent, openBlock, createElementBlock } from 'vue';
+"// defaults-static.js
+import { defineComponent, createElementBlock, openBlock } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"defaults-static\\",
- props: {
- foo: { default: \\"foo\\" },
- bar: { get default() {
- return 10;
- } },
- baz: { async default() {
- return 10;
- } },
- qux: { type: Function, default: () => {
- } },
- quux: { default: abc }
- },
- setup(__props) {
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(\\"div\\");
- };
- }
+ __name: "defaults-static",
+ props: {
+ foo: { default: "foo" },
+ bar: { get default() {
+ return 10;
+ } },
+ baz: { async default() {
+ return 10;
+ } },
+ qux: {
+ type: Function,
+ default: () => {}
+ },
+ quux: { default: abc }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var defaultsStatic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("div");
+}
+var defaultsStatic = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { defaultsStatic as default };
"
`;
+exports[`fixtures > tests/fixtures/err.vue > isProduction = false 1`] = `
+"// err.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "err",
+ setup(__props, { expose: __expose }) {
+ __expose();
+ // @ts-expect-error
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var err = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { err as default };
+"
+`;
+
+exports[`fixtures > tests/fixtures/err.vue > isProduction = true 1`] = `
+"// err.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "err",
+ setup(__props, { expose: __expose }) {
+ __expose();
+ // @ts-expect-error
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var err = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { err as default };
+"
+`;
+
exports[`fixtures > tests/fixtures/fn-default.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// fn-default.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"fn-default\\",
- props: {
- fn: { type: Function, required: true, default: () => {
- } }
- },
- setup(__props) {
- const props = __props;
- return () => {
- };
- }
+ __name: "fn-default",
+ props: { fn: {
+ type: Function,
+ required: true,
+ default: () => {}
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = { props };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var fnDefault = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -236,20 +395,26 @@ export { fnDefault as default };
`;
exports[`fixtures > tests/fixtures/fn-default.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// fn-default.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"fn-default\\",
- props: {
- fn: { type: Function, default: () => {
- } }
- },
- setup(__props) {
- const props = __props;
- return () => {
- };
- }
+ __name: "fn-default",
+ props: { fn: {
+ type: Function,
+ default: () => {}
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = { props };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var fnDefault = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -259,178 +424,277 @@ export { fnDefault as default };
`;
exports[`fixtures > tests/fixtures/import-from-vue.vue > isProduction = false 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// import-from-vue.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"import-from-vue\\",
- props: {
- setupBase: { type: String, required: true },
- num: { type: Number, required: true },
- bool: { type: Boolean, required: true },
- map: { type: Map, required: true },
- arr: { type: Array, required: true },
- union: { type: [String, Number], required: true },
- normalBase: { type: String, required: true },
- str: { type: String, required: true },
- setupBase_2: { type: String, required: true }
- },
- emits: [\\"click\\", \\"change\\"],
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "import-from-vue",
+ props: {
+ setupBase: {
+ type: String,
+ required: true
+ },
+ num: {
+ type: Number,
+ required: true
+ },
+ bool: {
+ type: Boolean,
+ required: true
+ },
+ map: {
+ type: Map,
+ required: true
+ },
+ arr: {
+ type: Array,
+ required: true
+ },
+ union: {
+ type: [String, Number],
+ required: true
+ },
+ normalBase: {
+ type: String,
+ required: true
+ },
+ str: {
+ type: String,
+ required: true
+ },
+ setupBase_2: {
+ type: String,
+ required: true
+ }
+ },
+ emits: ["click", "change"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var importFromVue = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var importFromVue = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { importFromVue as default };
"
`;
exports[`fixtures > tests/fixtures/import-from-vue.vue > isProduction = true 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// import-from-vue.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"import-from-vue\\",
- props: {
- setupBase: null,
- num: null,
- bool: { type: Boolean },
- map: null,
- arr: null,
- union: null,
- normalBase: null,
- str: null,
- setupBase_2: null
- },
- emits: [\\"click\\", \\"change\\"],
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "import-from-vue",
+ props: {
+ setupBase: null,
+ num: null,
+ bool: { type: Boolean },
+ map: null,
+ arr: null,
+ union: null,
+ normalBase: null,
+ str: null,
+ setupBase_2: null
+ },
+ emits: ["click", "change"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var importFromVue = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var importFromVue = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { importFromVue as default };
"
`;
exports[`fixtures > tests/fixtures/intersection.vue > isProduction = false 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// intersection.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"intersection\\",
- props: {
- base: { type: String, required: true },
- str: { type: String, required: true },
- num: { type: Number, required: true },
- map: { type: Map, required: true },
- arr: { type: Array, required: true },
- union: { type: [String, Number], required: true }
- },
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "intersection",
+ props: {
+ base: {
+ type: String,
+ required: true
+ },
+ str: {
+ type: String,
+ required: true
+ },
+ num: {
+ type: Number,
+ required: true
+ },
+ map: {
+ type: Map,
+ required: true
+ },
+ arr: {
+ type: Array,
+ required: true
+ },
+ union: {
+ type: [String, Number],
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var intersection = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var intersection = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { intersection as default };
"
`;
exports[`fixtures > tests/fixtures/intersection.vue > isProduction = true 1`] = `
-"import { defineComponent, renderSlot } from 'vue';
+"// intersection.js
+import { defineComponent, renderSlot } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"intersection\\",
- props: {
- base: null,
- str: null,
- num: null,
- map: null,
- arr: null,
- union: null
- },
- setup(__props) {
- return (_ctx, _cache) => {
- return renderSlot(_ctx.$slots, \\"default\\");
- };
- }
+ __name: "intersection",
+ props: {
+ base: null,
+ str: null,
+ num: null,
+ map: null,
+ arr: null,
+ union: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var intersection = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return renderSlot(_ctx.$slots, "default");
+}
+var intersection = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { intersection as default };
"
`;
exports[`fixtures > tests/fixtures/issue-260.vue > isProduction = false 1`] = `
-"import { defineComponent, toDisplayString } from 'vue';
+"// issue-260.js
+import { defineComponent, toDisplayString } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-260\\",
- props: {
- menu: { type: [Object, Array], required: false, default: () => ({ txt: \\"1-1\\" }) }
- },
- setup(__props) {
- const props = __props;
- return (_ctx, _cache) => {
- return toDisplayString(props.menu);
- };
- }
+ __name: "issue-260",
+ props: { menu: {
+ type: [Object, Array],
+ required: false,
+ default: () => ({ txt: "1-1" })
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = { props };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return toDisplayString($setup.props.menu);
+}
+var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { issue260 as default };
"
`;
exports[`fixtures > tests/fixtures/issue-260.vue > isProduction = true 1`] = `
-"import { defineComponent, toDisplayString } from 'vue';
+"// issue-260.js
+import { defineComponent, toDisplayString } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-260\\",
- props: {
- menu: { default: () => ({ txt: \\"1-1\\" }) }
- },
- setup(__props) {
- const props = __props;
- return (_ctx, _cache) => {
- return toDisplayString(props.menu);
- };
- }
+ __name: "issue-260",
+ props: { menu: { default: () => ({ txt: "1-1" }) } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = { props };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return toDisplayString($setup.props.menu);
+}
+var issue260 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { issue260 as default };
"
`;
exports[`fixtures > tests/fixtures/issue-328.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// issue-328.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-328\\",
- emits: [\\"foo\\"],
- setup(__props) {
- return () => {
- };
- }
+ __name: "issue-328",
+ emits: ["foo"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var issue328 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -440,16 +704,22 @@ export { issue328 as default };
`;
exports[`fixtures > tests/fixtures/issue-328.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// issue-328.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-328\\",
- emits: [\\"foo\\"],
- setup(__props) {
- return () => {
- };
- }
+ __name: "issue-328",
+ emits: ["foo"],
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var issue328 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -459,18 +729,25 @@ export { issue328 as default };
`;
exports[`fixtures > tests/fixtures/issue-351.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// issue-351.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-351\\",
- props: {
- modelValue: { type: [String, Boolean], required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "issue-351",
+ props: { modelValue: {
+ type: [String, Boolean],
+ required: true
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var issue351 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -480,18 +757,22 @@ export { issue351 as default };
`;
exports[`fixtures > tests/fixtures/issue-351.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// issue-351.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-351\\",
- props: {
- modelValue: { type: [String, Boolean] }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "issue-351",
+ props: { modelValue: { type: [String, Boolean] } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var issue351 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -501,88 +782,181 @@ export { issue351 as default };
`;
exports[`fixtures > tests/fixtures/issue-362.vue > isProduction = false 1`] = `
-"import { defineComponent, openBlock, createElementBlock, toDisplayString } from 'vue';
+"// issue-362.js
+import { defineComponent, createElementBlock, openBlock, toDisplayString } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-362\\",
- props: {
- trigger: { required: true }
- },
- setup(__props) {
- const props = __props;
- const Trigger = {
- click: \\"click\\",
- focus: \\"focus\\",
- hover: \\"hover\\"
- };
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(
- \\"button\\",
- null,
- toDisplayString(__props.trigger),
- 1
- /* TEXT */
- );
- };
- }
+ __name: "issue-362",
+ props: { trigger: { required: true } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const Trigger = {
+ click: "click",
+ focus: "focus",
+ hover: "hover"
+ };
+ const props = __props;
+ const __returned__ = {
+ Trigger,
+ props
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var issue362 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock(
+ "button",
+ null,
+ toDisplayString($props.trigger),
+ 1
+ /* TEXT */
+ );
+}
+var issue362 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { issue362 as default };
"
`;
exports[`fixtures > tests/fixtures/issue-362.vue > isProduction = true 1`] = `
-"import { defineComponent, openBlock, createElementBlock, toDisplayString } from 'vue';
+"// issue-362.js
+import { defineComponent, createElementBlock, openBlock, toDisplayString } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"issue-362\\",
- props: {
- trigger: null
- },
- setup(__props) {
- const props = __props;
- const Trigger = {
- click: \\"click\\",
- focus: \\"focus\\",
- hover: \\"hover\\"
- };
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(
- \\"button\\",
- null,
- toDisplayString(__props.trigger),
- 1
- /* TEXT */
- );
- };
- }
+ __name: "issue-362",
+ props: { trigger: null },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const Trigger = {
+ click: "click",
+ focus: "focus",
+ hover: "hover"
+ };
+ const props = __props;
+ const __returned__ = {
+ Trigger,
+ props
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var issue362 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock(
+ "button",
+ null,
+ toDisplayString($props.trigger),
+ 1
+ /* TEXT */
+ );
+}
+var issue362 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { issue362 as default };
"
`;
+exports[`fixtures > tests/fixtures/issue-806.vue > isProduction = false 1`] = `
+"// issue-806.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "issue-806",
+ props: { foo: {
+ type: [Function, Object],
+ required: false
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var issue806 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { issue806 as default };
+"
+`;
+
+exports[`fixtures > tests/fixtures/issue-806.vue > isProduction = true 1`] = `
+"// issue-806.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "issue-806",
+ props: { foo: { type: Function } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var issue806 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { issue806 as default };
+"
+`;
+
exports[`fixtures > tests/fixtures/json-resolve.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// json-resolve.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
+var foo = "bar";
+var pkg = {
+ foo: foo
+};
+
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"json-resolve\\",
- props: {
- foo: { type: String, required: true },
- bar: { type: Object, required: false }
- },
- setup(__props) {
- const props = __props;
- return () => {
- };
- }
+ __name: "json-resolve",
+ props: {
+ foo: {
+ type: String,
+ required: true
+ },
+ bar: {
+ type: Object,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = {
+ props,
+ get pkg() {
+ return pkg;
+ }
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var jsonResolve = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -592,20 +966,36 @@ export { jsonResolve as default };
`;
exports[`fixtures > tests/fixtures/json-resolve.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// json-resolve.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
+var foo = "bar";
+var pkg = {
+ foo: foo
+};
+
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"json-resolve\\",
- props: {
- foo: null,
- bar: null
- },
- setup(__props) {
- const props = __props;
- return () => {
- };
- }
+ __name: "json-resolve",
+ props: {
+ foo: null,
+ bar: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ const __returned__ = {
+ props,
+ get pkg() {
+ return pkg;
+ }
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var jsonResolve = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -615,20 +1005,35 @@ export { jsonResolve as default };
`;
exports[`fixtures > tests/fixtures/namespace.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// namespace.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"namespace\\",
- props: {
- x: { type: Boolean, required: true },
- y: { type: Number, required: true },
- z: { type: String, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "namespace",
+ props: {
+ x: {
+ type: Boolean,
+ required: true
+ },
+ y: {
+ type: Number,
+ required: true
+ },
+ z: {
+ type: String,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var namespace = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -638,20 +1043,26 @@ export { namespace as default };
`;
exports[`fixtures > tests/fixtures/namespace.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// namespace.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"namespace\\",
- props: {
- x: { type: Boolean },
- y: null,
- z: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "namespace",
+ props: {
+ x: { type: Boolean },
+ y: null,
+ z: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var namespace = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -661,19 +1072,31 @@ export { namespace as default };
`;
exports[`fixtures > tests/fixtures/optional-method.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// optional-method.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"optional-method\\",
- props: {
- onClick: { type: Function, required: false },
- onSubmit: { type: Function, required: false }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "optional-method",
+ props: {
+ onClick: {
+ type: Function,
+ required: false
+ },
+ onSubmit: {
+ type: Function,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var optionalMethod = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -683,19 +1106,25 @@ export { optionalMethod as default };
`;
exports[`fixtures > tests/fixtures/optional-method.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// optional-method.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"optional-method\\",
- props: {
- onClick: { type: Function },
- onSubmit: { type: Function }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "optional-method",
+ props: {
+ onClick: { type: Function },
+ onSubmit: { type: Function }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var optionalMethod = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -705,18 +1134,22 @@ export { optionalMethod as default };
`;
exports[`fixtures > tests/fixtures/playground.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// playground.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"playground\\",
- props: {
- foo: { required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "playground",
+ props: { foo: { required: true } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var playground = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -726,18 +1159,22 @@ export { playground as default };
`;
exports[`fixtures > tests/fixtures/playground.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// playground.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"playground\\",
- props: {
- foo: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "playground",
+ props: { foo: null },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var playground = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -746,23 +1183,115 @@ export { playground as default };
"
`;
+exports[`fixtures > tests/fixtures/radix-vue.vue > isProduction = false 1`] = `
+"// radix-vue.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "radix-vue",
+ props: {
+ asChild: {
+ type: Boolean,
+ required: false
+ },
+ as: {
+ type: [
+ String,
+ Object,
+ Function
+ ],
+ required: false
+ },
+ foo: {
+ type: String,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var radixVue = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { radixVue as default };
+"
+`;
+
+exports[`fixtures > tests/fixtures/radix-vue.vue > isProduction = true 1`] = `
+"// radix-vue.js
+import { defineComponent } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "radix-vue",
+ props: {
+ asChild: { type: Boolean },
+ as: { type: Function },
+ foo: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+var radixVue = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+
+export { radixVue as default };
+"
+`;
+
exports[`fixtures > tests/fixtures/resolve-failed.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// resolve-failed.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"resolve-failed\\",
- props: {
- foo: { required: true },
- bar: { type: Object, required: true },
- bool: { type: Boolean, skipCheck: true, required: true },
- fun: { type: Function, skipCheck: true, required: true },
- boolAndFun: { type: [Boolean, Function], skipCheck: true, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "resolve-failed",
+ props: {
+ foo: { required: true },
+ bar: {
+ type: Object,
+ required: true
+ },
+ bool: {
+ type: Boolean,
+ skipCheck: true,
+ required: true
+ },
+ fun: {
+ type: Function,
+ skipCheck: true,
+ required: true
+ },
+ boolAndFun: {
+ type: [Boolean, Function],
+ skipCheck: true,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var resolveFailed = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -772,22 +1301,28 @@ export { resolveFailed as default };
`;
exports[`fixtures > tests/fixtures/resolve-failed.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// resolve-failed.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"resolve-failed\\",
- props: {
- foo: null,
- bar: null,
- bool: { type: Boolean },
- fun: { type: Function },
- boolAndFun: { type: [Boolean, Function] }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "resolve-failed",
+ props: {
+ foo: null,
+ bar: null,
+ bool: { type: Boolean },
+ fun: { type: Function },
+ boolAndFun: { type: [Boolean, Function] }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var resolveFailed = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -796,19 +1331,88 @@ export { resolveFailed as default };
"
`;
+exports[`fixtures > tests/fixtures/short-emits.vue > isProduction = false 1`] = `
+"// short-emits.js
+import { defineComponent, createElementBlock, openBlock } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "short-emits",
+ emits: ["click"],
+ setup(__props, { expose: __expose, emit: __emit }) {
+ __expose();
+ const emit = __emit;
+ const __returned__ = { emit };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("button", {
+ onClick: _cache[0] || (_cache[0] = ($event) => $setup.emit("click"))
+ }, "click");
+}
+var shortEmits = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
+
+export { shortEmits as default };
+"
+`;
+
+exports[`fixtures > tests/fixtures/short-emits.vue > isProduction = true 1`] = `
+"// short-emits.js
+import { defineComponent, createElementBlock, openBlock } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+var _sfc_main = /* @__PURE__ */ defineComponent({
+ __name: "short-emits",
+ emits: ["click"],
+ setup(__props, { expose: __expose, emit: __emit }) {
+ __expose();
+ const emit = __emit;
+ const __returned__ = { emit };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
+});
+
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return openBlock(), createElementBlock("button", {
+ onClick: _cache[0] || (_cache[0] = ($event) => $setup.emit("click"))
+ }, "click");
+}
+var shortEmits = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
+
+export { shortEmits as default };
+"
+`;
+
exports[`fixtures > tests/fixtures/special-key.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// special-key.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"special-key\\",
- props: {
- \\"key-name\\": { type: String, required: false }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "special-key",
+ props: { "key-name": {
+ type: String,
+ required: false
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var specialKey = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -818,18 +1422,22 @@ export { specialKey as default };
`;
exports[`fixtures > tests/fixtures/special-key.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// special-key.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"special-key\\",
- props: {
- \\"key-name\\": null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "special-key",
+ props: { "key-name": null },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var specialKey = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -839,26 +1447,59 @@ export { specialKey as default };
`;
exports[`fixtures > tests/fixtures/template-keys.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// template-keys.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"template-keys\\",
- props: {
- \\"TfooSxZ0strstatic_value'\\": { type: String, required: true },
- \\"TfooSxZ1strstatic_value'\\": { type: String, required: true },
- \\"TfooSyZ0strstatic_value'\\": { type: String, required: true },
- \\"TfooSyZ1strstatic_value'\\": { type: String, required: true },
- \\"TbarSxZ0strstatic_value'\\": { type: String, required: true },
- \\"TbarSxZ1strstatic_value'\\": { type: String, required: true },
- \\"TbarSyZ0strstatic_value'\\": { type: String, required: true },
- \\"TbarSyZ1strstatic_value'\\": { type: String, required: true },
- extra: { type: String, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "template-keys",
+ props: {
+ "TfooSxZ0strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TfooSxZ1strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TfooSyZ0strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TfooSyZ1strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TbarSxZ0strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TbarSxZ1strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TbarSyZ0strstatic_value'": {
+ type: String,
+ required: true
+ },
+ "TbarSyZ1strstatic_value'": {
+ type: String,
+ required: true
+ },
+ extra: {
+ type: String,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var templateKeys = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -868,26 +1509,32 @@ export { templateKeys as default };
`;
exports[`fixtures > tests/fixtures/template-keys.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// template-keys.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"template-keys\\",
- props: {
- \\"TfooSxZ0strstatic_value'\\": null,
- \\"TfooSxZ1strstatic_value'\\": null,
- \\"TfooSyZ0strstatic_value'\\": null,
- \\"TfooSyZ1strstatic_value'\\": null,
- \\"TbarSxZ0strstatic_value'\\": null,
- \\"TbarSxZ1strstatic_value'\\": null,
- \\"TbarSyZ0strstatic_value'\\": null,
- \\"TbarSyZ1strstatic_value'\\": null,
- extra: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "template-keys",
+ props: {
+ "TfooSxZ0strstatic_value'": null,
+ "TfooSxZ1strstatic_value'": null,
+ "TfooSyZ0strstatic_value'": null,
+ "TfooSyZ1strstatic_value'": null,
+ "TbarSxZ0strstatic_value'": null,
+ "TbarSxZ1strstatic_value'": null,
+ "TbarSyZ0strstatic_value'": null,
+ "TbarSyZ1strstatic_value'": null,
+ extra: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var templateKeys = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -897,28 +1544,56 @@ export { templateKeys as default };
`;
exports[`fixtures > tests/fixtures/ts-indexed-access-type.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// ts-indexed-access-type.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"ts-indexed-access-type\\",
- props: {
- foo: { type: String, required: true },
- bar: { required: true },
- baz: { required: true },
- qux: { required: true },
- all: { required: true },
- arr: { type: [String, Number], required: true },
- arr2: { type: [String, Number], required: true },
- tuple: { type: [String, Boolean], required: true },
- methodFoo: { type: Function, required: true },
- methodBar: { type: Function, required: true },
- methodOpt: { type: Function, skipCheck: true, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "ts-indexed-access-type",
+ props: {
+ foo: {
+ type: String,
+ required: true
+ },
+ bar: { required: true },
+ baz: { required: true },
+ qux: { required: true },
+ all: { required: true },
+ arr: {
+ type: [String, Number],
+ required: true
+ },
+ arr2: {
+ type: [String, Number],
+ required: true
+ },
+ tuple: {
+ type: [String, Boolean],
+ required: true
+ },
+ methodFoo: {
+ type: Function,
+ required: true
+ },
+ methodBar: {
+ type: Function,
+ required: true
+ },
+ methodOpt: {
+ type: Function,
+ skipCheck: true,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var tsIndexedAccessType = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -928,28 +1603,34 @@ export { tsIndexedAccessType as default };
`;
exports[`fixtures > tests/fixtures/ts-indexed-access-type.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// ts-indexed-access-type.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"ts-indexed-access-type\\",
- props: {
- foo: null,
- bar: null,
- baz: null,
- qux: null,
- all: null,
- arr: null,
- arr2: null,
- tuple: { type: [String, Boolean] },
- methodFoo: { type: Function },
- methodBar: { type: Function },
- methodOpt: { type: Function }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "ts-indexed-access-type",
+ props: {
+ foo: null,
+ bar: null,
+ baz: null,
+ qux: null,
+ all: null,
+ arr: null,
+ arr2: null,
+ tuple: { type: [String, Boolean] },
+ methodFoo: { type: Function },
+ methodBar: { type: Function },
+ methodOpt: { type: Function }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var tsIndexedAccessType = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -959,19 +1640,31 @@ export { tsIndexedAccessType as default };
`;
exports[`fixtures > tests/fixtures/ts-utility-types.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// ts-utility-types.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"ts-utility-types\\",
- props: {
- foo: { type: String, required: true },
- bar: { type: String, required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "ts-utility-types",
+ props: {
+ foo: {
+ type: String,
+ required: true
+ },
+ bar: {
+ type: String,
+ required: true
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var tsUtilityTypes = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -981,19 +1674,25 @@ export { tsUtilityTypes as default };
`;
exports[`fixtures > tests/fixtures/ts-utility-types.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// ts-utility-types.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"ts-utility-types\\",
- props: {
- foo: null,
- bar: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "ts-utility-types",
+ props: {
+ foo: null,
+ bar: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var tsUtilityTypes = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1003,18 +1702,22 @@ export { tsUtilityTypes as default };
`;
exports[`fixtures > tests/fixtures/undefined.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// undefined.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"undefined\\",
- props: {
- foo: { required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "undefined",
+ props: { foo: { required: true } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var _undefined = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1024,18 +1727,22 @@ export { _undefined as default };
`;
exports[`fixtures > tests/fixtures/undefined.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// undefined.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"undefined\\",
- props: {
- foo: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "undefined",
+ props: { foo: null },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var _undefined = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1045,21 +1752,39 @@ export { _undefined as default };
`;
exports[`fixtures > tests/fixtures/union.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// union.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union\\",
- props: {
- type: { type: String, required: true },
- foo: { type: String, required: false },
- optional: { type: Boolean, required: false },
- bar: { type: Number, required: false }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "union",
+ props: {
+ type: {
+ type: String,
+ required: true
+ },
+ foo: {
+ type: String,
+ required: false
+ },
+ optional: {
+ type: Boolean,
+ required: false
+ },
+ bar: {
+ type: Number,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var union = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1069,21 +1794,27 @@ export { union as default };
`;
exports[`fixtures > tests/fixtures/union.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// union.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union\\",
- props: {
- type: null,
- foo: null,
- optional: { type: Boolean },
- bar: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "union",
+ props: {
+ type: null,
+ foo: null,
+ optional: { type: Boolean },
+ bar: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var union = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1093,16 +1824,27 @@ export { union as default };
`;
exports[`fixtures > tests/fixtures/union-emits.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// union-emits.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union-emits\\",
- emits: [\\"some\\", \\"emit\\", \\"another\\"],
- setup(__props, { emit }) {
- return () => {
- };
- }
+ __name: "union-emits",
+ emits: [
+ "some",
+ "emit",
+ "another"
+ ],
+ setup(__props, { expose: __expose, emit: __emit }) {
+ __expose();
+ const emit = __emit;
+ const __returned__ = { emit };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unionEmits = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1112,16 +1854,27 @@ export { unionEmits as default };
`;
exports[`fixtures > tests/fixtures/union-emits.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// union-emits.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union-emits\\",
- emits: [\\"some\\", \\"emit\\", \\"another\\"],
- setup(__props, { emit }) {
- return () => {
- };
- }
+ __name: "union-emits",
+ emits: [
+ "some",
+ "emit",
+ "another"
+ ],
+ setup(__props, { expose: __expose, emit: __emit }) {
+ __expose();
+ const emit = __emit;
+ const __returned__ = { emit };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unionEmits = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1131,20 +1884,35 @@ export { unionEmits as default };
`;
exports[`fixtures > tests/fixtures/union-props.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// union-props.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union-props\\",
- props: {
- foo: { type: [String, Number], required: true },
- bar: { type: [String, Number], required: true },
- optional: { type: Boolean, required: false }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "union-props",
+ props: {
+ foo: {
+ type: [String, Number],
+ required: true
+ },
+ bar: {
+ type: [String, Number],
+ required: true
+ },
+ optional: {
+ type: Boolean,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unionProps = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1154,20 +1922,26 @@ export { unionProps as default };
`;
exports[`fixtures > tests/fixtures/union-props.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// union-props.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"union-props\\",
- props: {
- foo: null,
- bar: null,
- optional: { type: Boolean }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "union-props",
+ props: {
+ foo: null,
+ bar: null,
+ optional: { type: Boolean }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unionProps = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1177,18 +1951,22 @@ export { unionProps as default };
`;
exports[`fixtures > tests/fixtures/unresolved.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// unresolved.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"unresolved\\",
- props: {
- foo: { required: true }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "unresolved",
+ props: { foo: { required: true } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unresolved = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1198,18 +1976,22 @@ export { unresolved as default };
`;
exports[`fixtures > tests/fixtures/unresolved.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// unresolved.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"unresolved\\",
- props: {
- foo: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "unresolved",
+ props: { foo: null },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var unresolved = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1219,21 +2001,39 @@ export { unresolved as default };
`;
exports[`fixtures > tests/fixtures/vue-core-7553.vue > isProduction = false 1`] = `
-"import { defineComponent } from 'vue';
+"// vue-core-7553.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"vue-core-7553\\",
- props: {
- size: { type: String, required: false },
- color: { type: [String, Number], required: true },
- appearance: { type: String, required: true },
- note: { type: String, required: false }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "vue-core-7553",
+ props: {
+ size: {
+ type: String,
+ required: false
+ },
+ color: {
+ type: [String, Number],
+ required: true
+ },
+ appearance: {
+ type: String,
+ required: true
+ },
+ note: {
+ type: String,
+ required: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var vueCore7553 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -1243,21 +2043,27 @@ export { vueCore7553 as default };
`;
exports[`fixtures > tests/fixtures/vue-core-7553.vue > isProduction = true 1`] = `
-"import { defineComponent } from 'vue';
+"// vue-core-7553.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"vue-core-7553\\",
- props: {
- size: null,
- color: null,
- appearance: null,
- note: null
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "vue-core-7553",
+ props: {
+ size: null,
+ color: null,
+ appearance: null,
+ note: null
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var vueCore7553 = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
diff --git a/packages/better-define/tests/fixtures.test.ts b/packages/better-define/tests/fixtures.test.ts
index c2686d431..266637b46 100644
--- a/packages/better-define/tests/fixtures.test.ts
+++ b/packages/better-define/tests/fixtures.test.ts
@@ -1,14 +1,14 @@
import { resolve } from 'node:path'
-import { describe } from 'vitest'
import {
- RollupEsbuildPlugin,
+ rollupBuild,
RollupJson,
RollupNodeResolve,
RollupVue,
RollupVueJsx,
- rollupBuild,
testFixtures,
+ UnpluginOxc,
} from '@vue-macros/test-utils'
+import { describe } from 'vitest'
import VueBetterDefine from '../src/rollup'
describe('fixtures', async () => {
@@ -21,14 +21,12 @@ describe('fixtures', async () => {
RollupVueJsx(),
RollupJson(),
RollupNodeResolve(),
- RollupEsbuildPlugin({
- target: 'esnext',
- }),
+ UnpluginOxc.rollup(),
]),
{
cwd: resolve(__dirname, '..'),
promise: true,
params: [['isProduction', [true, false]]],
- }
+ },
)
})
diff --git a/packages/better-define/tests/fixtures/defaults-dynamic.vue b/packages/better-define/tests/fixtures/defaults-dynamic.vue
index c43a45fe9..c6b1c957a 100644
--- a/packages/better-define/tests/fixtures/defaults-dynamic.vue
+++ b/packages/better-define/tests/fixtures/defaults-dynamic.vue
@@ -5,7 +5,7 @@ withDefaults(
}>(),
{
['f' + 'oo']: 'foo',
- }
+ },
)
diff --git a/packages/better-define/tests/fixtures/defaults-static.vue b/packages/better-define/tests/fixtures/defaults-static.vue
index 4249b74cd..d1dc6726f 100644
--- a/packages/better-define/tests/fixtures/defaults-static.vue
+++ b/packages/better-define/tests/fixtures/defaults-static.vue
@@ -22,7 +22,7 @@ withDefaults(
quux: abc,
},
},
- }
+ },
)
diff --git a/packages/better-define/tests/fixtures/err.vue b/packages/better-define/tests/fixtures/err.vue
new file mode 100644
index 000000000..8356893bd
--- /dev/null
+++ b/packages/better-define/tests/fixtures/err.vue
@@ -0,0 +1,4 @@
+
diff --git a/packages/better-define/tests/fixtures/fn-default.vue b/packages/better-define/tests/fixtures/fn-default.vue
index fc2d3d6c7..d503d1085 100644
--- a/packages/better-define/tests/fixtures/fn-default.vue
+++ b/packages/better-define/tests/fixtures/fn-default.vue
@@ -5,6 +5,6 @@ const props = withDefaults(
}>(),
{
fn: () => {},
- }
+ },
)
diff --git a/packages/better-define/tests/fixtures/issue-260.vue b/packages/better-define/tests/fixtures/issue-260.vue
index b6fdbe241..f46407a86 100644
--- a/packages/better-define/tests/fixtures/issue-260.vue
+++ b/packages/better-define/tests/fixtures/issue-260.vue
@@ -10,7 +10,7 @@ const props = withDefaults(
}>(),
{
menu: () => ({ txt: '1-1' }),
- }
+ },
)
diff --git a/packages/better-define/tests/fixtures/issue-806.vue b/packages/better-define/tests/fixtures/issue-806.vue
new file mode 100644
index 000000000..7bad9e255
--- /dev/null
+++ b/packages/better-define/tests/fixtures/issue-806.vue
@@ -0,0 +1,11 @@
+
diff --git a/packages/better-define/tests/fixtures/radix-vue.vue b/packages/better-define/tests/fixtures/radix-vue.vue
new file mode 100644
index 000000000..a288ab0f8
--- /dev/null
+++ b/packages/better-define/tests/fixtures/radix-vue.vue
@@ -0,0 +1,9 @@
+
diff --git a/packages/better-define/tests/fixtures/short-emits.vue b/packages/better-define/tests/fixtures/short-emits.vue
new file mode 100644
index 000000000..258c21c76
--- /dev/null
+++ b/packages/better-define/tests/fixtures/short-emits.vue
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/packages/better-define/tsdown.config.ts b/packages/better-define/tsdown.config.ts
new file mode 100644
index 000000000..3d82d8e38
--- /dev/null
+++ b/packages/better-define/tsdown.config.ts
@@ -0,0 +1,5 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ platform: 'node',
+})
diff --git a/packages/better-define/tsup.config.ts b/packages/better-define/tsup.config.ts
deleted file mode 100644
index 1605eae16..000000000
--- a/packages/better-define/tsup.config.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from '../../tsup.config.js'
diff --git a/packages/boolean-prop/README.md b/packages/boolean-prop/README.md
new file mode 100644
index 000000000..e5393b74c
--- /dev/null
+++ b/packages/boolean-prop/README.md
@@ -0,0 +1,3 @@
+# @vue-macros/boolean-prop [](https://npmjs.com/package/@vue-macros/boolean-prop)
+
+Please refer to [README.md](https://github.com/vue-macros/vue-macros#readme)
diff --git a/packages/boolean-prop/package.json b/packages/boolean-prop/package.json
new file mode 100644
index 000000000..364354c1f
--- /dev/null
+++ b/packages/boolean-prop/package.json
@@ -0,0 +1,87 @@
+{
+ "name": "@vue-macros/boolean-prop",
+ "version": "3.0.0-beta.21",
+ "description": "booleanProp feature from Vue Macros.",
+ "type": "module",
+ "keywords": [
+ "vue-macros",
+ "macros",
+ "vue",
+ "sfc",
+ "setup",
+ "script-setup",
+ "boolean-prop"
+ ],
+ "license": "MIT",
+ "homepage": "https://vue-macros.dev",
+ "bugs": {
+ "url": "https://github.com/vue-macros/vue-macros/issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/vue-macros/vue-macros.git",
+ "directory": "packages/boolean-prop"
+ },
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
+ "files": [
+ "dist"
+ ],
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "exports": {
+ ".": {
+ "dev": "./src/index.ts",
+ "default": "./dist/index.js"
+ },
+ "./api": {
+ "dev": "./src/api.ts",
+ "default": "./dist/api.js"
+ },
+ "./rolldown": {
+ "dev": "./src/rolldown.ts",
+ "default": "./dist/rolldown.js"
+ },
+ "./rollup": {
+ "dev": "./src/rollup.ts",
+ "default": "./dist/rollup.js"
+ },
+ "./vite": {
+ "dev": "./src/vite.ts",
+ "default": "./dist/vite.js"
+ },
+ "./*": "./*"
+ },
+ "typesVersions": {
+ "*": {
+ "*": [
+ "./dist/*",
+ "./*"
+ ]
+ }
+ },
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./api": "./dist/api.js",
+ "./rolldown": "./dist/rolldown.js",
+ "./rollup": "./dist/rollup.js",
+ "./vite": "./dist/vite.js",
+ "./*": "./*"
+ },
+ "tag": "next"
+ },
+ "scripts": {},
+ "dependencies": {
+ "@vue-macros/common": "workspace:*",
+ "@vue/compiler-core": "catalog:"
+ },
+ "devDependencies": {
+ "@vue/compiler-sfc": "catalog:"
+ },
+ "engines": {
+ "node": ">=20.18.0"
+ }
+}
diff --git a/packages/boolean-prop/src/api.ts b/packages/boolean-prop/src/api.ts
new file mode 100644
index 000000000..46d458ad7
--- /dev/null
+++ b/packages/boolean-prop/src/api.ts
@@ -0,0 +1 @@
+export * from './core'
diff --git a/packages/boolean-prop/src/core/index.ts b/packages/boolean-prop/src/core/index.ts
new file mode 100644
index 000000000..e67f13891
--- /dev/null
+++ b/packages/boolean-prop/src/core/index.ts
@@ -0,0 +1 @@
+export * from './transformer'
diff --git a/packages/boolean-prop/src/core/transformer.ts b/packages/boolean-prop/src/core/transformer.ts
new file mode 100644
index 000000000..2dae58699
--- /dev/null
+++ b/packages/boolean-prop/src/core/transformer.ts
@@ -0,0 +1,60 @@
+import type {
+ ConstantTypes,
+ NodeTransform,
+ NodeTypes,
+} from '@vue/compiler-core'
+
+export interface Options {
+ /**
+ * @default '!'
+ */
+ negativePrefix?: string
+}
+
+export function transformBooleanProp({
+ negativePrefix = '!',
+ constType = 3 satisfies ConstantTypes.CAN_STRINGIFY,
+}: Options & { constType?: ConstantTypes } = {}): NodeTransform {
+ return (node) => {
+ if (node.type !== (1 satisfies NodeTypes.ELEMENT)) return
+ for (const [i, prop] of node.props.entries()) {
+ if (
+ prop.type !== (6 satisfies NodeTypes.ATTRIBUTE) ||
+ prop.value !== undefined
+ )
+ continue
+
+ const isNegative = prop.name[0] === negativePrefix
+ const propName = isNegative ? prop.name.slice(1) : prop.name
+ const value = String(!isNegative)
+ if (isNegative) prop.loc.start.offset++
+ node.props[i] = {
+ type: 7 satisfies NodeTypes.DIRECTIVE,
+ name: 'bind',
+ arg: {
+ type: 4 satisfies NodeTypes.SIMPLE_EXPRESSION,
+ constType: 3 satisfies ConstantTypes.CAN_STRINGIFY,
+ content: propName,
+ isStatic: true,
+ loc: prop.loc,
+ },
+ exp: {
+ type: 4 satisfies NodeTypes.SIMPLE_EXPRESSION,
+ constType,
+ content: value,
+ isStatic: false,
+ loc: {
+ start: {
+ ...prop.loc.start,
+ offset: prop.loc.start.offset + 1,
+ },
+ end: prop.loc.end,
+ source: value,
+ },
+ },
+ loc: prop.loc,
+ modifiers: [],
+ }
+ }
+ }
+}
diff --git a/packages/boolean-prop/src/index.ts b/packages/boolean-prop/src/index.ts
new file mode 100644
index 000000000..4c924be9d
--- /dev/null
+++ b/packages/boolean-prop/src/index.ts
@@ -0,0 +1,52 @@
+import { getVuePluginApi, type VuePluginApi } from '@vue-macros/common'
+import { generatePluginName } from '#macros' with { type: 'macro' }
+import { transformBooleanProp, type Options } from './core/index'
+import type { Plugin } from 'vite'
+
+// legacy export
+export * from './api'
+
+const name = generatePluginName()
+
+function rollup(options: Options = {}): Plugin {
+ let api: VuePluginApi | null | undefined
+
+ return {
+ name,
+ configResolved(config) {
+ try {
+ api = getVuePluginApi(config.plugins)
+ } catch {}
+ },
+ buildStart(rollupOpts) {
+ if (api === undefined)
+ try {
+ api = getVuePluginApi(rollupOpts.plugins)
+ } catch (error: any) {
+ this.warn(error)
+ return
+ }
+
+ if (!api) return
+
+ api.options.template ||= {}
+ api.options.template.compilerOptions ||= {}
+ api.options.template.compilerOptions.nodeTransforms ||= []
+
+ api.options.template.compilerOptions.nodeTransforms.push(
+ transformBooleanProp(options),
+ )
+ },
+ }
+}
+
+const plugin: {
+ rollup: typeof rollup
+ rolldown: typeof rollup
+ vite: typeof rollup
+} = {
+ rollup,
+ rolldown: rollup,
+ vite: rollup,
+}
+export default plugin
diff --git a/packages/boolean-prop/src/rolldown.ts b/packages/boolean-prop/src/rolldown.ts
new file mode 100644
index 000000000..082a55c18
--- /dev/null
+++ b/packages/boolean-prop/src/rolldown.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rolldown as typeof unplugin.rolldown
diff --git a/packages/boolean-prop/src/rollup.ts b/packages/boolean-prop/src/rollup.ts
new file mode 100644
index 000000000..45545feb1
--- /dev/null
+++ b/packages/boolean-prop/src/rollup.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rollup as typeof unplugin.rollup
diff --git a/packages/boolean-prop/src/vite.ts b/packages/boolean-prop/src/vite.ts
new file mode 100644
index 000000000..a7c5db2c1
--- /dev/null
+++ b/packages/boolean-prop/src/vite.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.vite as typeof unplugin.vite
diff --git a/packages/boolean-prop/tests/__snapshots__/compiler.test.ts.snap b/packages/boolean-prop/tests/__snapshots__/compiler.test.ts.snap
new file mode 100644
index 000000000..6ef8f427f
--- /dev/null
+++ b/packages/boolean-prop/tests/__snapshots__/compiler.test.ts.snap
@@ -0,0 +1,178 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`compiler > basic 1`] = `
+{
+ "arg": {
+ "constType": 3,
+ "content": "checked",
+ "isStatic": true,
+ "loc": {
+ "end": {
+ "column": 15,
+ "line": 1,
+ "offset": 14,
+ },
+ "source": "checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 7,
+ },
+ },
+ "type": 4,
+ },
+ "exp": {
+ "constType": 3,
+ "content": "true",
+ "isStatic": false,
+ "loc": {
+ "end": {
+ "column": 15,
+ "line": 1,
+ "offset": 14,
+ },
+ "source": "true",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 8,
+ },
+ },
+ "type": 4,
+ },
+ "loc": {
+ "end": {
+ "column": 15,
+ "line": 1,
+ "offset": 14,
+ },
+ "source": "checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 7,
+ },
+ },
+ "modifiers": [],
+ "name": "bind",
+ "type": 7,
+}
+`;
+
+exports[`compiler > false prop 1`] = `
+{
+ "arg": {
+ "constType": 3,
+ "content": "checked",
+ "isStatic": true,
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "!checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 8,
+ },
+ },
+ "type": 4,
+ },
+ "exp": {
+ "constType": 3,
+ "content": "false",
+ "isStatic": false,
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "false",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 9,
+ },
+ },
+ "type": 4,
+ },
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "!checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 8,
+ },
+ },
+ "modifiers": [],
+ "name": "bind",
+ "type": 7,
+}
+`;
+
+exports[`compiler > false prop prefix 1`] = `
+{
+ "arg": {
+ "constType": 3,
+ "content": "checked",
+ "isStatic": true,
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "~checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 8,
+ },
+ },
+ "type": 4,
+ },
+ "exp": {
+ "constType": 3,
+ "content": "false",
+ "isStatic": false,
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "false",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 9,
+ },
+ },
+ "type": 4,
+ },
+ "loc": {
+ "end": {
+ "column": 16,
+ "line": 1,
+ "offset": 15,
+ },
+ "source": "~checked",
+ "start": {
+ "column": 8,
+ "line": 1,
+ "offset": 8,
+ },
+ },
+ "modifiers": [],
+ "name": "bind",
+ "type": 7,
+}
+`;
diff --git a/packages/boolean-prop/tests/__snapshots__/fixtures.test.ts.snap b/packages/boolean-prop/tests/__snapshots__/fixtures.test.ts.snap
new file mode 100644
index 000000000..c36098cc5
--- /dev/null
+++ b/packages/boolean-prop/tests/__snapshots__/fixtures.test.ts.snap
@@ -0,0 +1,22 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`fixtures > tests/fixtures/basic.vue 1`] = `
+"// basic.js
+import { createElementBlock, openBlock } from 'vue';
+import _export_sfc from '[NULL]/plugin-vue/export-helper';
+
+const _sfc_main = { };
+
+const _hoisted_1 = {
+ checked: true,
+ enabled: false
+};
+
+function _sfc_render(_ctx, _cache) {
+ return (openBlock(), createElementBlock("input", _hoisted_1))
+}
+var basic = /*#__PURE__*/_export_sfc(_sfc_main, [['render',_sfc_render],__FILE__]);
+
+export { basic as default };
+"
+`;
diff --git a/packages/boolean-prop/tests/compiler.test.ts b/packages/boolean-prop/tests/compiler.test.ts
new file mode 100644
index 000000000..3f86ecd3a
--- /dev/null
+++ b/packages/boolean-prop/tests/compiler.test.ts
@@ -0,0 +1,41 @@
+import { compileTemplate } from '@vue/compiler-sfc'
+import { describe, expect, test } from 'vitest'
+import { transformBooleanProp } from '../src'
+
+function compile(code: string, negativePrefix?: string) {
+ return compileTemplate({
+ source: code,
+ filename: 'anonymous.vue',
+ id: 'xxx',
+ compilerOptions: {
+ nodeTransforms: [
+ transformBooleanProp({
+ negativePrefix,
+ }),
+ ],
+ },
+ })
+}
+
+describe('compiler', () => {
+ test('basic', () => {
+ const original = compile(``)
+ const sugar = compile(``)
+ expect(sugar.code).toBe(original.code)
+ expect((sugar.ast as any).children[0].props[0]).matchSnapshot()
+ })
+
+ test('false prop', () => {
+ const original = compile(``)
+ const sugar = compile(``)
+ expect(sugar.code).toBe(original.code)
+ expect((sugar.ast as any).children[0].props[0]).matchSnapshot()
+ })
+
+ test('false prop prefix', () => {
+ const original = compile(``, '~')
+ const sugar = compile(``, '~')
+ expect(sugar.code).toBe(original.code)
+ expect((sugar.ast as any).children[0].props[0]).matchSnapshot()
+ })
+})
diff --git a/packages/boolean-prop/tests/fixtures.test.ts b/packages/boolean-prop/tests/fixtures.test.ts
new file mode 100644
index 000000000..55d3ac54f
--- /dev/null
+++ b/packages/boolean-prop/tests/fixtures.test.ts
@@ -0,0 +1,21 @@
+import { resolve } from 'node:path'
+import {
+ rollupBuild,
+ RollupVue,
+ testFixtures,
+ UnpluginOxc,
+} from '@vue-macros/test-utils'
+import { describe } from 'vitest'
+import BooleanProp from '../src/vite'
+
+describe('fixtures', async () => {
+ await testFixtures(
+ 'tests/fixtures/*.{vue,[jt]s?(x)}',
+ (args, id) =>
+ rollupBuild(id, [BooleanProp(), RollupVue(), UnpluginOxc.rollup()]),
+ {
+ cwd: resolve(__dirname, '..'),
+ promise: true,
+ },
+ )
+})
diff --git a/packages/boolean-prop/tests/fixtures/basic.vue b/packages/boolean-prop/tests/fixtures/basic.vue
new file mode 100644
index 000000000..b0b98bd9d
--- /dev/null
+++ b/packages/boolean-prop/tests/fixtures/basic.vue
@@ -0,0 +1,3 @@
+
+
+
diff --git a/packages/chain-call/CHANGELOG.md b/packages/chain-call/CHANGELOG.md
deleted file mode 100644
index c060b23ad..000000000
--- a/packages/chain-call/CHANGELOG.md
+++ /dev/null
@@ -1,43 +0,0 @@
-# @vue-macros/chain-call
-
-## 0.1.0
-
-### Minor Changes
-
-- [`d1c2f527`](https://github.com/vue-macros/vue-macros/commit/d1c2f527f18c7e90cc96677f667a148ac0213fc9) Thanks [@sxzz](https://github.com/sxzz)! - publish dts files
-
-### Patch Changes
-
-- Updated dependencies [[`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741), [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb)]:
- - @vue-macros/common@1.6.0
-
-## 0.0.4
-
-### Patch Changes
-
-- Updated dependencies [[`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779)]:
- - @vue-macros/common@1.5.0
-
-## 0.0.3
-
-### Patch Changes
-
-- [`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4) Thanks [@sxzz](https://github.com/sxzz)! - add types for both esm and cjs
-
-- Updated dependencies [[`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4)]:
- - @vue-macros/common@1.4.1
-
-## 0.0.2
-
-### Patch Changes
-
-- [`14bda40b`](https://github.com/vue-macros/vue-macros/commit/14bda40b21bf41ecedb7dd674f3e0c5828ae0414) Thanks [@sxzz](https://github.com/sxzz)! - add type fallback for all TS versions
-
-## 0.0.1
-
-### Patch Changes
-
-- [#231](https://github.com/vue-macros/vue-macros/pull/231) [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88) Thanks [@alexzhang1030](https://github.com/alexzhang1030)! - new feature `chainCall`
-
-- Updated dependencies [[`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219), [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88), [`ee4e093`](https://github.com/vue-macros/vue-macros/commit/ee4e093ec07931da9d24ded155a153e3496b4c7b)]:
- - @vue-macros/common@1.4.0
diff --git a/packages/chain-call/macros.d.ts b/packages/chain-call/macros.d.ts
index 6f9ac4ae7..cdcf0ac49 100644
--- a/packages/chain-call/macros.d.ts
+++ b/packages/chain-call/macros.d.ts
@@ -1,4 +1,4 @@
-import { type ComponentObjectPropsOptions, type ExtractPropTypes } from 'vue'
+import type { ComponentObjectPropsOptions, ExtractPropTypes } from 'vue'
// copy from vue-core
export type Prettify = {
@@ -38,17 +38,14 @@ type BooleanKey = K extends any
// end
export type AttachWithDefaults = Props & {
- withDefaults(): Props
- withDefaults<
- BKeys extends BooleanKey,
- Defaults extends InferDefaults,
- >(
- defaults?: Defaults
- ): Prettify>
+ withDefaults: (() => Props) &
+ (, Defaults extends InferDefaults>(
+ defaults?: Defaults,
+ ) => Prettify>)
}
export declare function defineProps(
- props: PropNames[]
+ props: PropNames[],
): Prettify<
AttachWithDefaults<
Readonly<{
diff --git a/packages/chain-call/package.json b/packages/chain-call/package.json
index 338e0a50a..4f74d4a1f 100644
--- a/packages/chain-call/package.json
+++ b/packages/chain-call/package.json
@@ -1,8 +1,8 @@
{
"name": "@vue-macros/chain-call",
- "version": "0.1.0",
- "packageManager": "pnpm@8.6.10",
- "description": "chain-call feature from Vue Macros.",
+ "version": "3.0.0-beta.21",
+ "description": "chainCall feature from Vue Macros.",
+ "type": "module",
"keywords": [
"vue-macros",
"macros",
@@ -14,7 +14,7 @@
"unplugin"
],
"license": "MIT",
- "homepage": "https://github.com/vue-macros/vue-macros#readme",
+ "homepage": "https://vue-macros.dev",
"bugs": {
"url": "https://github.com/vue-macros/vue-macros/issues"
},
@@ -23,68 +23,47 @@
"url": "git+https://github.com/vue-macros/vue-macros.git",
"directory": "packages/chain-call"
},
- "author": "三咲智子 ",
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
"files": [
"*.d.ts",
"dist"
],
- "main": "dist/index.js",
- "module": "dist/index.mjs",
- "types": "index.d.ts",
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
"exports": {
".": {
"dev": "./src/index.ts",
- "types": {
- "require": "./dist/index.d.ts",
- "import": "./dist/index.d.mts"
- },
- "require": "./dist/index.js",
- "import": "./dist/index.mjs"
+ "default": "./dist/index.js"
},
"./api": {
"dev": "./src/api.ts",
- "types": {
- "require": "./dist/api.d.ts",
- "import": "./dist/api.d.mts"
- },
- "require": "./dist/api.js",
- "import": "./dist/api.mjs"
+ "default": "./dist/api.js"
},
"./esbuild": {
"dev": "./src/esbuild.ts",
- "types": {
- "require": "./dist/esbuild.d.ts",
- "import": "./dist/esbuild.d.mts"
- },
- "require": "./dist/esbuild.js",
- "import": "./dist/esbuild.mjs"
+ "default": "./dist/esbuild.js"
+ },
+ "./rolldown": {
+ "dev": "./src/rolldown.ts",
+ "default": "./dist/rolldown.js"
},
"./rollup": {
"dev": "./src/rollup.ts",
- "types": {
- "require": "./dist/rollup.d.ts",
- "import": "./dist/rollup.d.mts"
- },
- "require": "./dist/rollup.js",
- "import": "./dist/rollup.mjs"
+ "default": "./dist/rollup.js"
+ },
+ "./rspack": {
+ "dev": "./src/rspack.ts",
+ "default": "./dist/rspack.js"
},
"./vite": {
"dev": "./src/vite.ts",
- "types": {
- "require": "./dist/vite.d.ts",
- "import": "./dist/vite.d.mts"
- },
- "require": "./dist/vite.js",
- "import": "./dist/vite.mjs"
+ "default": "./dist/vite.js"
},
"./webpack": {
"dev": "./src/webpack.ts",
- "types": {
- "require": "./dist/webpack.d.ts",
- "import": "./dist/webpack.d.mts"
- },
- "require": "./dist/webpack.js",
- "import": "./dist/webpack.mjs"
+ "default": "./dist/webpack.js"
},
"./*": [
"./*",
@@ -99,18 +78,30 @@
]
}
},
- "scripts": {
- "build": "tsup && tsx ../../scripts/postbuild.ts",
- "dev": "DEV=1 tsup"
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./api": "./dist/api.js",
+ "./esbuild": "./dist/esbuild.js",
+ "./rolldown": "./dist/rolldown.js",
+ "./rollup": "./dist/rollup.js",
+ "./rspack": "./dist/rspack.js",
+ "./vite": "./dist/vite.js",
+ "./webpack": "./dist/webpack.js",
+ "./*": [
+ "./*",
+ "./*.d.ts"
+ ]
+ },
+ "tag": "next"
},
+ "scripts": {},
"dependencies": {
"@vue-macros/common": "workspace:*",
- "unplugin": "^1.4.0"
- },
- "devDependencies": {
- "rollup": "^3.26.3"
+ "unplugin": "catalog:"
},
"engines": {
- "node": ">=16.14.0"
+ "node": ">=20.18.0"
}
}
diff --git a/packages/chain-call/src/core/index.ts b/packages/chain-call/src/core/index.ts
index 1156d4281..d2467f69c 100644
--- a/packages/chain-call/src/core/index.ts
+++ b/packages/chain-call/src/core/index.ts
@@ -1,27 +1,27 @@
import {
DEFINE_PROPS,
- MagicString,
- WITH_DEFAULTS,
- getTransformResult,
+ generateTransform,
isCallOf,
isIdentifierOf,
+ MagicStringAST,
parseSFC,
removeMacroImport,
walkAST,
+ WITH_DEFAULTS,
+ type CodeTransform,
} from '@vue-macros/common'
-import {
- type CallExpression,
- type MemberExpression,
- type Node,
-} from '@babel/types'
+import type { CallExpression, MemberExpression, Node } from '@babel/types'
-export function transformChainCall(code: string, id: string) {
+export function transformChainCall(
+ code: string,
+ id: string,
+): CodeTransform | undefined {
if (!code.includes(DEFINE_PROPS)) return
const { scriptSetup, getSetupAst, offset } = parseSFC(code, id)
if (!scriptSetup) return
- const s = new MagicString(code)
+ const s = new MagicStringAST(code)
const setupAst = getSetupAst()!
walkAST(setupAst, {
@@ -36,7 +36,7 @@ export function transformChainCall(code: string, id: string) {
node.arguments[0] && s.sliceNode(node.arguments[0], { offset })
const definePropsString = s.sliceNode(
(node.callee as MemberExpression).object as CallExpression,
- { offset }
+ { offset },
)
s.overwriteNode(
@@ -44,11 +44,11 @@ export function transformChainCall(code: string, id: string) {
withDefaultString
? `${WITH_DEFAULTS}(${definePropsString}, ${withDefaultString})`
: definePropsString,
- { offset }
+ { offset },
)
}
- return getTransformResult(s, id)
+ return generateTransform(s, id)
}
function isChainCall(node: Node): node is CallExpression {
diff --git a/packages/chain-call/src/esbuild.ts b/packages/chain-call/src/esbuild.ts
index 71f1e0952..e8c6460dd 100644
--- a/packages/chain-call/src/esbuild.ts
+++ b/packages/chain-call/src/esbuild.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.esbuild
+export default unplugin.esbuild as typeof unplugin.esbuild
diff --git a/packages/chain-call/src/index.ts b/packages/chain-call/src/index.ts
index e54448ba5..f24b2b8ba 100644
--- a/packages/chain-call/src/index.ts
+++ b/packages/chain-call/src/index.ts
@@ -1,45 +1,51 @@
-import { createUnplugin } from 'unplugin'
import {
- type BaseOptions,
- type MarkRequired,
- REGEX_SETUP_SFC,
- REGEX_VUE_SFC,
- REGEX_VUE_SUB,
createFilter,
detectVueVersion,
+ FilterFileType,
+ getFilterPattern,
+ type BaseOptions,
+ type MarkRequired,
} from '@vue-macros/common'
+import { generatePluginName } from '#macros' with { type: 'macro' }
+import {
+ createUnplugin,
+ type UnpluginContextMeta,
+ type UnpluginInstance,
+} from 'unplugin'
import { transformChainCall } from './core'
export type Options = BaseOptions
export type OptionsResolved = MarkRequired
-function resolveOption(options: Options): OptionsResolved {
+function resolveOptions(
+ options: Options,
+ framework: UnpluginContextMeta['framework'],
+): OptionsResolved {
const version = options.version || detectVueVersion()
+ const include = getFilterPattern(
+ [FilterFileType.VUE_SFC_WITH_SETUP, FilterFileType.SETUP_SFC],
+ framework,
+ )
return {
- include: [REGEX_VUE_SFC, REGEX_SETUP_SFC, REGEX_VUE_SUB],
+ include,
...options,
version,
}
}
-const name = 'unplugin-vue-chain-call'
+const name = generatePluginName()
-export default createUnplugin(
- (userOptions = {}) => {
- const options = resolveOption(userOptions)
+const plugin: UnpluginInstance = createUnplugin(
+ (userOptions = {}, { framework }) => {
+ const options = resolveOptions(userOptions, framework)
const filter = createFilter(options)
return {
name,
enforce: 'pre',
-
- transformInclude(id) {
- return filter(id)
- },
-
- transform(code, id) {
- return transformChainCall(code, id)
- },
+ transformInclude: filter,
+ transform: transformChainCall,
}
- }
+ },
)
+export default plugin
diff --git a/packages/chain-call/src/rolldown.ts b/packages/chain-call/src/rolldown.ts
new file mode 100644
index 000000000..082a55c18
--- /dev/null
+++ b/packages/chain-call/src/rolldown.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rolldown as typeof unplugin.rolldown
diff --git a/packages/chain-call/src/rollup.ts b/packages/chain-call/src/rollup.ts
index ed6909cd3..45545feb1 100644
--- a/packages/chain-call/src/rollup.ts
+++ b/packages/chain-call/src/rollup.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.rollup
+export default unplugin.rollup as typeof unplugin.rollup
diff --git a/packages/chain-call/src/rspack.ts b/packages/chain-call/src/rspack.ts
new file mode 100644
index 000000000..6df8a0299
--- /dev/null
+++ b/packages/chain-call/src/rspack.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rspack as typeof unplugin.rspack
diff --git a/packages/chain-call/src/vite.ts b/packages/chain-call/src/vite.ts
index 589f4b964..a7c5db2c1 100644
--- a/packages/chain-call/src/vite.ts
+++ b/packages/chain-call/src/vite.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.vite
+export default unplugin.vite as typeof unplugin.vite
diff --git a/packages/chain-call/src/webpack.ts b/packages/chain-call/src/webpack.ts
index 83091ee31..74c1c9020 100644
--- a/packages/chain-call/src/webpack.ts
+++ b/packages/chain-call/src/webpack.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.webpack
+export default unplugin.webpack as typeof unplugin.webpack
diff --git a/packages/chain-call/tests/__snapshots__/fixtures.test.ts.snap b/packages/chain-call/tests/__snapshots__/fixtures.test.ts.snap
index 3659e931e..503aa19dc 100644
--- a/packages/chain-call/tests/__snapshots__/fixtures.test.ts.snap
+++ b/packages/chain-call/tests/__snapshots__/fixtures.test.ts.snap
@@ -1,23 +1,46 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`fixtures > tests/fixtures/basic.vue 1`] = `
-"import { defineComponent } from 'vue';
+"// basic.js
+import { defineComponent } from 'vue';
import { expectTypeOf } from 'expect-type';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"basic\\",
- props: {
- foo: { type: String, required: false, default: \\"111\\" },
- bar: { type: Number, required: false, default: 111 },
- baz: { type: Boolean, required: false, default: false }
- },
- setup(__props) {
- const props = __props;
- expectTypeOf(props).toEqualTypeOf();
- return () => {
- };
- }
+ __name: "basic",
+ props: {
+ foo: {
+ type: String,
+ required: false,
+ default: "111"
+ },
+ bar: {
+ type: Number,
+ required: false,
+ default: 111
+ },
+ baz: {
+ type: Boolean,
+ required: false,
+ default: false
+ }
+ },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ expectTypeOf(props).toEqualTypeOf();
+ const __returned__ = {
+ props,
+ get expectTypeOf() {
+ return expectTypeOf;
+ }
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var basic = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -27,66 +50,64 @@ export { basic as default };
`;
exports[`fixtures > tests/fixtures/declare.vue 1`] = `
-"import { defineComponent, toDisplayString } from 'vue';
+"// declare.js
+import { defineComponent, toDisplayString } from 'vue';
import { expectTypeOf } from 'expect-type';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"declare\\",
- props: {
- bar: { type: Boolean, required: false, default: true }
- },
- setup(__props) {
- const props = __props;
- expectTypeOf(props).toEqualTypeOf();
- return (_ctx, _cache) => {
- return toDisplayString(props);
- };
- }
+ __name: "declare",
+ props: { bar: {
+ type: Boolean,
+ required: false,
+ default: true
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ expectTypeOf(props).toEqualTypeOf();
+ const __returned__ = { props };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
-var declare = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
+function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
+ return toDisplayString($setup.props);
+}
+var declare = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], __FILE__]);
export { declare as default };
"
`;
-exports[`fixtures > tests/fixtures/destruct.vue 1`] = `
-"import { defineComponent, openBlock, createElementBlock, toDisplayString } from 'vue';
-import _export_sfc from '[NULL]/plugin-vue/export-helper';
-
-var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"destruct\\",
- props: {
- foo: { type: String, required: false, default: \\"111\\" }
- },
- setup(__props) {
- const { foo } = __props;
- return (_ctx, _cache) => {
- return openBlock(), createElementBlock(\\"div\\", null, toDisplayString(foo));
- };
- }
-});
-
-var destruct = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
-
-export { destruct as default };
-"
-`;
-
exports[`fixtures > tests/fixtures/empty.vue 1`] = `
-"import { defineComponent } from 'vue';
+"// empty.js
+import { defineComponent } from 'vue';
import { expectTypeOf } from 'expect-type';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"empty\\",
- setup(__props) {
- const props = __props;
- expectTypeOf().toEqualTypeOf();
- return () => {
- };
- }
+ __name: "empty",
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ expectTypeOf().toEqualTypeOf();
+ const __returned__ = {
+ props,
+ get expectTypeOf() {
+ return expectTypeOf;
+ }
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var empty = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -96,21 +117,33 @@ export { empty as default };
`;
exports[`fixtures > tests/fixtures/empty-defaults.vue 1`] = `
-"import { defineComponent } from 'vue';
+"// empty-defaults.js
+import { defineComponent } from 'vue';
import { expectTypeOf } from 'expect-type';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"empty-defaults\\",
- props: {
- foo: { type: String, required: false }
- },
- setup(__props) {
- const props = __props;
- expectTypeOf().toEqualTypeOf();
- return () => {
- };
- }
+ __name: "empty-defaults",
+ props: { foo: {
+ type: String,
+ required: false
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const props = __props;
+ expectTypeOf().toEqualTypeOf();
+ const __returned__ = {
+ props,
+ get expectTypeOf() {
+ return expectTypeOf;
+ }
+ };
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var emptyDefaults = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
@@ -120,18 +153,26 @@ export { emptyDefaults as default };
`;
exports[`fixtures > tests/fixtures/tsx.vue 1`] = `
-"import { defineComponent } from 'vue';
+"// tsx.js
+import { defineComponent } from 'vue';
import _export_sfc from '[NULL]/plugin-vue/export-helper';
var _sfc_main = /* @__PURE__ */ defineComponent({
- __name: \\"tsx\\",
- props: {
- foo: { type: String, required: false, default: \\"111\\" }
- },
- setup(__props) {
- return () => {
- };
- }
+ __name: "tsx",
+ props: { foo: {
+ type: String,
+ required: false,
+ default: "111"
+ } },
+ setup(__props, { expose: __expose }) {
+ __expose();
+ const __returned__ = {};
+ Object.defineProperty(__returned__, "__isScriptSetup", {
+ enumerable: false,
+ value: true
+ });
+ return __returned__;
+ }
});
var tsx = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]);
diff --git a/packages/chain-call/tests/fixtures.test.ts b/packages/chain-call/tests/fixtures.test.ts
index 9ebca28ef..b8ca3a20a 100644
--- a/packages/chain-call/tests/fixtures.test.ts
+++ b/packages/chain-call/tests/fixtures.test.ts
@@ -1,12 +1,12 @@
import { resolve } from 'node:path'
-import { describe } from 'vitest'
import {
- RollupEsbuildPlugin,
+ rollupBuild,
RollupRemoveVueFilePathPlugin,
RollupVue,
- rollupBuild,
testFixtures,
+ UnpluginOxc,
} from '@vue-macros/test-utils'
+import { describe } from 'vitest'
import { transformChainCall } from '../src/core'
import VueChainCall from '../src/rollup'
@@ -18,20 +18,19 @@ describe('fixtures', async () => {
VueChainCall(),
RollupVue(),
RollupRemoveVueFilePathPlugin(),
- RollupEsbuildPlugin({
- target: 'esnext',
- }),
+ UnpluginOxc.rollup(),
]),
{
cwd: resolve(__dirname, '..'),
promise: true,
- }
+ },
)
await testFixtures(
- import.meta.glob('./fixtures/definePropsRefs.vue', {
+ import.meta.glob('./fixtures/definePropsRefs.vue', {
eager: true,
- as: 'raw',
+ query: '?raw',
+ import: 'default',
}),
- (_, id, code) => transformChainCall(code, id)?.code
+ (_, id, code) => transformChainCall(code, id)?.code,
)
})
diff --git a/packages/chain-call/tests/fixtures/basic.vue b/packages/chain-call/tests/fixtures/basic.vue
index 7646a9c47..1bf219d2c 100644
--- a/packages/chain-call/tests/fixtures/basic.vue
+++ b/packages/chain-call/tests/fixtures/basic.vue
@@ -1,6 +1,6 @@
-
- {{ foo }}
-
diff --git a/packages/chain-call/tests/fixtures/empty-defaults.vue b/packages/chain-call/tests/fixtures/empty-defaults.vue
index 64c2e3913..063691399 100644
--- a/packages/chain-call/tests/fixtures/empty-defaults.vue
+++ b/packages/chain-call/tests/fixtures/empty-defaults.vue
@@ -1,6 +1,6 @@
\n`)
},
}
}
-export function removeMacroImport(node: Node, s: MagicString, offset: number) {
+export function removeMacroImport(
+ node: Node,
+ s: MagicStringAST,
+ offset: number,
+): true | undefined {
if (
node.type === 'ImportDeclaration' &&
node.attributes?.some(
(attr) =>
- resolveString(attr.key) === 'type' && attr.value.value === 'macro'
+ resolveString(attr.key) === 'type' && attr.value.value === 'macro',
)
) {
s.removeNode(node, { offset })
diff --git a/packages/common/tsdown.config.ts b/packages/common/tsdown.config.ts
new file mode 100644
index 000000000..1459ed567
--- /dev/null
+++ b/packages/common/tsdown.config.ts
@@ -0,0 +1,6 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ entry: ['./src/index.ts'],
+ external: ['node:module'],
+})
diff --git a/packages/common/tsup.config.ts b/packages/common/tsup.config.ts
deleted file mode 100644
index 8ec97581c..000000000
--- a/packages/common/tsup.config.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import config from '../../tsup.config.js'
-
-export default {
- ...config,
- entry: ['./src/index.ts'],
-}
diff --git a/packages/config/package.json b/packages/config/package.json
new file mode 100644
index 000000000..81b23879d
--- /dev/null
+++ b/packages/config/package.json
@@ -0,0 +1,110 @@
+{
+ "name": "@vue-macros/config",
+ "version": "3.0.0-beta.21",
+ "description": "Config API for Vue Macros.",
+ "type": "module",
+ "keywords": [
+ "vue-macros",
+ "macros",
+ "vue",
+ "sfc",
+ "setup",
+ "script-setup",
+ "config"
+ ],
+ "license": "MIT",
+ "homepage": "https://vue-macros.dev",
+ "bugs": {
+ "url": "https://github.com/vue-macros/vue-macros/issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/vue-macros/vue-macros.git",
+ "directory": "packages/config"
+ },
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
+ "files": [
+ "dist"
+ ],
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "exports": {
+ ".": {
+ "dev": "./src/index.ts",
+ "default": "./dist/index.js"
+ },
+ "./config": {
+ "dev": "./src/config.ts",
+ "default": "./dist/config.js"
+ },
+ "./define": {
+ "dev": "./src/define.ts",
+ "default": "./dist/define.js"
+ },
+ "./options": {
+ "dev": "./src/options.ts",
+ "default": "./dist/options.js"
+ },
+ "./*": "./*"
+ },
+ "typesVersions": {
+ "*": {
+ "*": [
+ "./dist/*",
+ "./*"
+ ]
+ }
+ },
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./config": "./dist/config.js",
+ "./define": "./dist/define.js",
+ "./options": "./dist/options.js",
+ "./*": "./*"
+ },
+ "tag": "next"
+ },
+ "scripts": {},
+ "dependencies": {
+ "@vue-macros/common": "workspace:*",
+ "quansync": "catalog:",
+ "unconfig": "catalog:"
+ },
+ "devDependencies": {
+ "@vue-macros/better-define": "workspace:*",
+ "@vue-macros/boolean-prop": "workspace:*",
+ "@vue-macros/chain-call": "workspace:*",
+ "@vue-macros/common": "workspace:*",
+ "@vue-macros/define-emit": "workspace:*",
+ "@vue-macros/define-models": "workspace:*",
+ "@vue-macros/define-prop": "workspace:*",
+ "@vue-macros/define-props": "workspace:*",
+ "@vue-macros/define-props-refs": "workspace:*",
+ "@vue-macros/define-render": "workspace:*",
+ "@vue-macros/define-slots": "workspace:*",
+ "@vue-macros/define-stylex": "workspace:*",
+ "@vue-macros/devtools": "workspace:*",
+ "@vue-macros/export-expose": "workspace:*",
+ "@vue-macros/export-props": "workspace:*",
+ "@vue-macros/export-render": "workspace:*",
+ "@vue-macros/hoist-static": "workspace:*",
+ "@vue-macros/jsx-directive": "workspace:*",
+ "@vue-macros/named-template": "workspace:*",
+ "@vue-macros/reactivity-transform": "workspace:*",
+ "@vue-macros/script-lang": "workspace:*",
+ "@vue-macros/setup-block": "workspace:*",
+ "@vue-macros/setup-component": "workspace:*",
+ "@vue-macros/setup-sfc": "workspace:*",
+ "@vue-macros/short-bind": "workspace:*",
+ "@vue-macros/short-emits": "workspace:*",
+ "@vue-macros/short-vmodel": "workspace:*",
+ "unplugin-vue-define-options": "workspace:*"
+ },
+ "engines": {
+ "node": ">=20.18.0"
+ }
+}
diff --git a/packages/config/src/config.ts b/packages/config/src/config.ts
new file mode 100644
index 000000000..873d49a3f
--- /dev/null
+++ b/packages/config/src/config.ts
@@ -0,0 +1,24 @@
+import { quansync, type QuansyncFn } from 'quansync/macro'
+import { loadConfig as _loadConfig } from 'unconfig'
+import type { Options } from './options'
+
+export const loadConfig: QuansyncFn = quansync(
+ async (cwd: string) => {
+ const { config } = await _loadConfig({
+ sources: [
+ {
+ files: 'vue-macros.config',
+ extensions: ['mts', 'cts', 'ts', 'mjs', 'cjs', 'js', 'json', ''],
+ },
+ {
+ files: 'package.json',
+ extensions: [],
+ rewrite: (config: any) => config?.vueMacros,
+ },
+ ],
+ defaults: {},
+ cwd,
+ })
+ return config
+ },
+)
diff --git a/packages/config/src/define.ts b/packages/config/src/define.ts
new file mode 100644
index 000000000..cc2d1b5fe
--- /dev/null
+++ b/packages/config/src/define.ts
@@ -0,0 +1,7 @@
+import type { Options } from './options'
+
+export function defineConfig(
+ config: Omit,
+): Omit {
+ return config
+}
diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts
new file mode 100644
index 000000000..4f7eb381c
--- /dev/null
+++ b/packages/config/src/index.ts
@@ -0,0 +1,3 @@
+export * from './config'
+export * from './define'
+export * from './options'
diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts
new file mode 100644
index 000000000..40fbe751e
--- /dev/null
+++ b/packages/config/src/options.ts
@@ -0,0 +1,297 @@
+/* eslint perfectionist/sort-imports: ["error", {
+ customGroups: {
+ "value": {
+ "vue-macros": ["@vue-macros/.*", "unplugin-vue-define-options"]
+ },
+ },
+ groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'vue-macros'],
+ internalPattern: ['#.*'],
+ newlinesBetween: 'ignore',
+}] */
+/* eslint perfectionist/sort-interfaces: ["error", { ignorePattern: ["OptionsCommon"] }] */
+/* eslint perfectionist/sort-objects: ["error", { partitionByNewLine: true }] */
+
+import process from 'node:process'
+import { quansync, type QuansyncFn } from 'quansync/macro'
+import { loadConfig } from './config'
+
+import type { Options as OptionsBetterDefine } from '@vue-macros/better-define'
+import type { Options as OptionsBooleanProp } from '@vue-macros/boolean-prop'
+import type { Options as OptionsChainCall } from '@vue-macros/chain-call'
+import {
+ detectVueVersion,
+ type BaseOptions,
+ type FilterOptions,
+} from '@vue-macros/common'
+import type { Options as OptionsDefineEmit } from '@vue-macros/define-emit'
+import type { Options as OptionsDefineModels } from '@vue-macros/define-models'
+import type { Options as OptionsDefineProp } from '@vue-macros/define-prop'
+import type { Options as OptionsDefineProps } from '@vue-macros/define-props'
+import type { Options as OptionsDefinePropsRefs } from '@vue-macros/define-props-refs'
+import type { Options as OptionsDefineRender } from '@vue-macros/define-render'
+import type { Options as OptionsDefineSlots } from '@vue-macros/define-slots'
+import type { Options as OptionsDefineStyleX } from '@vue-macros/define-stylex'
+import type { Options as OptionsExportExpose } from '@vue-macros/export-expose'
+import type { Options as OptionsExportProps } from '@vue-macros/export-props'
+import type { Options as OptionsExportRender } from '@vue-macros/export-render'
+import type { Options as OptionsHoistStatic } from '@vue-macros/hoist-static'
+import type { Options as OptionsJsxDirective } from '@vue-macros/jsx-directive'
+import type { Options as OptionsNamedTemplate } from '@vue-macros/named-template'
+import type { Options as OptionsReactivityTransform } from '@vue-macros/reactivity-transform'
+import type { Options as OptionsScriptLang } from '@vue-macros/script-lang'
+import type { Options as OptionsSetupBlock } from '@vue-macros/setup-block'
+import type { Options as OptionsSetupComponent } from '@vue-macros/setup-component'
+import type { Options as OptionsSetupSFC } from '@vue-macros/setup-sfc'
+import type { Options as OptionsShortBind } from '@vue-macros/short-bind'
+import type { Options as OptionsShortEmits } from '@vue-macros/short-emits'
+import type { Options as OptionsShortVmodel } from '@vue-macros/short-vmodel'
+import type { Options as OptionsDefineOptions } from 'unplugin-vue-define-options'
+
+export interface OptionsCommon extends Omit {
+ root?: string
+ plugins?: {
+ vue?: any
+ vueJsx?: any
+ vueRouter?: any
+ }
+ /** @internal */
+ nuxtContext?: {
+ isClient?: boolean
+ }
+}
+
+export interface FeatureOptionsMap {
+ /**
+ * @see {@link https://vue-macros.dev/features/better-define.html}
+ * @default true
+ */
+ betterDefine: OptionsBetterDefine
+ /**
+ * @see {@link https://vue-macros.dev/features/boolean-prop.html}
+ * @default false
+ */
+ booleanProp: OptionsBooleanProp
+ /**
+ * @see {@link https://vue-macros.dev/macros/chain-call.html}
+ * @default true
+ */
+ chainCall: OptionsChainCall
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-emit.html}
+ * @default true
+ */
+ defineEmit: OptionsDefineEmit
+ /**
+ * @see {@link https://vue-macros.dev/volar/define-generic.html}
+ * @default true
+ */
+ defineGeneric: FilterOptions
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-models.html}
+ * @default true
+ */
+ defineModels: OptionsDefineModels
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-options.html}
+ * @default vueVersion < 3.3
+ */
+ defineOptions: OptionsDefineOptions
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-prop.html}
+ * @default true
+ */
+ defineProp: OptionsDefineProp
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-props.html}
+ * @default true
+ */
+ defineProps: OptionsDefineProps
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-props-refs.html}
+ * @default true
+ */
+ definePropsRefs: OptionsDefinePropsRefs
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-render.html}
+ * @default true
+ */
+ defineRender: OptionsDefineRender
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-slots.html}
+ * @default vueVersion < 3.3
+ */
+ defineSlots: OptionsDefineSlots
+ /**
+ * @see {@link https://vue-macros.dev/macros/define-stylex.html}
+ * @default false
+ */
+ defineStyleX: OptionsDefineStyleX
+ /**
+ * @see {@link https://vue-macros.dev/features/export-expose.html}
+ * @default false
+ */
+ exportExpose: OptionsExportExpose
+ /**
+ * @see {@link https://vue-macros.dev/features/export-props.html}
+ * @default false
+ */
+ exportProps: OptionsExportProps
+ /**
+ * @see {@link https://vue-macros.dev/features/export-render.html}
+ * @default false
+ */
+ exportRender: OptionsExportRender
+ /**
+ * @see {@link https://vue-macros.dev/features/hoist-static.html}
+ * @default true
+ */
+ hoistStatic: OptionsHoistStatic
+ /**
+ * @see {@link https://vue-macros.dev/features/jsx-directive.html}
+ * @default true
+ */
+ jsxDirective: OptionsJsxDirective
+ /**
+ * @see {@link https://vue-macros.dev/features/jsx-ref.html}
+ * @default false
+ */
+ jsxRef: FilterOptions & { alias?: string[] }
+ /**
+ * @see {@link https://vue-macros.dev/features/named-template.html}
+ * @default false
+ * @deprecated Not actively maintained now. Try [createReusableTemplate](https://vueuse.org/core/createReusableTemplate/) instead.
+ */
+ namedTemplate: OptionsNamedTemplate
+ /**
+ * @see {@link https://vue-macros.dev/features/reactivity-transform.html}
+ * @default true
+ */
+ reactivityTransform: OptionsReactivityTransform
+ /**
+ * @see {@link https://vue-macros.dev/features/script-lang.html}
+ * @default false
+ */
+ scriptLang: OptionsScriptLang
+ /**
+ * @see {@link https://vue-macros.dev/volar/script-sfc.html}
+ * @default false
+ */
+ scriptSFC: FilterOptions
+ /**
+ * **experimental**: unpublished feature
+ * @default false
+ */
+ setupBlock: OptionsSetupBlock
+ /**
+ * @see {@link https://vue-macros.dev/macros/setup-component.html}
+ * @default true
+ */
+ setupComponent: OptionsSetupComponent
+ /**
+ * @see {@link https://vue-macros.dev/volar/setup-jsdoc.html}
+ * @default true
+ */
+ setupJsdoc: FilterOptions
+ /**
+ * @see {@link https://vue-macros.dev/macros/setup-sfc.html}
+ * @default false
+ */
+ setupSFC: OptionsSetupSFC
+ /**
+ * @see {@link https://vue-macros.dev/features/short-bind.html}
+ * @default vueVersion < 3.4
+ */
+ shortBind: OptionsShortBind
+ /**
+ * @see {@link https://vue-macros.dev/macros/short-emits.html}
+ * @default vueVersion < 3.3
+ */
+ shortEmits: OptionsShortEmits
+ /**
+ * @see {@link https://vue-macros.dev/macros/short-vmodel.html}
+ * @default true
+ */
+ shortVmodel: OptionsShortVmodel
+}
+export type FeatureName = keyof FeatureOptionsMap
+export type FeatureOptions = FeatureOptionsMap[FeatureName]
+
+type OptionalSubOptions = boolean | Omit | undefined
+export type Options = OptionsCommon & {
+ [K in keyof FeatureOptionsMap]?: OptionalSubOptions
+}
+
+export type OptionsResolved = Required & {
+ [K in keyof FeatureOptionsMap]: false | FeatureOptionsMap[K]
+}
+
+export const resolveOptions: QuansyncFn<
+ OptionsResolved,
+ [options?: Options | undefined, cwd?: string | undefined]
+> = quansync(async (options?: Options, cwd: string = process.cwd()) => {
+ const config = await loadConfig(cwd)
+
+ let { isProduction, nuxtContext, plugins, root, version, ...subOptions } = {
+ ...config,
+ ...options,
+ }
+
+ root = root || cwd
+ version = version || detectVueVersion(root)
+ isProduction = isProduction ?? process.env.NODE_ENV === 'production'
+
+ const globalOptions = { isProduction, root, version }
+ return {
+ isProduction,
+ nuxtContext: nuxtContext || {},
+ plugins: plugins || {},
+ root,
+ version,
+
+ betterDefine: resolveSubOptions('betterDefine'),
+ booleanProp: resolveSubOptions('booleanProp', false),
+ chainCall: resolveSubOptions('chainCall'),
+ defineEmit: resolveSubOptions('defineEmit'),
+ defineGeneric: resolveSubOptions('defineGeneric'),
+ defineModels: resolveSubOptions('defineModels'),
+ defineOptions: resolveSubOptions('defineOptions', 3.3),
+ defineProp: resolveSubOptions('defineProp'),
+ defineProps: resolveSubOptions('defineProps'),
+ definePropsRefs: resolveSubOptions('definePropsRefs'),
+ defineRender: resolveSubOptions('defineRender'),
+ defineSlots: resolveSubOptions('defineSlots', 3.3),
+ defineStyleX: resolveSubOptions('defineStyleX', false),
+ exportExpose: resolveSubOptions('exportExpose', false),
+ exportProps: resolveSubOptions('exportProps', false),
+ exportRender: resolveSubOptions('exportRender', false),
+ hoistStatic: resolveSubOptions('hoistStatic'),
+ jsxDirective: resolveSubOptions('jsxDirective'),
+ jsxRef: resolveSubOptions('jsxRef', false),
+ namedTemplate: resolveSubOptions('namedTemplate'),
+ reactivityTransform: resolveSubOptions('reactivityTransform'),
+ scriptLang: resolveSubOptions('scriptLang', false),
+ scriptSFC: resolveSubOptions('scriptSFC', false),
+ setupBlock: resolveSubOptions('setupBlock', false),
+ setupComponent: resolveSubOptions('setupComponent'),
+ setupJsdoc: resolveSubOptions('setupJsdoc'),
+ setupSFC: resolveSubOptions('setupSFC', false),
+ shortBind: resolveSubOptions('shortBind', 3.4),
+ shortEmits: resolveSubOptions('shortEmits', 3.3),
+ shortVmodel: resolveSubOptions('shortVmodel'),
+ }
+
+ function resolveSubOptions(
+ name: K,
+ belowVersion: boolean | number = true,
+ ): FeatureOptionsMap[K] | false {
+ const defaultEnabled =
+ typeof belowVersion === 'boolean' ? belowVersion : version! < belowVersion
+ const options: OptionalSubOptions =
+ subOptions[name] ?? defaultEnabled
+ if (!options) return false
+ return {
+ ...globalOptions,
+ ...(options === true ? {} : options),
+ }
+ }
+})
diff --git a/packages/config/tsdown.config.ts b/packages/config/tsdown.config.ts
new file mode 100644
index 000000000..3d82d8e38
--- /dev/null
+++ b/packages/config/tsdown.config.ts
@@ -0,0 +1,5 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ platform: 'node',
+})
diff --git a/packages/define-emit/CHANGELOG.md b/packages/define-emit/CHANGELOG.md
deleted file mode 100644
index a2fd462a8..000000000
--- a/packages/define-emit/CHANGELOG.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# @vue-macros/define-emit
-
-## 0.1.10
-
-### Patch Changes
-
-- Updated dependencies [[`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741), [`20367274`](https://github.com/vue-macros/vue-macros/commit/2036727443c659eb84037eae85c5ac565521dd3e), [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb)]:
- - @vue-macros/common@1.6.0
- - @vue-macros/api@0.8.0
-
-## 0.1.9
-
-### Patch Changes
-
-- Updated dependencies [[`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779)]:
- - @vue-macros/common@1.5.0
- - @vue-macros/api@0.7.4
-
-## 0.1.8
-
-### Patch Changes
-
-- [`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4) Thanks [@sxzz](https://github.com/sxzz)! - add types for both esm and cjs
-
-- Updated dependencies [[`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4)]:
- - @vue-macros/common@1.4.1
- - @vue-macros/api@0.7.3
-
-## 0.1.7
-
-### Patch Changes
-
-- [`14bda40b`](https://github.com/vue-macros/vue-macros/commit/14bda40b21bf41ecedb7dd674f3e0c5828ae0414) Thanks [@sxzz](https://github.com/sxzz)! - add type fallback for all TS versions
-
-## 0.1.6
-
-### Patch Changes
-
-- [`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219) Thanks [@sxzz](https://github.com/sxzz)! - Switch to ast-kit
-
-- [`e877a5d`](https://github.com/vue-macros/vue-macros/commit/e877a5da35fdf0bb0f302877597b33512e963f11) Thanks [@sxzz](https://github.com/sxzz)! - upgrade eslint-config
-
-- [`edee536`](https://github.com/vue-macros/vue-macros/commit/edee5363cdb5aa939d79a0b55adf8571580562a4) Thanks [@sxzz](https://github.com/sxzz)! - add build config
-
-- Updated dependencies [[`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219), [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88), [`ee4e093`](https://github.com/vue-macros/vue-macros/commit/ee4e093ec07931da9d24ded155a153e3496b4c7b)]:
- - @vue-macros/common@1.4.0
- - @vue-macros/api@0.7.2
-
-## 0.1.5
-
-### Patch Changes
-
-- Updated dependencies [[`34be70e`](https://github.com/vue-macros/vue-macros/commit/34be70e5b3e37615b563da02bff5ae89de63b713)]:
- - @vue-macros/common@1.3.3
- - @vue-macros/api@0.7.1
-
-## 0.1.4
-
-### Patch Changes
-
-- Updated dependencies [[`65a04b2`](https://github.com/vue-macros/vue-macros/commit/65a04b2c7d0c71fd696cf80370fc78405c621a42), [`39c72ff`](https://github.com/vue-macros/vue-macros/commit/39c72ff0f351b9b2d7eb5ad22e2a8b98f7a263a0)]:
- - @vue-macros/api@0.7.0
- - @vue-macros/common@1.3.2
-
-## 0.1.3
-
-### Patch Changes
-
-- Updated dependencies [[`90a1862`](https://github.com/vue-macros/vue-macros/commit/90a186263021114924c35bae537bb463fb3a4c32)]:
- - @vue-macros/api@0.6.3
-
-## 0.1.2
-
-### Patch Changes
-
-- Updated dependencies [[`ed7ca8c`](https://github.com/vue-macros/vue-macros/commit/ed7ca8cd1fc334fb3cf5b96ee6b64e55c7390d61)]:
- - @vue-macros/common@1.3.1
- - @vue-macros/api@0.6.2
-
-## 0.1.1
-
-### Patch Changes
-
-- Updated dependencies [[`791b2f3`](https://github.com/vue-macros/vue-macros/commit/791b2f31684c4156c4d3f26a4b22e06ab2c678f7)]:
- - @vue-macros/api@0.6.1
-
-## 0.1.0
-
-### Minor Changes
-
-- [`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f) Thanks [@sxzz](https://github.com/sxzz)! - separate `defineProp` and `defineEmit`
-
-### Patch Changes
-
-- [#347](https://github.com/vue-macros/vue-macros/pull/347) [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1) Thanks [@kekexunxun](https://github.com/kekexunxun)! - fix include regex
-
-- Updated dependencies [[`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f), [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1), [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d)]:
- - @vue-macros/api@0.6.0
- - @vue-macros/common@1.3.0
diff --git a/packages/define-emit/macros.d.ts b/packages/define-emit/macros.d.ts
index 25ddf93d0..2acda7bf3 100644
--- a/packages/define-emit/macros.d.ts
+++ b/packages/define-emit/macros.d.ts
@@ -1,12 +1,12 @@
type MaybeTupleFunction = T extends any[]
? (...args: T) => R
: T extends (...args: any) => any
- ? (...args: Parameters) => R
- : T
+ ? (...args: Parameters) => R
+ : T
export declare function defineEmit<
T extends ((...args: any) => any) | any[] = any[],
>(
emitName?: string,
- validator?: MaybeTupleFunction
+ validator?: MaybeTupleFunction,
): MaybeTupleFunction
diff --git a/packages/define-emit/package.json b/packages/define-emit/package.json
index 39e2a15cd..007a3d873 100644
--- a/packages/define-emit/package.json
+++ b/packages/define-emit/package.json
@@ -1,8 +1,8 @@
{
"name": "@vue-macros/define-emit",
- "version": "0.1.10",
- "packageManager": "pnpm@8.6.10",
- "description": "define-emit feature from Vue Macros.",
+ "version": "3.0.0-beta.21",
+ "description": "defineEmit feature from Vue Macros.",
+ "type": "module",
"keywords": [
"vue-macros",
"macros",
@@ -14,7 +14,7 @@
"unplugin"
],
"license": "MIT",
- "homepage": "https://github.com/vue-macros/vue-macros#readme",
+ "homepage": "https://vue-macros.dev",
"bugs": {
"url": "https://github.com/vue-macros/vue-macros/issues"
},
@@ -23,68 +23,47 @@
"url": "git+https://github.com/vue-macros/vue-macros.git",
"directory": "packages/define-emit"
},
- "author": "三咲智子 ",
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
"files": [
"*.d.ts",
"dist"
],
- "main": "dist/index.js",
- "module": "dist/index.mjs",
- "types": "dist/index.d.ts",
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
"exports": {
".": {
"dev": "./src/index.ts",
- "types": {
- "require": "./dist/index.d.ts",
- "import": "./dist/index.d.mts"
- },
- "require": "./dist/index.js",
- "import": "./dist/index.mjs"
+ "default": "./dist/index.js"
},
"./api": {
"dev": "./src/api.ts",
- "types": {
- "require": "./dist/api.d.ts",
- "import": "./dist/api.d.mts"
- },
- "require": "./dist/api.js",
- "import": "./dist/api.mjs"
+ "default": "./dist/api.js"
},
"./esbuild": {
"dev": "./src/esbuild.ts",
- "types": {
- "require": "./dist/esbuild.d.ts",
- "import": "./dist/esbuild.d.mts"
- },
- "require": "./dist/esbuild.js",
- "import": "./dist/esbuild.mjs"
+ "default": "./dist/esbuild.js"
+ },
+ "./rolldown": {
+ "dev": "./src/rolldown.ts",
+ "default": "./dist/rolldown.js"
},
"./rollup": {
"dev": "./src/rollup.ts",
- "types": {
- "require": "./dist/rollup.d.ts",
- "import": "./dist/rollup.d.mts"
- },
- "require": "./dist/rollup.js",
- "import": "./dist/rollup.mjs"
+ "default": "./dist/rollup.js"
+ },
+ "./rspack": {
+ "dev": "./src/rspack.ts",
+ "default": "./dist/rspack.js"
},
"./vite": {
"dev": "./src/vite.ts",
- "types": {
- "require": "./dist/vite.d.ts",
- "import": "./dist/vite.d.mts"
- },
- "require": "./dist/vite.js",
- "import": "./dist/vite.mjs"
+ "default": "./dist/vite.js"
},
"./webpack": {
"dev": "./src/webpack.ts",
- "types": {
- "require": "./dist/webpack.d.ts",
- "import": "./dist/webpack.d.mts"
- },
- "require": "./dist/webpack.js",
- "import": "./dist/webpack.mjs"
+ "default": "./dist/webpack.js"
},
"./*": [
"./*",
@@ -99,23 +78,36 @@
]
}
},
- "scripts": {
- "build": "tsup && tsx ../../scripts/postbuild.ts",
- "dev": "DEV=true tsup"
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./api": "./dist/api.js",
+ "./esbuild": "./dist/esbuild.js",
+ "./rolldown": "./dist/rolldown.js",
+ "./rollup": "./dist/rollup.js",
+ "./rspack": "./dist/rspack.js",
+ "./vite": "./dist/vite.js",
+ "./webpack": "./dist/webpack.js",
+ "./*": [
+ "./*",
+ "./*.d.ts"
+ ]
+ },
+ "tag": "next"
},
+ "scripts": {},
"peerDependencies": {
"vue": "^2.7.0 || ^3.2.25"
},
"dependencies": {
- "@vue-macros/api": "workspace:*",
"@vue-macros/common": "workspace:*",
- "rollup": "^3.26.3",
- "unplugin": "^1.4.0"
+ "unplugin": "catalog:"
},
"devDependencies": {
- "vue": "^3.3.4"
+ "vue": "catalog:"
},
"engines": {
- "node": ">=16.14.0"
+ "node": ">=20.18.0"
}
}
diff --git a/packages/define-emit/src/core/index.ts b/packages/define-emit/src/core/index.ts
index 3bca61ff4..3fce5254b 100644
--- a/packages/define-emit/src/core/index.ts
+++ b/packages/define-emit/src/core/index.ts
@@ -1,81 +1,84 @@
import {
DEFINE_EMIT,
- HELPER_PREFIX,
- MagicString,
escapeKey,
- getTransformResult,
+ generateTransform,
+ HELPER_PREFIX,
isCallOf,
+ MagicStringAST,
parseSFC,
- walkASTSetup,
+ walkAST,
+ type CodeTransform,
} from '@vue-macros/common'
import type * as t from '@babel/types'
-export const EMIT_VARIABLE_NAME = `${HELPER_PREFIX}emit`
+export const EMIT_VARIABLE_NAME: '__MACROS_emit' = `${HELPER_PREFIX}emit`
export interface Emit {
name: string
validator?: string
}
-export async function transformDefineEmit(code: string, id: string) {
+export function transformDefineEmit(
+ code: string,
+ id: string,
+): CodeTransform | undefined {
if (!code.includes(DEFINE_EMIT)) return
const { scriptSetup, getSetupAst } = parseSFC(code, id)
if (!scriptSetup) return
const offset = scriptSetup.loc.start.offset
- const s = new MagicString(code)
+ const s = new MagicStringAST(code)
const setupAst = getSetupAst()!
const emits: Emit[] = []
- await walkASTSetup(setupAst, (setup) => {
- setup.onEnter(
- (node): node is t.CallExpression => isCallOf(node, DEFINE_EMIT),
- (node, parent) => {
- const [name, validator] = node.arguments
- let emitName: string
- if (!name) {
- if (
- parent?.type !== 'VariableDeclarator' ||
- parent.id.type !== 'Identifier'
- ) {
- throw new Error(
- `A variable must be used to receive the return value of ${DEFINE_EMIT}.`
- )
- }
- emitName = parent.id.name
- } else if (name.type !== 'StringLiteral') {
+ walkAST(setupAst, {
+ enter(node, parent) {
+ if (!isCallOf(node, DEFINE_EMIT)) return
+
+ const [name, validator] = node.arguments
+ let emitName: string
+ if (!name) {
+ if (
+ parent?.type !== 'VariableDeclarator' ||
+ parent.id.type !== 'Identifier'
+ ) {
throw new Error(
- `The first argument of ${DEFINE_EMIT} must be a string literal.`
+ `A variable must be used to receive the return value of ${DEFINE_EMIT}.`,
)
- } else {
- emitName = name.value
}
-
- emits.push({
- name: emitName,
- validator: validator ? s.sliceNode(validator, { offset }) : undefined,
- })
-
- s.overwriteNode(
- node,
- `(...args) => ${EMIT_VARIABLE_NAME}(${JSON.stringify(
- emitName
- )}, ...args)`,
- { offset }
+ emitName = parent.id.name
+ } else if (name.type !== 'StringLiteral') {
+ throw new Error(
+ `The first argument of ${DEFINE_EMIT} must be a string literal.`,
)
+ } else {
+ emitName = name.value
}
- )
+
+ emits.push({
+ name: emitName,
+ validator: validator ? s.sliceNode(validator, { offset }) : undefined,
+ })
+
+ s.overwriteNode(
+ node,
+ `(...args) => ${EMIT_VARIABLE_NAME}(${JSON.stringify(
+ emitName,
+ )}, ...args)`,
+ { offset },
+ )
+ },
})
if (emits.length > 0) {
s.prependLeft(
offset!,
- `\nconst ${EMIT_VARIABLE_NAME} = defineEmits(${mountEmits()})\n`
+ `\nconst ${EMIT_VARIABLE_NAME} = defineEmits(${mountEmits()})\n`,
)
}
- return getTransformResult(s, id)
+ return generateTransform(s, id)
function mountEmits() {
const isAllWithoutOptions = emits.every(({ validator }) => !validator)
@@ -87,7 +90,7 @@ export async function transformDefineEmit(code: string, id: string) {
return `{
${emits
.map(
- ({ name, validator }) => `${escapeKey(name)}: ${validator || `null`}`
+ ({ name, validator }) => `${escapeKey(name)}: ${validator || `null`}`,
)
.join(',\n ')}
}`
diff --git a/packages/define-emit/src/esbuild.ts b/packages/define-emit/src/esbuild.ts
index 71f1e0952..e8c6460dd 100644
--- a/packages/define-emit/src/esbuild.ts
+++ b/packages/define-emit/src/esbuild.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.esbuild
+export default unplugin.esbuild as typeof unplugin.esbuild
diff --git a/packages/define-emit/src/index.ts b/packages/define-emit/src/index.ts
index f2da8d10e..13018f93d 100644
--- a/packages/define-emit/src/index.ts
+++ b/packages/define-emit/src/index.ts
@@ -1,69 +1,63 @@
-import { createUnplugin } from 'unplugin'
+import process from 'node:process'
import {
- type BaseOptions,
- type MarkRequired,
- REGEX_SETUP_SFC,
- REGEX_VUE_SFC,
- REGEX_VUE_SUB,
createFilter,
detectVueVersion,
+ FilterFileType,
+ getFilterPattern,
+ type BaseOptions,
+ type MarkRequired,
} from '@vue-macros/common'
-import { RollupResolve, setResolveTSFileIdImpl } from '@vue-macros/api'
-import { type PluginContext } from 'rollup'
+import { generatePluginName } from '#macros' with { type: 'macro' }
+import {
+ createUnplugin,
+ type UnpluginContextMeta,
+ type UnpluginInstance,
+} from 'unplugin'
import { transformDefineEmit } from './core'
-export interface Options extends BaseOptions {
- isProduction?: boolean
-}
-
+export type Options = BaseOptions
export type OptionsResolved = MarkRequired<
Options,
'include' | 'version' | 'isProduction'
>
-function resolveOption(options: Options): OptionsResolved {
+function resolveOptions(
+ options: Options,
+ framework: UnpluginContextMeta['framework'],
+): OptionsResolved {
const version = options.version || detectVueVersion()
+ const include = getFilterPattern(
+ [FilterFileType.VUE_SFC_WITH_SETUP, FilterFileType.SETUP_SFC],
+ framework,
+ )
return {
- include: [REGEX_VUE_SFC, REGEX_SETUP_SFC, REGEX_VUE_SUB],
+ include,
isProduction: process.env.NODE_ENV === 'production',
...options,
version,
}
}
-const name = 'unplugin-vue-define-emit'
+const name = generatePluginName()
-export default createUnplugin(
+const plugin: UnpluginInstance = createUnplugin(
(userOptions = {}, { framework }) => {
- const options = resolveOption(userOptions)
+ const options = resolveOptions(userOptions, framework)
const filter = createFilter(options)
- const { resolve, handleHotUpdate } = RollupResolve()
return {
name,
enforce: 'pre',
- buildStart() {
- if (framework === 'rollup' || framework === 'vite') {
- setResolveTSFileIdImpl(resolve(this as PluginContext))
- }
- },
-
- transformInclude(id) {
- return filter(id)
- },
-
- transform(code, id) {
- return transformDefineEmit(code, id)
- },
+ transformInclude: filter,
+ transform: transformDefineEmit,
vite: {
configResolved(config) {
- options.isProduction = config.isProduction
+ options.isProduction ??= config.isProduction
},
-
- handleHotUpdate,
},
}
- }
+ },
)
+export default plugin
diff --git a/packages/define-emit/src/rolldown.ts b/packages/define-emit/src/rolldown.ts
new file mode 100644
index 000000000..082a55c18
--- /dev/null
+++ b/packages/define-emit/src/rolldown.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rolldown as typeof unplugin.rolldown
diff --git a/packages/define-emit/src/rollup.ts b/packages/define-emit/src/rollup.ts
index ed6909cd3..45545feb1 100644
--- a/packages/define-emit/src/rollup.ts
+++ b/packages/define-emit/src/rollup.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.rollup
+export default unplugin.rollup as typeof unplugin.rollup
diff --git a/packages/define-emit/src/rspack.ts b/packages/define-emit/src/rspack.ts
new file mode 100644
index 000000000..6df8a0299
--- /dev/null
+++ b/packages/define-emit/src/rspack.ts
@@ -0,0 +1,3 @@
+import unplugin from '.'
+
+export default unplugin.rspack as typeof unplugin.rspack
diff --git a/packages/define-emit/src/vite.ts b/packages/define-emit/src/vite.ts
index 589f4b964..a7c5db2c1 100644
--- a/packages/define-emit/src/vite.ts
+++ b/packages/define-emit/src/vite.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.vite
+export default unplugin.vite as typeof unplugin.vite
diff --git a/packages/define-emit/src/webpack.ts b/packages/define-emit/src/webpack.ts
index 83091ee31..74c1c9020 100644
--- a/packages/define-emit/src/webpack.ts
+++ b/packages/define-emit/src/webpack.ts
@@ -1,3 +1,3 @@
import unplugin from '.'
-export default unplugin.webpack
+export default unplugin.webpack as typeof unplugin.webpack
diff --git a/packages/define-emit/tests/__snapshots__/fixtures.test.ts.snap b/packages/define-emit/tests/__snapshots__/fixtures.test.ts.snap
index 7b882c1bd..825c25fef 100644
--- a/packages/define-emit/tests/__snapshots__/fixtures.test.ts.snap
+++ b/packages/define-emit/tests/__snapshots__/fixtures.test.ts.snap
@@ -1,30 +1,31 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`fixtures > tests/fixtures/define-emit.vue 1`] = `
-"var defineEmit = \`
\`;
diff --git a/packages/define-emit/tests/define-emit.test.ts b/packages/define-emit/tests/define-emit.test.ts
index c14ce2beb..3fc836c89 100644
--- a/packages/define-emit/tests/define-emit.test.ts
+++ b/packages/define-emit/tests/define-emit.test.ts
@@ -1,5 +1,5 @@
-import { describe, expect, it } from 'vitest'
import { removeSpaces } from '@vue-macros/test-utils'
+import { describe, expect, it } from 'vitest'
import { EMIT_VARIABLE_NAME, transformDefineEmit } from '../src/core'
describe('defineEmit', () => {
@@ -13,13 +13,13 @@ describe('defineEmit', () => {
`,
- 'test.vue'
+ 'test.vue',
)
const code = removeSpaces(result!.code)
expect(code).includes(`const ${EMIT_VARIABLE_NAME} = defineEmits(["foo"])`)
expect(code).includes(
- `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`
+ `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`,
)
})
@@ -33,16 +33,16 @@ describe('defineEmit', () => {
`,
- 'test.vue'
+ 'test.vue',
)
const code = removeSpaces(result!.code)
expect(code).includes(
- `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`
+ `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`,
)
expect(code).includes(
- `const ${EMIT_VARIABLE_NAME} = defineEmits({ foo: (payload) => payload.length > 0 })`
+ `const ${EMIT_VARIABLE_NAME} = defineEmits({ foo: (payload) => payload.length > 0 })`,
)
})
@@ -53,19 +53,19 @@ describe('defineEmit', () => {
const foo = defineEmit('foo')
const bar = defineEmit('bar')
`,
- 'test.vue'
+ 'test.vue',
)
const code = result?.code ? result.code.trim().replaceAll(/\s+/g, ' ') : ''
expect(code).includes(
- `const ${EMIT_VARIABLE_NAME} = defineEmits(["foo", "bar"])`
+ `const ${EMIT_VARIABLE_NAME} = defineEmits(["foo", "bar"])`,
)
expect(code).includes(
- `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`
+ `const foo = (...args) => ${EMIT_VARIABLE_NAME}("foo", ...args)`,
)
expect(code).includes(
- `const bar = (...args) => ${EMIT_VARIABLE_NAME}("bar", ...args)`
+ `const bar = (...args) => ${EMIT_VARIABLE_NAME}("bar", ...args)`,
)
})
})
diff --git a/packages/define-emit/tests/fixtures.test.ts b/packages/define-emit/tests/fixtures.test.ts
index ddb120412..1fb4c1678 100644
--- a/packages/define-emit/tests/fixtures.test.ts
+++ b/packages/define-emit/tests/fixtures.test.ts
@@ -1,11 +1,11 @@
import { resolve } from 'node:path'
-import { describe } from 'vitest'
import {
- RollupEsbuildPlugin,
- RollupToStringPlugin,
rollupBuild,
+ RollupToStringPlugin,
testFixtures,
+ UnpluginOxc,
} from '@vue-macros/test-utils'
+import { describe } from 'vitest'
import VueDefineEmit from '../src/rollup'
describe('fixtures', async () => {
@@ -15,10 +15,8 @@ describe('fixtures', async () => {
rollupBuild(id, [
VueDefineEmit({ isProduction: false }),
RollupToStringPlugin(),
- RollupEsbuildPlugin({
- target: 'esnext',
- }),
+ UnpluginOxc.rollup(),
]),
- { cwd: resolve(__dirname, '..'), promise: true }
+ { cwd: resolve(__dirname, '..'), promise: true },
)
})
diff --git a/packages/define-emit/tests/fixtures/define-emit.vue b/packages/define-emit/tests/fixtures/define-emit.vue
index 50a82dba2..78b1e1c53 100644
--- a/packages/define-emit/tests/fixtures/define-emit.vue
+++ b/packages/define-emit/tests/fixtures/define-emit.vue
@@ -9,13 +9,13 @@ expectTypeOf(bar).toEqualTypeOf<(value: string) => void>()
const baz = defineEmit<(value: number) => void>(
'baz',
- (value) => typeof value === 'number'
+ (value) => typeof value === 'number',
)
expectTypeOf(baz).toEqualTypeOf<(value: number) => void>()
const qux = defineEmit<[value: string]>(
- 'baz',
- (value) => typeof value === 'string'
+ 'qux',
+ (value) => typeof value === 'string',
)
expectTypeOf(qux).toEqualTypeOf<(value: string) => void>()
diff --git a/packages/define-emit/tsdown.config.ts b/packages/define-emit/tsdown.config.ts
new file mode 100644
index 000000000..3d82d8e38
--- /dev/null
+++ b/packages/define-emit/tsdown.config.ts
@@ -0,0 +1,5 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ platform: 'node',
+})
diff --git a/packages/define-emit/tsup.config.ts b/packages/define-emit/tsup.config.ts
deleted file mode 100644
index 1605eae16..000000000
--- a/packages/define-emit/tsup.config.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from '../../tsup.config.js'
diff --git a/packages/define-models/CHANGELOG.md b/packages/define-models/CHANGELOG.md
deleted file mode 100644
index 95892e40f..000000000
--- a/packages/define-models/CHANGELOG.md
+++ /dev/null
@@ -1,369 +0,0 @@
-# @vue-macros/define-model
-
-## 1.0.10
-
-### Patch Changes
-
-- [`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741) Thanks [@sxzz](https://github.com/sxzz)! - refactor: replace `{}` with `Object.create(null)`
-
-- Updated dependencies [[`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741), [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb)]:
- - @vue-macros/common@1.6.0
-
-## 1.0.9
-
-### Patch Changes
-
-- [`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779) Thanks [@sxzz](https://github.com/sxzz)! - refactor: reuse resolveObjectKey from ast-kit
-
-- Updated dependencies [[`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779)]:
- - @vue-macros/common@1.5.0
-
-## 1.0.8
-
-### Patch Changes
-
-- [`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4) Thanks [@sxzz](https://github.com/sxzz)! - add types for both esm and cjs
-
-- Updated dependencies [[`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4)]:
- - @vue-macros/common@1.4.1
-
-## 1.0.7
-
-### Patch Changes
-
-- [`14bda40b`](https://github.com/vue-macros/vue-macros/commit/14bda40b21bf41ecedb7dd674f3e0c5828ae0414) Thanks [@sxzz](https://github.com/sxzz)! - add type fallback for all TS versions
-
-## 1.0.6
-
-### Patch Changes
-
-- [`abd3f06`](https://github.com/vue-macros/vue-macros/commit/abd3f069893c5a3e428a3bcaa97b1f2ceedbd342) Thanks [@sxzz](https://github.com/sxzz)! - normalize virtual file path
-
-- Updated dependencies [[`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219), [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88), [`ee4e093`](https://github.com/vue-macros/vue-macros/commit/ee4e093ec07931da9d24ded155a153e3496b4c7b)]:
- - @vue-macros/common@1.4.0
-
-## 1.0.5
-
-### Patch Changes
-
-- Updated dependencies [[`34be70e`](https://github.com/vue-macros/vue-macros/commit/34be70e5b3e37615b563da02bff5ae89de63b713)]:
- - @vue-macros/common@1.3.3
-
-## 1.0.4
-
-### Patch Changes
-
-- Updated dependencies [[`39c72ff`](https://github.com/vue-macros/vue-macros/commit/39c72ff0f351b9b2d7eb5ad22e2a8b98f7a263a0)]:
- - @vue-macros/common@1.3.2
-
-## 1.0.3
-
-### Patch Changes
-
-- [`96c0721`](https://github.com/vue-macros/vue-macros/commit/96c07214801f9d76b683d4a826686997bd598f5d) Thanks [@sxzz](https://github.com/sxzz)! - fix peer dep versions
-
-- Updated dependencies [[`ed7ca8c`](https://github.com/vue-macros/vue-macros/commit/ed7ca8cd1fc334fb3cf5b96ee6b64e55c7390d61)]:
- - @vue-macros/common@1.3.1
-
-## 1.0.2
-
-### Patch Changes
-
-- [#347](https://github.com/vue-macros/vue-macros/pull/347) [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1) Thanks [@kekexunxun](https://github.com/kekexunxun)! - fix include regex
-
-- [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d) Thanks [@sxzz](https://github.com/sxzz)! - simplify import helper function
-
-- Updated dependencies [[`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f), [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1), [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d)]:
- - @vue-macros/common@1.3.0
-
-## 1.0.1
-
-### Patch Changes
-
-- [`2cd0c5b`](https://github.com/vue-macros/vue-macros/commit/2cd0c5b332ee2040250dea832d9883f0b598df8c) Thanks [@sxzz](https://github.com/sxzz)! - simplify import helper function
-
-- Updated dependencies [[`2cd0c5b`](https://github.com/vue-macros/vue-macros/commit/2cd0c5b332ee2040250dea832d9883f0b598df8c), [`5d65f5b`](https://github.com/vue-macros/vue-macros/commit/5d65f5b5a4d774c02346965ed8020425fa3a0986)]:
- - @vue-macros/common@1.2.0
-
-## 1.4.3
-
-### Patch Changes
-
-- [`4b9e6de`](https://github.com/vue-macros/vue-macros/commit/4b9e6deed3ba2ba82d8f7cbdf56530dbb98af604) Thanks [@sxzz](https://github.com/sxzz)! - use TS for helper code
-
-- [`d944bb0`](https://github.com/vue-macros/vue-macros/commit/d944bb0e57bbf3a742f72a4776d582f52410a71f) Thanks [@sxzz](https://github.com/sxzz)! - tidy virtual module id
-
-## 1.4.2
-
-### Patch Changes
-
-- [`e06c3d1`](https://github.com/vue-macros/vue-macros/commit/e06c3d18062c6052cff97b59a6e98215581d5808) Thanks [@sxzz](https://github.com/sxzz)! - switch to magic-string-ast, ec64836e08b2927d1a63d22f7492ab2dd1e83172
-
-- Updated dependencies [[`e06c3d1`](https://github.com/vue-macros/vue-macros/commit/e06c3d18062c6052cff97b59a6e98215581d5808)]:
- - @vue-macros/common@1.1.4
-
-## 1.4.1
-
-### Patch Changes
-
-- [`f94feb1`](https://github.com/vue-macros/vue-macros/commit/f94feb18dad273658fd7f02b0b34e3f28e614f5b) Thanks [@sxzz](https://github.com/sxzz)! - remove catching errors
-
-- Updated dependencies [[`ceb4fba`](https://github.com/vue-macros/vue-macros/commit/ceb4fbae7e2a90d3421b1357159d3d6f632947f1)]:
- - @vue-macros/common@1.1.3
-
-## 1.4.0
-
-### Minor Changes
-
-- [`e5c4f66`](https://github.com/vue-macros/vue-macros/commit/e5c4f66e9a3f2382c50cb9f083413303a0a582e3) Thanks [@sxzz](https://github.com/sxzz)! - export all apis
-
-### Patch Changes
-
-- [`c3190f1`](https://github.com/vue-macros/vue-macros/commit/c3190f1011aaca57651d86c1121c7a48ac72d812) Thanks [@sxzz](https://github.com/sxzz)! - exports all files
-
-- [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425) Thanks [@sxzz](https://github.com/sxzz)! - simplify plugin options
-
-- Updated dependencies [[`40ecab4`](https://github.com/vue-macros/vue-macros/commit/40ecab454b6db796e316e3c591b3c21777ea56d3), [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425)]:
- - @vue-macros/common@1.1.2
-
-## 1.3.4
-
-### Patch Changes
-
-- [`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480) Thanks [@sxzz](https://github.com/sxzz)! - rename helper name
-
-- Updated dependencies [[`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480)]:
- - @vue-macros/common@1.1.1
-
-## 1.3.3
-
-### Patch Changes
-
-- Updated dependencies [[`f40d270`](https://github.com/vue-macros/vue-macros/commit/f40d2701239967cfc288def57bc8b32ef57fad7e)]:
- - @vue-macros/common@1.1.0
-
-## 1.3.2
-
-### Patch Changes
-
-- [`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242) Thanks [@sxzz](https://github.com/sxzz)! - tidy package manifests
-
-- Updated dependencies [[`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242)]:
- - @vue-macros/common@1.0.1
-
-## 1.3.1
-
-### Patch Changes
-
-- [`58dc87d`](https://github.com/vue-macros/vue-macros/commit/58dc87d4c102863069119965132f4a2ccd0edeb8) Thanks [@sxzz](https://github.com/sxzz)! - simplify dts files
-
-## 1.3.0
-
-### Minor Changes
-
-- [`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862) Thanks [@sxzz](https://github.com/sxzz)! - support TypeScript 5.0
-
-### Patch Changes
-
-- Updated dependencies [[`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862), [`c91cb0f`](https://github.com/vue-macros/vue-macros/commit/c91cb0f761a06d0b5e6b7ef662824773cb4a2e61)]:
- - @vue-macros/common@1.0.0
-
-## 1.2.6
-
-### Patch Changes
-
-- Updated dependencies [[`75bda71`](https://github.com/vue-macros/vue-macros/commit/75bda71e3bc5b82e2f88234563cfefe535fceb88)]:
- - @vue-macros/common@0.15.0
-
-## 1.2.5
-
-### Patch Changes
-
-- [#230](https://github.com/vue-macros/vue-macros/pull/230) [`7c19e34`](https://github.com/vue-macros/vue-macros/commit/7c19e34c487c597dcb60cad3718b23133a99daf7) Thanks [@alexzhang1030](https://github.com/alexzhang1030)! - replace transfrom to transform
-
-## 1.2.4
-
-### Patch Changes
-
-- [`af45741`](https://github.com/vue-macros/vue-macros/commit/af4574121dd43957343669fdc4051fb452a23e6b) Thanks [@sxzz](https://github.com/sxzz)! - refactor sfc ast
-
-- Updated dependencies [[`af45741`](https://github.com/vue-macros/vue-macros/commit/af4574121dd43957343669fdc4051fb452a23e6b)]:
- - @vue-macros/common@0.14.0
-
-## 1.2.3
-
-### Patch Changes
-
-- Updated dependencies [[`a673932`](https://github.com/vue-macros/vue-macros/commit/a673932d712f235c6ba98b38222306a7695ef1d7)]:
- - @vue-macros/common@0.13.8
-
-## 1.2.2
-
-### Patch Changes
-
-- Updated dependencies [[`7829161`](https://github.com/vue-macros/vue-macros/commit/7829161929733ce4e094d5c567ef8fbba9675168), [`3010b1e`](https://github.com/vue-macros/vue-macros/commit/3010b1ea9bc81bb7e09b5155f4b1695c6457a2db)]:
- - @vue-macros/common@0.13.7
-
-## 1.2.1
-
-### Patch Changes
-
-- [`ed21c75`](https://github.com/vue-macros/vue-macros/commit/ed21c75324012b55b1a9393d143e994e32332620) Thanks [@sxzz](https://github.com/sxzz)! - support rename in declaration
-
-## 1.2.0
-
-### Minor Changes
-
-- [`3691988`](https://github.com/vue-macros/vue-macros/commit/36919886766d79584afe787eb6bb83addabd8d8a) Thanks [@sxzz](https://github.com/sxzz)! - support passing model options to vueuse
-
-### Patch Changes
-
-- [`93bb81e`](https://github.com/vue-macros/vue-macros/commit/93bb81e5ef323383dd7ed302b49a8fe60be557d5) Thanks [@sxzz](https://github.com/sxzz)! - remove scriptCompiled
-
-- [`fa6b968`](https://github.com/vue-macros/vue-macros/commit/fa6b9682f33812c99117515ea98471e534b28da4) Thanks [@sxzz](https://github.com/sxzz)! - extract SFC ast parse to common
-
-- Updated dependencies [[`b9218d4`](https://github.com/vue-macros/vue-macros/commit/b9218d45db8845a8ea44b1e825cdd97c7adb7a7d), [`af9978b`](https://github.com/vue-macros/vue-macros/commit/af9978bac81a9fa8e5fb09feefea704d6cde5ecf), [`fa6b968`](https://github.com/vue-macros/vue-macros/commit/fa6b9682f33812c99117515ea98471e534b28da4)]:
- - @vue-macros/common@0.13.6
-
-## 1.1.1
-
-### Patch Changes
-
-- [`d81825a`](https://github.com/vue-macros/vue-macros/commit/d81825a9bbe003f5af4ee3858241cc5bdb8f264f) Thanks [@sxzz](https://github.com/sxzz)! - support webpack with vue-loader@15
-
-- Updated dependencies [[`d81825a`](https://github.com/vue-macros/vue-macros/commit/d81825a9bbe003f5af4ee3858241cc5bdb8f264f)]:
- - @vue-macros/common@0.13.5
-
-## 1.1.0
-
-### Minor Changes
-
-- [#177](https://github.com/vue-macros/vue-macros/pull/177) [`934d5f8`](https://github.com/vue-macros/vue-macros/commit/934d5f8e935fc6ee0a4b3846e183b6611e10c571) Thanks [@sxzz](https://github.com/sxzz)! - Support Vite 4
- Drop Rollup 2
-
-## 1.0.0
-
-### Major Changes
-
-- [`15f3d42`](https://github.com/vue-macros/vue-macros/commit/15f3d42db5219c849f1248a881db8329e5b4b87c) Thanks [@sxzz](https://github.com/sxzz)! - make it stable. NOTHING changed.
-
-## 0.14.1
-
-### Patch Changes
-
-- Updated dependencies [[`419d2d2`](https://github.com/vue-macros/vue-macros/commit/419d2d21e0e01108abb6f628b4546c1c29077002)]:
- - @vue-macros/common@0.13.4
-
-## 0.14.0
-
-### Minor Changes
-
-- [`8c2bf9a`](https://github.com/vue-macros/vue-macros/commit/8c2bf9ab5eb8e399bc51d75270cf871667ff0166) Thanks [@sxzz](https://github.com/sxzz)! - support optional model
-
-### Patch Changes
-
-- [`bb50fa6`](https://github.com/vue-macros/vue-macros/commit/bb50fa6522e1f9a32de13fcf50e2152370c74e03) Thanks [@sxzz](https://github.com/sxzz)! - improve limit
-
-## 0.13.8
-
-### Patch Changes
-
-- Updated dependencies [[`b7998af`](https://github.com/vue-macros/vue-macros/commit/b7998afd69a0c8f8a619fab9a379c15ba4ad889f), [`d889b02`](https://github.com/vue-macros/vue-macros/commit/d889b028adb80ef02a2c17b7b7d687688cb5d5e5)]:
- - @vue-macros/common@0.13.3
-
-## 0.13.7
-
-### Patch Changes
-
-- [`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137) Thanks [@sxzz](https://github.com/sxzz)! - support context in setupComponent
-
-- Updated dependencies [[`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137)]:
- - @vue-macros/common@0.13.2
-
-## 0.13.6
-
-### Patch Changes
-
-- [`459f26b`](https://github.com/vue-macros/vue-macros/commit/459f26bc806097e3531131177d9dd73e7e3cdde9) Thanks [@sxzz](https://github.com/sxzz)! - support withDefaults in defineModel
-
-- Updated dependencies [[`b5fa188`](https://github.com/vue-macros/vue-macros/commit/b5fa18833b2262e9e416af7e96f83391efc877bb)]:
- - @vue-macros/common@0.13.1
-
-## 0.13.5
-
-### Patch Changes
-
-- [#128](https://github.com/vue-macros/vue-macros/pull/128) [`977dbe6`](https://github.com/vue-macros/vue-macros/commit/977dbe6649f8016e3bee43ec8fd91d399f749151) Thanks [@sxzz](https://github.com/sxzz)! - upgrade unplugin
-
-- Updated dependencies [[`d88fe67`](https://github.com/vue-macros/vue-macros/commit/d88fe674258c2d9d418d5b2e56aea6f70a199776)]:
- - @vue-macros/common@0.13.0
-
-## 0.13.4
-
-### Patch Changes
-
-- Updated dependencies [[`6fa5b3e`](https://github.com/vue-macros/vue-macros/commit/6fa5b3eed9de69a19921f0b38809d80d2cde3d50), [`1ac6e49`](https://github.com/vue-macros/vue-macros/commit/1ac6e496b3039a78f0288ca53698f88461ab6efc)]:
- - @vue-macros/common@0.12.3
-
-## 0.13.3
-
-### Patch Changes
-
-- [#108](https://github.com/vue-macros/vue-macros/pull/108) [`d036273`](https://github.com/vue-macros/vue-macros/commit/d036273e88368d6b6ef33a31b7bc13f2c0c0f005) Thanks [@renovate](https://github.com/apps/renovate)! - upgrade deps
-
-- Updated dependencies [[`d036273`](https://github.com/vue-macros/vue-macros/commit/d036273e88368d6b6ef33a31b7bc13f2c0c0f005)]:
- - @vue-macros/common@0.12.2
-
-## 0.13.2
-
-### Patch Changes
-
-- [`7877ac7`](https://github.com/vue-macros/vue-macros/commit/7877ac7d92c0c9b90297364abddae3562236e2d2) Thanks [@sxzz](https://github.com/sxzz)! - fix unifed key
-
-## 0.13.1
-
-### Patch Changes
-
-- [`ac603d0`](https://github.com/vue-macros/vue-macros/commit/ac603d0018637a615133899940f5ca8bd76b7435) Thanks [@sxzz](https://github.com/sxzz)! - add unified
-
-## 0.13.0
-
-### Minor Changes
-
-- [#104](https://github.com/vue-macros/vue-macros/pull/104) [`97d82c6`](https://github.com/vue-macros/vue-macros/commit/97d82c62a3aad1b1158b9697ad6bd9d052c1c086) Thanks [@sxzz](https://github.com/sxzz)! - add runtime defineModel, requires `@vueuse/core`.
-
- ⚠️ BREAKING CHANGE: original `defineModel` renamed to `$defineModel`.
-
-### Patch Changes
-
-- Updated dependencies [[`97d82c6`](https://github.com/vue-macros/vue-macros/commit/97d82c62a3aad1b1158b9697ad6bd9d052c1c086)]:
- - @vue-macros/common@0.12.1
-
-## 0.12.0
-
-### Minor Changes
-
-- [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72) Thanks [@sxzz](https://github.com/sxzz)! - sync version
-
-### Patch Changes
-
-- Updated dependencies [[`f3a1b08`](https://github.com/vue-macros/vue-macros/commit/f3a1b08f49060740a5e53a8f3e91db0dc47c366f), [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72)]:
- - @vue-macros/common@0.12.0
-
-## 0.12.0-beta.3
-
-### Patch Changes
-
-- Updated dependencies [[`f3a1b08`](https://github.com/vue-macros/vue-macros/commit/f3a1b08f49060740a5e53a8f3e91db0dc47c366f)]:
- - @vue-macros/common@0.12.0-beta.3
-
-## 0.12.0-beta.2
-
-### Minor Changes
-
-- [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72) Thanks [@sxzz](https://github.com/sxzz)! - sync version
-
-### Patch Changes
-
-- Updated dependencies [[`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72)]:
- - @vue-macros/common@0.12.0-beta.2
diff --git a/packages/define-models/macros.d.ts b/packages/define-models/macros.d.ts
index 29bd007f0..49a6c1c54 100644
--- a/packages/define-models/macros.d.ts
+++ b/packages/define-models/macros.d.ts
@@ -1,5 +1,5 @@
-import { type WritableComputedRef } from 'vue'
-import { type UseVModelOptions } from '@vueuse/core'
+import type { UseVModelOptions } from '@vueuse/core'
+import type { WritableComputedRef } from 'vue'
export type UseModelOptions = Omit, 'passive'> & {
/**
@@ -11,7 +11,6 @@ export type UseModelOptions = Omit, 'passive'> & {
passive?: boolean
}
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type ModelOptions = {}> = T
export const defineModels: () => {
diff --git a/packages/define-models/package.json b/packages/define-models/package.json
index c7f602bf0..6ffcdfb5b 100644
--- a/packages/define-models/package.json
+++ b/packages/define-models/package.json
@@ -1,8 +1,8 @@
{
"name": "@vue-macros/define-models",
- "version": "1.0.10",
- "packageManager": "pnpm@8.6.10",
- "description": "define-models feature from Vue Macros.",
+ "version": "3.0.0-beta.21",
+ "description": "defineModels feature from Vue Macros.",
+ "type": "module",
"keywords": [
"vue-macros",
"macros",
@@ -14,7 +14,7 @@
"unplugin"
],
"license": "MIT",
- "homepage": "https://github.com/vue-macros/vue-macros#readme",
+ "homepage": "https://vue-macros.dev",
"bugs": {
"url": "https://github.com/vue-macros/vue-macros/issues"
},
@@ -23,68 +23,47 @@
"url": "git+https://github.com/vue-macros/vue-macros.git",
"directory": "packages/define-models"
},
- "author": "三咲智子 ",
+ "author": "三咲智子 Kevin Deng ",
+ "funding": "https://github.com/sponsors/vue-macros",
"files": [
"*.d.ts",
"dist"
],
- "main": "dist/index.js",
- "module": "dist/index.mjs",
- "types": "dist/index.d.ts",
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
"exports": {
".": {
"dev": "./src/index.ts",
- "types": {
- "require": "./dist/index.d.ts",
- "import": "./dist/index.d.mts"
- },
- "require": "./dist/index.js",
- "import": "./dist/index.mjs"
+ "default": "./dist/index.js"
},
"./api": {
"dev": "./src/api.ts",
- "types": {
- "require": "./dist/api.d.ts",
- "import": "./dist/api.d.mts"
- },
- "require": "./dist/api.js",
- "import": "./dist/api.mjs"
+ "default": "./dist/api.js"
},
"./esbuild": {
"dev": "./src/esbuild.ts",
- "types": {
- "require": "./dist/esbuild.d.ts",
- "import": "./dist/esbuild.d.mts"
- },
- "require": "./dist/esbuild.js",
- "import": "./dist/esbuild.mjs"
+ "default": "./dist/esbuild.js"
+ },
+ "./rolldown": {
+ "dev": "./src/rolldown.ts",
+ "default": "./dist/rolldown.js"
},
"./rollup": {
"dev": "./src/rollup.ts",
- "types": {
- "require": "./dist/rollup.d.ts",
- "import": "./dist/rollup.d.mts"
- },
- "require": "./dist/rollup.js",
- "import": "./dist/rollup.mjs"
+ "default": "./dist/rollup.js"
+ },
+ "./rspack": {
+ "dev": "./src/rspack.ts",
+ "default": "./dist/rspack.js"
},
"./vite": {
"dev": "./src/vite.ts",
- "types": {
- "require": "./dist/vite.d.ts",
- "import": "./dist/vite.d.mts"
- },
- "require": "./dist/vite.js",
- "import": "./dist/vite.mjs"
+ "default": "./dist/vite.js"
},
"./webpack": {
"dev": "./src/webpack.ts",
- "types": {
- "require": "./dist/webpack.d.ts",
- "import": "./dist/webpack.d.mts"
- },
- "require": "./dist/webpack.js",
- "import": "./dist/webpack.mjs"
+ "default": "./dist/webpack.js"
},
"./*": [
"./*",
@@ -99,10 +78,25 @@
]
}
},
- "scripts": {
- "build": "tsup && tsx ../../scripts/postbuild.ts",
- "dev": "DEV=true tsup"
+ "publishConfig": {
+ "access": "public",
+ "exports": {
+ ".": "./dist/index.js",
+ "./api": "./dist/api.js",
+ "./esbuild": "./dist/esbuild.js",
+ "./rolldown": "./dist/rolldown.js",
+ "./rollup": "./dist/rollup.js",
+ "./rspack": "./dist/rspack.js",
+ "./vite": "./dist/vite.js",
+ "./webpack": "./dist/webpack.js",
+ "./*": [
+ "./*",
+ "./*.d.ts"
+ ]
+ },
+ "tag": "next"
},
+ "scripts": {},
"peerDependencies": {
"@vueuse/core": ">=9.0.0"
},
@@ -113,15 +107,14 @@
},
"dependencies": {
"@vue-macros/common": "workspace:*",
- "ast-walker-scope": "^0.4.2",
- "unplugin": "^1.4.0"
+ "ast-walker-scope": "catalog:",
+ "unplugin": "catalog:"
},
"devDependencies": {
- "@vue-macros/api": "workspace:^",
- "@vueuse/core": "^10.2.1",
- "vue": "^3.3.4"
+ "@vueuse/core": "catalog:",
+ "vue": "catalog:"
},
"engines": {
- "node": ">=16.14.0"
+ "node": ">=20.18.0"
}
}
diff --git a/packages/define-models/src/core/helper/emit-helper.ts b/packages/define-models/src/core/helper/emit-helper.ts
index 9e3d61972..141803831 100644
--- a/packages/define-models/src/core/helper/emit-helper.ts
+++ b/packages/define-models/src/core/helper/emit-helper.ts
@@ -1,12 +1,11 @@
-import { type SetupContext } from 'vue'
+import type { SetupContext } from 'vue'
-// eslint-disable-next-line import/no-default-export
export default (
emitFn: SetupContext['emit'],
key: string,
value: unknown,
...args: unknown[]
-) => {
+): any => {
emitFn(key, value)
return args.length > 0 ? args[0] : value
}
diff --git a/packages/define-models/src/core/helper/index.ts b/packages/define-models/src/core/helper/index.ts
index 631f49e10..2a6669aea 100644
--- a/packages/define-models/src/core/helper/index.ts
+++ b/packages/define-models/src/core/helper/index.ts
@@ -1,9 +1,9 @@
import { VIRTUAL_ID_PREFIX } from '@vue-macros/common'
-export const helperPrefix = `${VIRTUAL_ID_PREFIX}/define-models` as const
+export const helperPrefix: '/vue-macros/define-models' = `${VIRTUAL_ID_PREFIX}/define-models`
-export const emitHelperId = `${helperPrefix}/emit-helper` as const
+export const emitHelperId: '/vue-macros/define-models/emit-helper' = `${helperPrefix}/emit-helper`
export { default as emitHelperCode } from './emit-helper?raw'
-export const useVmodelHelperId = `${helperPrefix}/use-vmodel` as const
+export const useVmodelHelperId: '/vue-macros/define-models/use-vmodel' = `${helperPrefix}/use-vmodel`
export { default as useVmodelHelperCode } from './use-vmodel?raw'
diff --git a/packages/define-models/src/core/helper/use-vmodel.ts b/packages/define-models/src/core/helper/use-vmodel.ts
index 710d87701..8c5f83a17 100644
--- a/packages/define-models/src/core/helper/use-vmodel.ts
+++ b/packages/define-models/src/core/helper/use-vmodel.ts
@@ -1,13 +1,12 @@
-import { type Ref, getCurrentInstance } from 'vue'
-import { type UseVModelOptions, useVModel } from '@vueuse/core'
+import { useVModel, type UseVModelOptions } from '@vueuse/core'
+import { getCurrentInstance, type Ref } from 'vue'
-// eslint-disable-next-line import/no-default-export
export default (
...keys: (
| string
| [string, string | undefined, string | undefined, UseVModelOptions]
)[]
-) => {
+): Record> => {
const props = getCurrentInstance()!.proxy!.$props as Record
const ret: Record> = Object.create(null)
for (const _k of keys) {
diff --git a/packages/define-models/src/core/index.ts b/packages/define-models/src/core/index.ts
index 197e8837c..1713bb3b9 100644
--- a/packages/define-models/src/core/index.ts
+++ b/packages/define-models/src/core/index.ts
@@ -1,62 +1,58 @@
-import { extractIdentifiers, walkAST } from 'ast-walker-scope'
import {
DEFINE_EMITS,
DEFINE_MODELS,
DEFINE_MODELS_DOLLAR,
- DEFINE_OPTIONS,
DEFINE_PROPS,
+ generateTransform,
HELPER_PREFIX,
- MagicString,
- REPO_ISSUE_URL,
- WITH_DEFAULTS,
- getTransformResult,
importHelperFn,
isCallOf,
+ MagicStringAST,
parseSFC,
+ REPO_ISSUE_URL,
resolveObjectKey,
+ WITH_DEFAULTS,
+ type CodeTransform,
} from '@vue-macros/common'
-import {
- type Identifier,
- type LVal,
- type Node,
- type ObjectExpression,
- type ObjectPattern,
- type ObjectProperty,
- type Statement,
- type TSInterfaceBody,
- type TSTypeLiteral,
- type VariableDeclaration,
-} from '@babel/types'
+import { extractIdentifiers, walkAST } from 'ast-walker-scope'
import { emitHelperId, useVmodelHelperId } from './helper'
+import type {
+ Identifier,
+ LVal,
+ Node,
+ ObjectPattern,
+ TSInterfaceBody,
+ TSType,
+ TSTypeLiteral,
+ VariableDeclaration,
+ VoidPattern,
+} from '@babel/types'
export function transformDefineModels(
code: string,
id: string,
- version: number,
- unified: boolean
-) {
+): CodeTransform | undefined {
let hasDefineProps = false
let hasDefineEmits = false
let hasDefineModels = false
- let propsTypeDecl: TSInterfaceBody | TSTypeLiteral | undefined
+ let propsTypeDecl: TSType | undefined
let propsDestructureDecl: Node | undefined
- let emitsTypeDecl: TSInterfaceBody | TSTypeLiteral | undefined
+ let emitsTypeDecl: TSType | undefined
let emitsIdentifier: string | undefined
let runtimeDefineFn: string | undefined
let modelDecl: Node | undefined
let modelDeclKind: string | undefined
- let modelTypeDecl: TSInterfaceBody | TSTypeLiteral | undefined
+ let modelTypeDecl: TSType | undefined
let modelIdentifier: string | undefined
let modelDestructureDecl: ObjectPattern | undefined
const modelIdentifiers = new Set()
- const modelVue2: { event: string; prop: string } = { prop: '', event: '' }
let mode: 'reactivity-transform' | 'runtime' | undefined
- function processDefinePropsOrEmits(node: Node, declId?: LVal) {
+ function processDefinePropsOrEmits(node: Node, declId?: VoidPattern | LVal) {
if (isCallOf(node, WITH_DEFAULTS)) {
node = node.arguments[0]
}
@@ -79,24 +75,12 @@ export function transformDefineModels(
if (type === 'props') hasDefineProps = true
else hasDefineEmits = true
- const typeDeclRaw = node.typeParameters?.params?.[0]
- if (!typeDeclRaw)
+ const typeDecl = node.typeParameters?.params?.[0]
+ if (!typeDecl)
throw new SyntaxError(
- `${fnName}() expected a type parameter when used with ${DEFINE_MODELS}.`
+ `${fnName}() expected a type parameter when used with ${DEFINE_MODELS}.`,
)
- const typeDecl = resolveQualifiedType(
- typeDeclRaw,
- (node) => node.type === 'TSTypeLiteral'
- ) as TSTypeLiteral | TSInterfaceBody | undefined
-
- if (!typeDecl) {
- throw new SyntaxError(
- `type argument passed to ${fnName}() must be a literal type, ` +
- `or a reference to an interface or literal type.`
- )
- }
-
if (type === 'props') propsTypeDecl = typeDecl
else emitsTypeDecl = typeDecl
@@ -116,8 +100,8 @@ export function transformDefineModels(
function processDefineModels(
node: Node,
- declId?: LVal,
- kind?: VariableDeclaration['kind']
+ declId?: VoidPattern | LVal,
+ kind?: VariableDeclaration['kind'],
) {
if (isCallOf(node, DEFINE_MODELS)) mode = 'runtime'
else if (isCallOf(node, DEFINE_MODELS_DOLLAR)) mode = 'reactivity-transform'
@@ -129,20 +113,9 @@ export function transformDefineModels(
hasDefineModels = true
modelDecl = node
- const propsTypeDeclRaw = node.typeParameters?.params[0]
- if (!propsTypeDeclRaw) {
- throw new SyntaxError(`expected a type parameter for ${DEFINE_MODELS}.`)
- }
- modelTypeDecl = resolveQualifiedType(
- propsTypeDeclRaw,
- (node) => node.type === 'TSTypeLiteral'
- ) as TSTypeLiteral | TSInterfaceBody | undefined
-
+ modelTypeDecl = node.typeParameters?.params[0]
if (!modelTypeDecl) {
- throw new SyntaxError(
- `type argument passed to ${DEFINE_MODELS}() must be a literal type, ` +
- `or a reference to an interface or literal type.`
- )
+ throw new SyntaxError(`expected a type parameter for ${DEFINE_MODELS}.`)
}
if (mode === 'reactivity-transform' && declId) {
@@ -159,7 +132,7 @@ export function transformDefineModels(
} else {
modelIdentifier = scriptSetup!.loc.source.slice(
declId.start!,
- declId.end!
+ declId.end!,
)
}
}
@@ -168,111 +141,6 @@ export function transformDefineModels(
return true
}
- function processDefineOptions(node: Node) {
- if (!isCallOf(node, DEFINE_OPTIONS)) return false
-
- const [arg] = node.arguments
- if (arg) processVue2Model(arg)
-
- return true
- }
-
- function processVue2Script() {
- if (!script) return
- const scriptAst = getScriptAst()!.body
- if (scriptAst.length === 0) return
-
- // process normal
"
`;
exports[`fixtures > ./fixtures/reactivity-transform/no-decl.vue 1`] = `
-"
"
`;
exports[`fixtures > ./fixtures/reactivity-transform/rename.vue 1`] = `
-"
"
`;
exports[`fixtures > ./fixtures/reactivity-transform/with-define-props-decl.vue 1`] = `
-"
"
`;
exports[`fixtures > ./fixtures/reactivity-transform/with-define-props-empty.vue 1`] = `
-"
"
`;
exports[`fixtures > ./fixtures/reactivity-transform/with-define-props-ref.vue 1`] = `
-"
@@ -253,17 +260,18 @@ defineProps()
`;
exports[`fixtures > ./fixtures/reactivity-transform/with-define-props-rest.vue 1`] = `
-"
-"
-`;
-
-exports[`fixtures > ./fixtures/runtime/vue2/custom-model.vue 1`] = `
-"
-
-"
-`;
-
-exports[`fixtures > ./fixtures/runtime/vue2/custom-model-defineComponent.vue 1`] = `
-"
-
-"
-`;
-
-exports[`fixtures > ./fixtures/runtime/vue2/v-model.vue 1`] = `
-"
-"
-`;
-
-exports[`fixtures > ./fixtures/runtime/vue3/assignment.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/basic.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/error-empty-define-props.vue 1`] = `"defineProps() expected a type parameter when used with defineModels."`;
+exports[`fixtures > ./fixtures/runtime/error-empty-define-props.vue 1`] = `[SyntaxError: defineProps() expected a type parameter when used with defineModels.]`;
-exports[`fixtures > ./fixtures/runtime/vue3/error-runtime.vue 1`] = `"defineProps() cannot accept non-type arguments when used with defineModels()"`;
+exports[`fixtures > ./fixtures/runtime/error-runtime.vue 1`] = `[SyntaxError: defineProps() cannot accept non-type arguments when used with defineModels()]`;
-exports[`fixtures > ./fixtures/runtime/vue3/multi-decl.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/no-decl.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/no-type.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/optional.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/options.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/rest.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/with-defaults.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/with-define-props-empty.vue 1`] = `
-"
"
`;
-exports[`fixtures > ./fixtures/runtime/vue3/with-define-props-ref.vue 1`] = `
-"
"
`;
diff --git a/packages/define-models/tests/fixtures.test.ts b/packages/define-models/tests/fixtures.test.ts
index ec0f34acf..d0634ccc8 100644
--- a/packages/define-models/tests/fixtures.test.ts
+++ b/packages/define-models/tests/fixtures.test.ts
@@ -4,13 +4,11 @@ import { transformDefineModels } from '../src/core'
describe('fixtures', async () => {
await testFixtures(
- import.meta.glob('./fixtures/**/*.{vue,js,ts}', {
+ import.meta.glob('./fixtures/**/*.{vue,js,ts}', {
eager: true,
- as: 'raw',
+ query: '?raw',
+ import: 'default',
}),
- (args, id, code) => {
- const version = id.includes('vue2') ? 2 : 3
- return transformDefineModels(code, id, version, true)?.code
- }
+ (args, id, code) => transformDefineModels(code, id)?.code,
)
})
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/assignment.vue b/packages/define-models/tests/fixtures/runtime/assignment.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/assignment.vue
rename to packages/define-models/tests/fixtures/runtime/assignment.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/basic.vue b/packages/define-models/tests/fixtures/runtime/basic.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/basic.vue
rename to packages/define-models/tests/fixtures/runtime/basic.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/define-props-runtime.vue b/packages/define-models/tests/fixtures/runtime/define-props-runtime.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/define-props-runtime.vue
rename to packages/define-models/tests/fixtures/runtime/define-props-runtime.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/empty.vue b/packages/define-models/tests/fixtures/runtime/empty.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/empty.vue
rename to packages/define-models/tests/fixtures/runtime/empty.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/error-empty-define-props.vue b/packages/define-models/tests/fixtures/runtime/error-empty-define-props.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/error-empty-define-props.vue
rename to packages/define-models/tests/fixtures/runtime/error-empty-define-props.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/error-runtime.vue b/packages/define-models/tests/fixtures/runtime/error-runtime.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/error-runtime.vue
rename to packages/define-models/tests/fixtures/runtime/error-runtime.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/multi-decl.vue b/packages/define-models/tests/fixtures/runtime/multi-decl.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/multi-decl.vue
rename to packages/define-models/tests/fixtures/runtime/multi-decl.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/no-decl.vue b/packages/define-models/tests/fixtures/runtime/no-decl.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/no-decl.vue
rename to packages/define-models/tests/fixtures/runtime/no-decl.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/no-type.vue b/packages/define-models/tests/fixtures/runtime/no-type.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/no-type.vue
rename to packages/define-models/tests/fixtures/runtime/no-type.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/optional.vue b/packages/define-models/tests/fixtures/runtime/optional.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/optional.vue
rename to packages/define-models/tests/fixtures/runtime/optional.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/options.vue b/packages/define-models/tests/fixtures/runtime/options.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/options.vue
rename to packages/define-models/tests/fixtures/runtime/options.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/rename.vue b/packages/define-models/tests/fixtures/runtime/rename.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/rename.vue
rename to packages/define-models/tests/fixtures/runtime/rename.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/rest.vue b/packages/define-models/tests/fixtures/runtime/rest.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/rest.vue
rename to packages/define-models/tests/fixtures/runtime/rest.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue2/basic.vue b/packages/define-models/tests/fixtures/runtime/vue2/basic.vue
deleted file mode 100644
index 5edcbe8aa..000000000
--- a/packages/define-models/tests/fixtures/runtime/vue2/basic.vue
+++ /dev/null
@@ -1,23 +0,0 @@
-
diff --git a/packages/define-models/tests/fixtures/runtime/vue2/custom-model-defineComponent.vue b/packages/define-models/tests/fixtures/runtime/vue2/custom-model-defineComponent.vue
deleted file mode 100644
index e1bb44156..000000000
--- a/packages/define-models/tests/fixtures/runtime/vue2/custom-model-defineComponent.vue
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
diff --git a/packages/define-models/tests/fixtures/runtime/vue2/custom-model.vue b/packages/define-models/tests/fixtures/runtime/vue2/custom-model.vue
deleted file mode 100644
index f6e9afc8c..000000000
--- a/packages/define-models/tests/fixtures/runtime/vue2/custom-model.vue
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
diff --git a/packages/define-models/tests/fixtures/runtime/vue2/v-model.vue b/packages/define-models/tests/fixtures/runtime/vue2/v-model.vue
deleted file mode 100644
index 4dd32e80e..000000000
--- a/packages/define-models/tests/fixtures/runtime/vue2/v-model.vue
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/with-defaults.vue b/packages/define-models/tests/fixtures/runtime/with-defaults.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/with-defaults.vue
rename to packages/define-models/tests/fixtures/runtime/with-defaults.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/with-define-emits.vue b/packages/define-models/tests/fixtures/runtime/with-define-emits.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/with-define-emits.vue
rename to packages/define-models/tests/fixtures/runtime/with-define-emits.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/with-define-props-empty.vue b/packages/define-models/tests/fixtures/runtime/with-define-props-empty.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/with-define-props-empty.vue
rename to packages/define-models/tests/fixtures/runtime/with-define-props-empty.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/with-define-props-ref.vue b/packages/define-models/tests/fixtures/runtime/with-define-props-ref.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/with-define-props-ref.vue
rename to packages/define-models/tests/fixtures/runtime/with-define-props-ref.vue
diff --git a/packages/define-models/tests/fixtures/runtime/vue3/with-define-props.vue b/packages/define-models/tests/fixtures/runtime/with-define-props.vue
similarity index 100%
rename from packages/define-models/tests/fixtures/runtime/vue3/with-define-props.vue
rename to packages/define-models/tests/fixtures/runtime/with-define-props.vue
diff --git a/packages/define-models/tsdown.config.ts b/packages/define-models/tsdown.config.ts
new file mode 100644
index 000000000..4a092a139
--- /dev/null
+++ b/packages/define-models/tsdown.config.ts
@@ -0,0 +1,7 @@
+import { defineConfig } from 'tsdown/config'
+
+export default defineConfig({
+ unused: {
+ ignore: { peerDependencies: ['@vueuse/core'] },
+ },
+})
diff --git a/packages/define-models/tsup.config.ts b/packages/define-models/tsup.config.ts
deleted file mode 100644
index 1605eae16..000000000
--- a/packages/define-models/tsup.config.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from '../../tsup.config.js'
diff --git a/packages/define-options/CHANGELOG.md b/packages/define-options/CHANGELOG.md
deleted file mode 100644
index 486aa639d..000000000
--- a/packages/define-options/CHANGELOG.md
+++ /dev/null
@@ -1,311 +0,0 @@
-# unplugin-vue-define-options
-
-## 1.3.12
-
-### Patch Changes
-
-- Updated dependencies [[`f862ed6a`](https://github.com/vue-macros/vue-macros/commit/f862ed6a1a291cb51be98e8bcd541850d6f19741), [`5932a0c9`](https://github.com/vue-macros/vue-macros/commit/5932a0c9cfb6759a2fc4517e7115852cfe147ebb)]:
- - @vue-macros/common@1.6.0
-
-## 1.3.11
-
-### Patch Changes
-
-- Updated dependencies [[`c107e446`](https://github.com/vue-macros/vue-macros/commit/c107e44618dd4ed59b5f2145c54d88f8e6ca7779)]:
- - @vue-macros/common@1.5.0
-
-## 1.3.10
-
-### Patch Changes
-
-- [`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4) Thanks [@sxzz](https://github.com/sxzz)! - add types for both esm and cjs
-
-- Updated dependencies [[`1bfca25c`](https://github.com/vue-macros/vue-macros/commit/1bfca25c132f4fd2d3aca723e00ffc8312de19a4)]:
- - @vue-macros/common@1.4.1
-
-## 1.3.9
-
-### Patch Changes
-
-- [`14bda40b`](https://github.com/vue-macros/vue-macros/commit/14bda40b21bf41ecedb7dd674f3e0c5828ae0414) Thanks [@sxzz](https://github.com/sxzz)! - add type fallback for all TS versions
-
-## 1.3.8
-
-### Patch Changes
-
-- Updated dependencies [[`8521a80`](https://github.com/vue-macros/vue-macros/commit/8521a80e6221633f7baf0b9a6f78caf415613219), [`23b789f`](https://github.com/vue-macros/vue-macros/commit/23b789fa46abcb0d29f7d4f0b60c5ec271d66d88), [`ee4e093`](https://github.com/vue-macros/vue-macros/commit/ee4e093ec07931da9d24ded155a153e3496b4c7b)]:
- - @vue-macros/common@1.4.0
-
-## 1.3.7
-
-### Patch Changes
-
-- Updated dependencies [[`34be70e`](https://github.com/vue-macros/vue-macros/commit/34be70e5b3e37615b563da02bff5ae89de63b713)]:
- - @vue-macros/common@1.3.3
-
-## 1.3.6
-
-### Patch Changes
-
-- [`5806748`](https://github.com/vue-macros/vue-macros/commit/5806748a10132ac97b1c5389a72933441d2b952a) Thanks [@sxzz](https://github.com/sxzz)! - disallow more keys for `defineOptions`
-
-- Updated dependencies [[`39c72ff`](https://github.com/vue-macros/vue-macros/commit/39c72ff0f351b9b2d7eb5ad22e2a8b98f7a263a0)]:
- - @vue-macros/common@1.3.2
-
-## 1.3.5
-
-### Patch Changes
-
-- Updated dependencies [[`ed7ca8c`](https://github.com/vue-macros/vue-macros/commit/ed7ca8cd1fc334fb3cf5b96ee6b64e55c7390d61)]:
- - @vue-macros/common@1.3.1
-
-## 1.3.4
-
-### Patch Changes
-
-- [#347](https://github.com/vue-macros/vue-macros/pull/347) [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1) Thanks [@kekexunxun](https://github.com/kekexunxun)! - remove auto import limited with Vue version 2
-
-- [#347](https://github.com/vue-macros/vue-macros/pull/347) [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1) Thanks [@kekexunxun](https://github.com/kekexunxun)! - fix include regex
-
-- [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d) Thanks [@sxzz](https://github.com/sxzz)! - simplify import helper function
-
-- Updated dependencies [[`deb98b7`](https://github.com/vue-macros/vue-macros/commit/deb98b727cb4e25292dc4bf38d6fd68e1a48e54f), [`3dabd96`](https://github.com/vue-macros/vue-macros/commit/3dabd962e7a2596423052293195b97962eab08a1), [`49ce826`](https://github.com/vue-macros/vue-macros/commit/49ce8265265e84bdd00a20b0a13d02d64c82392d)]:
- - @vue-macros/common@1.3.0
-
-## 1.3.3
-
-### Patch Changes
-
-- [`2cd0c5b`](https://github.com/vue-macros/vue-macros/commit/2cd0c5b332ee2040250dea832d9883f0b598df8c) Thanks [@sxzz](https://github.com/sxzz)! - simplify import helper function
-
-- Updated dependencies [[`2cd0c5b`](https://github.com/vue-macros/vue-macros/commit/2cd0c5b332ee2040250dea832d9883f0b598df8c), [`5d65f5b`](https://github.com/vue-macros/vue-macros/commit/5d65f5b5a4d774c02346965ed8020425fa3a0986)]:
- - @vue-macros/common@1.2.0
-
-## 1.3.2
-
-### Patch Changes
-
-- [`e06c3d1`](https://github.com/vue-macros/vue-macros/commit/e06c3d18062c6052cff97b59a6e98215581d5808) Thanks [@sxzz](https://github.com/sxzz)! - switch to magic-string-ast, ec64836e08b2927d1a63d22f7492ab2dd1e83172
-
-- Updated dependencies [[`e06c3d1`](https://github.com/vue-macros/vue-macros/commit/e06c3d18062c6052cff97b59a6e98215581d5808)]:
- - @vue-macros/common@1.1.4
-
-## 1.3.1
-
-### Patch Changes
-
-- [`f94feb1`](https://github.com/vue-macros/vue-macros/commit/f94feb18dad273658fd7f02b0b34e3f28e614f5b) Thanks [@sxzz](https://github.com/sxzz)! - remove catching errors
-
-- Updated dependencies [[`ceb4fba`](https://github.com/vue-macros/vue-macros/commit/ceb4fbae7e2a90d3421b1357159d3d6f632947f1)]:
- - @vue-macros/common@1.1.3
-
-## 1.3.0
-
-### Minor Changes
-
-- [`e5c4f66`](https://github.com/vue-macros/vue-macros/commit/e5c4f66e9a3f2382c50cb9f083413303a0a582e3) Thanks [@sxzz](https://github.com/sxzz)! - export all apis
-
-### Patch Changes
-
-- [`c3190f1`](https://github.com/vue-macros/vue-macros/commit/c3190f1011aaca57651d86c1121c7a48ac72d812) Thanks [@sxzz](https://github.com/sxzz)! - exports all files
-
-- [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425) Thanks [@sxzz](https://github.com/sxzz)! - simplify plugin options
-
-- Updated dependencies [[`40ecab4`](https://github.com/vue-macros/vue-macros/commit/40ecab454b6db796e316e3c591b3c21777ea56d3), [`0b235bf`](https://github.com/vue-macros/vue-macros/commit/0b235bf8d2c5754898a178a99e99c1272156e425)]:
- - @vue-macros/common@1.1.2
-
-## 1.2.4
-
-### Patch Changes
-
-- [`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480) Thanks [@sxzz](https://github.com/sxzz)! - rename helper name
-
-- Updated dependencies [[`9fe6426`](https://github.com/vue-macros/vue-macros/commit/9fe6426464d1aa6567e7df2f0108a51e46c06480)]:
- - @vue-macros/common@1.1.1
-
-## 1.2.3
-
-### Patch Changes
-
-- Updated dependencies [[`f40d270`](https://github.com/vue-macros/vue-macros/commit/f40d2701239967cfc288def57bc8b32ef57fad7e)]:
- - @vue-macros/common@1.1.0
-
-## 1.2.2
-
-### Patch Changes
-
-- [`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242) Thanks [@sxzz](https://github.com/sxzz)! - tidy package manifests
-
-- Updated dependencies [[`e339535`](https://github.com/vue-macros/vue-macros/commit/e33953564dbbce28d4b61f61b27d7cdfcdf5c242)]:
- - @vue-macros/common@1.0.1
-
-## 1.2.1
-
-### Patch Changes
-
-- [`58dc87d`](https://github.com/vue-macros/vue-macros/commit/58dc87d4c102863069119965132f4a2ccd0edeb8) Thanks [@sxzz](https://github.com/sxzz)! - simplify dts files
-
-## 1.2.0
-
-### Minor Changes
-
-- [`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862) Thanks [@sxzz](https://github.com/sxzz)! - support TypeScript 5.0
-
-### Patch Changes
-
-- Updated dependencies [[`33849ad`](https://github.com/vue-macros/vue-macros/commit/33849ad63ad3d1d06a0a9e3ef4f58da545b90862), [`c91cb0f`](https://github.com/vue-macros/vue-macros/commit/c91cb0f761a06d0b5e6b7ef662824773cb4a2e61)]:
- - @vue-macros/common@1.0.0
-
-## 1.1.6
-
-### Patch Changes
-
-- Updated dependencies [[`75bda71`](https://github.com/vue-macros/vue-macros/commit/75bda71e3bc5b82e2f88234563cfefe535fceb88)]:
- - @vue-macros/common@0.15.0
-
-## 1.1.5
-
-### Patch Changes
-
-- [`af45741`](https://github.com/vue-macros/vue-macros/commit/af4574121dd43957343669fdc4051fb452a23e6b) Thanks [@sxzz](https://github.com/sxzz)! - refactor sfc ast
-
-- Updated dependencies [[`af45741`](https://github.com/vue-macros/vue-macros/commit/af4574121dd43957343669fdc4051fb452a23e6b)]:
- - @vue-macros/common@0.14.0
-
-## 1.1.4
-
-### Patch Changes
-
-- Updated dependencies [[`a673932`](https://github.com/vue-macros/vue-macros/commit/a673932d712f235c6ba98b38222306a7695ef1d7)]:
- - @vue-macros/common@0.13.8
-
-## 1.1.3
-
-### Patch Changes
-
-- Updated dependencies [[`7829161`](https://github.com/vue-macros/vue-macros/commit/7829161929733ce4e094d5c567ef8fbba9675168), [`3010b1e`](https://github.com/vue-macros/vue-macros/commit/3010b1ea9bc81bb7e09b5155f4b1695c6457a2db)]:
- - @vue-macros/common@0.13.7
-
-## 1.1.2
-
-### Patch Changes
-
-- [`af9978b`](https://github.com/vue-macros/vue-macros/commit/af9978bac81a9fa8e5fb09feefea704d6cde5ecf) Thanks [@sxzz](https://github.com/sxzz)! - support jsx by default
-
-- [`fa6b968`](https://github.com/vue-macros/vue-macros/commit/fa6b9682f33812c99117515ea98471e534b28da4) Thanks [@sxzz](https://github.com/sxzz)! - extract SFC ast parse to common
-
-- Updated dependencies [[`b9218d4`](https://github.com/vue-macros/vue-macros/commit/b9218d45db8845a8ea44b1e825cdd97c7adb7a7d), [`af9978b`](https://github.com/vue-macros/vue-macros/commit/af9978bac81a9fa8e5fb09feefea704d6cde5ecf), [`fa6b968`](https://github.com/vue-macros/vue-macros/commit/fa6b9682f33812c99117515ea98471e534b28da4)]:
- - @vue-macros/common@0.13.6
-
-## 1.1.1
-
-### Patch Changes
-
-- [`d81825a`](https://github.com/vue-macros/vue-macros/commit/d81825a9bbe003f5af4ee3858241cc5bdb8f264f) Thanks [@sxzz](https://github.com/sxzz)! - support webpack with vue-loader@15
-
-- Updated dependencies [[`d81825a`](https://github.com/vue-macros/vue-macros/commit/d81825a9bbe003f5af4ee3858241cc5bdb8f264f)]:
- - @vue-macros/common@0.13.5
-
-## 1.1.0
-
-### Minor Changes
-
-- [#177](https://github.com/vue-macros/vue-macros/pull/177) [`934d5f8`](https://github.com/vue-macros/vue-macros/commit/934d5f8e935fc6ee0a4b3846e183b6611e10c571) Thanks [@sxzz](https://github.com/sxzz)! - Support Vite 4
- Drop Rollup 2
-
-## 1.0.0
-
-### Major Changes
-
-- [`15f3d42`](https://github.com/vue-macros/vue-macros/commit/15f3d42db5219c849f1248a881db8329e5b4b87c) Thanks [@sxzz](https://github.com/sxzz)! - make it stable. NOTHING changed.
-
-## 0.12.8
-
-### Patch Changes
-
-- Updated dependencies [[`419d2d2`](https://github.com/vue-macros/vue-macros/commit/419d2d21e0e01108abb6f628b4546c1c29077002)]:
- - @vue-macros/common@0.13.4
-
-## 0.12.7
-
-### Patch Changes
-
-- Updated dependencies [[`b7998af`](https://github.com/vue-macros/vue-macros/commit/b7998afd69a0c8f8a619fab9a379c15ba4ad889f), [`d889b02`](https://github.com/vue-macros/vue-macros/commit/d889b028adb80ef02a2c17b7b7d687688cb5d5e5)]:
- - @vue-macros/common@0.13.3
-
-## 0.12.6
-
-### Patch Changes
-
-- [`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137) Thanks [@sxzz](https://github.com/sxzz)! - support context in setupComponent
-
-- Updated dependencies [[`85f1c86`](https://github.com/vue-macros/vue-macros/commit/85f1c8621ffaaeac313974445a0ef41fafdd2137)]:
- - @vue-macros/common@0.13.2
-
-## 0.12.5
-
-### Patch Changes
-
-- Updated dependencies [[`b5fa188`](https://github.com/vue-macros/vue-macros/commit/b5fa18833b2262e9e416af7e96f83391efc877bb)]:
- - @vue-macros/common@0.13.1
-
-## 0.12.4
-
-### Patch Changes
-
-- [#128](https://github.com/vue-macros/vue-macros/pull/128) [`977dbe6`](https://github.com/vue-macros/vue-macros/commit/977dbe6649f8016e3bee43ec8fd91d399f749151) Thanks [@sxzz](https://github.com/sxzz)! - upgrade unplugin
-
-- Updated dependencies [[`d88fe67`](https://github.com/vue-macros/vue-macros/commit/d88fe674258c2d9d418d5b2e56aea6f70a199776)]:
- - @vue-macros/common@0.13.0
-
-## 0.12.3
-
-### Patch Changes
-
-- Updated dependencies [[`6fa5b3e`](https://github.com/vue-macros/vue-macros/commit/6fa5b3eed9de69a19921f0b38809d80d2cde3d50), [`1ac6e49`](https://github.com/vue-macros/vue-macros/commit/1ac6e496b3039a78f0288ca53698f88461ab6efc)]:
- - @vue-macros/common@0.12.3
-
-## 0.12.2
-
-### Patch Changes
-
-- [#108](https://github.com/vue-macros/vue-macros/pull/108) [`d036273`](https://github.com/vue-macros/vue-macros/commit/d036273e88368d6b6ef33a31b7bc13f2c0c0f005) Thanks [@renovate](https://github.com/apps/renovate)! - upgrade deps
-
-- Updated dependencies [[`d036273`](https://github.com/vue-macros/vue-macros/commit/d036273e88368d6b6ef33a31b7bc13f2c0c0f005)]:
- - @vue-macros/common@0.12.2
-
-## 0.12.1
-
-### Patch Changes
-
-- Updated dependencies [[`97d82c6`](https://github.com/vue-macros/vue-macros/commit/97d82c62a3aad1b1158b9697ad6bd9d052c1c086)]:
- - @vue-macros/common@0.12.1
-
-## 0.12.0
-
-### Minor Changes
-
-- [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72) Thanks [@sxzz](https://github.com/sxzz)! - sync version
-
-### Patch Changes
-
-- Updated dependencies [[`f3a1b08`](https://github.com/vue-macros/vue-macros/commit/f3a1b08f49060740a5e53a8f3e91db0dc47c366f), [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72)]:
- - @vue-macros/common@0.12.0
-
-## 0.12.0-beta.3
-
-### Patch Changes
-
-- Updated dependencies [[`f3a1b08`](https://github.com/vue-macros/vue-macros/commit/f3a1b08f49060740a5e53a8f3e91db0dc47c366f)]:
- - @vue-macros/common@0.12.0-beta.3
-
-## 0.12.0-beta.2
-
-### Minor Changes
-
-- [`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72) Thanks [@sxzz](https://github.com/sxzz)! - sync version
-
-### Patch Changes
-
-- Updated dependencies [[`0b37cb7`](https://github.com/vue-macros/vue-macros/commit/0b37cb7e38a5c1893f037fc31f6ca3bd40e74b72)]:
- - @vue-macros/common@0.12.0-beta.2
diff --git a/packages/define-options/README.md b/packages/define-options/README.md
index 24191907d..093a100c0 100644
--- a/packages/define-options/README.md
+++ b/packages/define-options/README.md
@@ -4,8 +4,6 @@
# unplugin-vue-define-options [](https://npmjs.com/package/unplugin-vue-define-options)
-📜 Documentation
-
Options API can be declared using the `defineOptions` in `