Skip to content

Commit

Permalink
feat(plugin-vue-jsx): add jsx pure flag (#10205)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhaoyuan committed Nov 8, 2022
1 parent dd871af commit 14b7caf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/plugin-vue-jsx/src/index.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -93,6 +95,23 @@ function vueJsxPlugin(options: Options = {}): Plugin {
])
}

if (!ssr && !needHmr) {
plugins.push(() => {
return {
visitor: {
CallExpression: {
enter(_path: babel.NodePath<CallExpression>) {
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,
Expand Down

0 comments on commit 14b7caf

Please sign in to comment.