From 14b7caf73a8f4f434cd409a238ec50150738613b Mon Sep 17 00:00:00 2001 From: Fansy <35361626+fanhaoyuan@users.noreply.github.com> Date: Tue, 8 Nov 2022 17:17:41 +0800 Subject: [PATCH] feat(plugin-vue-jsx): add `jsx` pure flag (#10205) --- packages/plugin-vue-jsx/src/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/plugin-vue-jsx/src/index.ts b/packages/plugin-vue-jsx/src/index.ts index cb288872..15fcb808 100644 --- a/packages/plugin-vue-jsx/src/index.ts +++ b/packages/plugin-vue-jsx/src/index.ts @@ -6,6 +6,8 @@ import jsx from '@vue/babel-plugin-jsx' import { createFilter, normalizePath } from 'vite' import type { ComponentOptions } from 'vue' import type { Plugin } from 'vite' +// eslint-disable-next-line node/no-extraneous-import +import type { CallExpression, Identifier } from '@babel/types' import type { Options } from './types' export * from './types' @@ -93,6 +95,23 @@ function vueJsxPlugin(options: Options = {}): Plugin { ]) } + if (!ssr && !needHmr) { + plugins.push(() => { + return { + visitor: { + CallExpression: { + enter(_path: babel.NodePath) { + if (isDefineComponentCall(_path.node)) { + const callee = _path.node.callee as Identifier + callee.name = `/* @__PURE__ */ ${callee.name}` + } + } + } + } + } + }) + } + const result = babel.transformSync(code, { babelrc: false, ast: true,