mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-13 02:59:13 +08:00
fix: wrong compilation result when _Fragment is imported (#518)
* fix: optimize Fragment judgement Co-authored-by: Amour1688 <lcz141186@gmail.com>
This commit is contained in:
parent
465d62928d
commit
35780fd7d4
@ -32,7 +32,8 @@ export const isDirective = (src: string): boolean => src.startsWith('v-')
|
|||||||
* @param tag string
|
* @param tag string
|
||||||
* @returns boolean
|
* @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
|
* Check if a Node is a component
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`MereProps Order: MereProps Order 1`] = `
|
||||||
"import { createVNode as _createVNode, mergeProps as _mergeProps, createTextVNode as _createTextVNode } from \\"vue\\";
|
"import { createVNode as _createVNode, mergeProps as _mergeProps, createTextVNode as _createTextVNode } from \\"vue\\";
|
||||||
|
|
||||||
|
@ -317,4 +317,22 @@ isCustomElementTests.forEach(({name, from }) => {
|
|||||||
expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name);
|
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);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user