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 sugarVModel = require('./sugar-v-model');
const sugarFragment = require('./sugar-fragment'); const sugarFragment = require('./sugar-fragment');
module.exports = ({ types: t }, opts = {}) => ({ module.exports = ({ types: t }) => ({
name: 'babel-plugin-jsx', name: 'babel-plugin-jsx',
inherits: syntaxJsx, inherits: syntaxJsx,
visitor: { visitor: {
...sugarVModel(t), ...sugarVModel(t),
...tranformVueJSX(t, opts), ...tranformVueJSX(t),
...sugarFragment(t), ...sugarFragment(t),
}, },
}); });

View File

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