diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts index 57895a07..18e2e6d4 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts @@ -16,6 +16,7 @@ import { transformJSXSpreadAttribute, transformJSXSpreadChild, transformJSXText, + transformText, walksScope, } from './utils'; import SlotFlags from './slotFlags'; @@ -36,7 +37,7 @@ const getJSXAttributeValue = ( return transformJSXElement(valuePath, state); } if (valuePath.isStringLiteral()) { - return transformJSXText(valuePath); + return t.stringLiteral(transformText(valuePath.node.value)); } if (valuePath.isJSXExpressionContainer()) { return transformJSXExpressionContainer(valuePath); diff --git a/packages/babel-plugin-jsx/src/utils.ts b/packages/babel-plugin-jsx/src/utils.ts index 0361f55f..9b4ab4f7 100644 --- a/packages/babel-plugin-jsx/src/utils.ts +++ b/packages/babel-plugin-jsx/src/utils.ts @@ -140,8 +140,12 @@ export const getJSXAttributeName = (path: NodePath): string => { export const transformJSXText = ( path: NodePath ): t.StringLiteral | null => { - const { node } = path; - const lines = node.value.split(/\r\n|\n|\r/); + const str = transformText(path.node.value); + return str !== '' ? t.stringLiteral(str) : null; +}; + +export const transformText = (text: string) => { + const lines = text.split(/\r\n|\n|\r/); let lastNonEmptyLine = 0; @@ -182,7 +186,7 @@ export const transformJSXText = ( } } - return str !== '' ? t.stringLiteral(str) : null; + return str; }; /** diff --git a/packages/babel-plugin-jsx/test/index.test.tsx b/packages/babel-plugin-jsx/test/index.test.tsx index f136224f..f675787a 100644 --- a/packages/babel-plugin-jsx/test/index.test.tsx +++ b/packages/babel-plugin-jsx/test/index.test.tsx @@ -254,6 +254,15 @@ describe('Transform JSX', () => { expect(calls).toEqual(expect.arrayContaining([3, 4])); }); + + test('empty string', () => { + const wrapper = shallowMount({ + setup() { + return () =>

; + }, + }); + expect(wrapper.html()).toBe('

'); + }); }); describe('directive', () => {