mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
fix error when use fragment
This commit is contained in:
parent
7a1a39a4cb
commit
5e2eaa6ced
@ -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),
|
||||
},
|
||||
});
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user