fix error when use fragment

This commit is contained in:
Amour1688 2020-05-26 23:49:19 +08:00
parent 7a1a39a4cb
commit 5e2eaa6ced
2 changed files with 5 additions and 6 deletions

View File

@ -3,12 +3,12 @@ const tranformVueJSX = require('./transform-vue-jsx');
const sugarVModel = require('./sugar-v-model');
const sugarFragment = require('./sugar-fragment');
module.exports = ({ types: t }, opts = {}) => ({
module.exports = ({ types: t }) => ({
name: 'babel-plugin-jsx',
inherits: syntaxJsx,
visitor: {
...sugarVModel(t),
...tranformVueJSX(t, opts),
...tranformVueJSX(t),
...sugarFragment(t),
},
});

View File

@ -287,6 +287,7 @@ const getChildren = (t, paths) => paths
&& !t.isJSXEmptyExpression(value)
));
const transformJSXElement = (t, path, state) => {
const directives = [];
const tag = getTag(t, path);
@ -294,7 +295,7 @@ const transformJSXElement = (t, path, state) => {
const h = t.callExpression(state.h, [
tag,
getAttributes(t, path, state, directives),
!t.isStringLiteral(tag)
!t.isStringLiteral(tag) && !tag.name.includes('Fragment')
? t.objectExpression([
t.objectProperty(
t.identifier('default'),
@ -326,9 +327,7 @@ module.exports = (t) => ({
JSXElement: {
exit(path, state) {
imports.forEach((m) => {
if (!state[m]) {
state[m] = addNamed(path, m, 'vue');
}
});
path.replaceWith(
transformJSXElement(t, path, state),