diff --git a/index.js b/index.js index e0746b9..64b25c8 100644 --- a/index.js +++ b/index.js @@ -18,10 +18,12 @@ module.exports = function (babel) { exit (path, file) { // turn tag into createElement call var callExpr = buildElementCall(path.get('openingElement'), file) - // add children array as 3rd arg - callExpr.arguments.push(t.arrayExpression(path.node.children)) - if (callExpr.arguments.length >= 3) { - callExpr._prettyCall = true + if (path.node.children.length) { + // add children array as 3rd arg + callExpr.arguments.push(t.arrayExpression(path.node.children)) + if (callExpr.arguments.length >= 3) { + callExpr._prettyCall = true + } } path.replaceWith(t.inherits(callExpr, path.node)) } diff --git a/test/test.js b/test/test.js index aa3faed..b0cd4a9 100644 --- a/test/test.js +++ b/test/test.js @@ -27,6 +27,12 @@ describe('babel-plugin-transform-vue-jsx', () => { expect(vnode.data.attrs.id).to.equal('foo') }) + it('should omit children argument if possible', () => { + const vnode = render(h =>
) + const children = vnode.children + expect(children).to.equal(undefined) + }) + it('should handle top-level special attrs', () => { const vnode = render(h => (