mirror of
				https://github.com/vuejs/babel-plugin-jsx.git
				synced 2025-10-31 17:32:32 +08:00 
			
		
		
		
	| @@ -16,6 +16,7 @@ import { | |||||||
|   transformJSXSpreadAttribute, |   transformJSXSpreadAttribute, | ||||||
|   transformJSXSpreadChild, |   transformJSXSpreadChild, | ||||||
|   transformJSXText, |   transformJSXText, | ||||||
|  |   transformText, | ||||||
|   walksScope, |   walksScope, | ||||||
| } from './utils'; | } from './utils'; | ||||||
| import SlotFlags from './slotFlags'; | import SlotFlags from './slotFlags'; | ||||||
| @@ -36,7 +37,7 @@ const getJSXAttributeValue = ( | |||||||
|     return transformJSXElement(valuePath, state); |     return transformJSXElement(valuePath, state); | ||||||
|   } |   } | ||||||
|   if (valuePath.isStringLiteral()) { |   if (valuePath.isStringLiteral()) { | ||||||
|     return transformJSXText(valuePath); |     return t.stringLiteral(transformText(valuePath.node.value)); | ||||||
|   } |   } | ||||||
|   if (valuePath.isJSXExpressionContainer()) { |   if (valuePath.isJSXExpressionContainer()) { | ||||||
|     return transformJSXExpressionContainer(valuePath); |     return transformJSXExpressionContainer(valuePath); | ||||||
|   | |||||||
| @@ -140,8 +140,12 @@ export const getJSXAttributeName = (path: NodePath<t.JSXAttribute>): string => { | |||||||
| export const transformJSXText = ( | export const transformJSXText = ( | ||||||
|   path: NodePath<t.JSXText | t.StringLiteral> |   path: NodePath<t.JSXText | t.StringLiteral> | ||||||
| ): t.StringLiteral | null => { | ): t.StringLiteral | null => { | ||||||
|   const { node } = path; |   const str = transformText(path.node.value); | ||||||
|   const lines = node.value.split(/\r\n|\n|\r/); |   return str !== '' ? t.stringLiteral(str) : null; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | export const transformText = (text: string) => { | ||||||
|  |   const lines = text.split(/\r\n|\n|\r/); | ||||||
|  |  | ||||||
|   let lastNonEmptyLine = 0; |   let lastNonEmptyLine = 0; | ||||||
|  |  | ||||||
| @@ -182,7 +186,7 @@ export const transformJSXText = ( | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return str !== '' ? t.stringLiteral(str) : null; |   return str; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
| @@ -254,6 +254,15 @@ describe('Transform JSX', () => { | |||||||
|  |  | ||||||
|     expect(calls).toEqual(expect.arrayContaining([3, 4])); |     expect(calls).toEqual(expect.arrayContaining([3, 4])); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  |   test('empty string', () => { | ||||||
|  |     const wrapper = shallowMount({ | ||||||
|  |       setup() { | ||||||
|  |         return () => <h1 title=""></h1>; | ||||||
|  |       }, | ||||||
|  |     }); | ||||||
|  |     expect(wrapper.html()).toBe('<h1 title=""></h1>'); | ||||||
|  |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| describe('directive', () => { | describe('directive', () => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user