Skip to content
3 changes: 2 additions & 1 deletion packages/babel-plugin-jsx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const isDirective = (src: string): boolean => src.startsWith('v-')
* @param tag string
* @returns boolean
*/
export const shouldTransformedToSlots = (tag: string) => !(tag.endsWith(FRAGMENT) || tag === KEEP_ALIVE);
// if _Fragment is already imported, it will end with number
export const shouldTransformedToSlots = (tag: string) => !(tag.match(RegExp(`^_?${FRAGMENT}\\d*$`)) || tag === KEEP_ALIVE);

/**
* Check if a Node is a component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`_Fragment already imported: _Fragment already imported 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode, Fragment as _Fragment2 } from \\"vue\\";
import { Fragment as _Fragment } from 'vue';

const Root1 = () => _createVNode(_Fragment2, null, [_createTextVNode(\\"root1\\")]);

const Root2 = () => _createVNode(_Fragment, null, [_createTextVNode(\\"root2\\")]);"
`;

exports[`MereProps Order: MereProps Order 1`] = `
"import { createVNode as _createVNode, mergeProps as _mergeProps, createTextVNode as _createTextVNode } from \\"vue\\";

Expand Down
20 changes: 19 additions & 1 deletion packages/babel-plugin-jsx/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,22 @@ isCustomElementTests.forEach(({name, from }) => {
expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name);
}
)
})
})

const fragmentTests = [{
name: '_Fragment already imported',
from: `
import { Fragment as _Fragment } from 'vue'
const Root1 = () => <>root1</>
const Root2 = () => <_Fragment>root2</_Fragment>
`
}];

fragmentTests.forEach(({ name, from}) => {
test(
name,
async () => {
expect(await transpile(from)).toMatchSnapshot(name);
},
);
});