diff --git a/packages/babel-plugin-jsx/README.md b/packages/babel-plugin-jsx/README.md index 53eb7887..1bbe7309 100644 --- a/packages/babel-plugin-jsx/README.md +++ b/packages/babel-plugin-jsx/README.md @@ -51,6 +51,14 @@ Default: `undefined` configuring custom elements +#### isGlobalElement + +Type: `(tag: string) => boolean` + +Default: `undefined` + +configuring global elements so that they don't need to be wrapped by `resolveComponent`. + #### mergeProps Type: `boolean` diff --git a/packages/babel-plugin-jsx/src/interface.ts b/packages/babel-plugin-jsx/src/interface.ts index e2aa08e0..c403c9dd 100644 --- a/packages/babel-plugin-jsx/src/interface.ts +++ b/packages/babel-plugin-jsx/src/interface.ts @@ -20,6 +20,8 @@ export interface VueJSXPluginOptions { mergeProps?: boolean; /** configuring custom elements */ isCustomElement?: (tag: string) => boolean; + /** configuring global elements */ + isGlobalElement?: (tag: string) => boolean; /** enable object slots syntax */ enableObjectSlots?: boolean; /** Replace the function used when compiling JSX expressions */ diff --git a/packages/babel-plugin-jsx/src/utils.ts b/packages/babel-plugin-jsx/src/utils.ts index 6e1d24de..8fcb2046 100644 --- a/packages/babel-plugin-jsx/src/utils.ts +++ b/packages/babel-plugin-jsx/src/utils.ts @@ -109,9 +109,11 @@ export const getTag = ( ? t.identifier(name) : state.opts.isCustomElement?.(name) ? t.stringLiteral(name) - : t.callExpression(createIdentifier(state, 'resolveComponent'), [ - t.stringLiteral(name), - ]); + : state.opts.isGlobalElement?.(name) + ? t.identifier(name) + : t.callExpression(createIdentifier(state, 'resolveComponent'), [ + t.stringLiteral(name), + ]); } return t.stringLiteral(name);