File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
packages/babel-plugin-jsx Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 transformJSXSpreadAttribute ,
1717 transformJSXSpreadChild ,
1818 transformJSXText ,
19+ transformText ,
1920 walksScope ,
2021} from './utils' ;
2122import SlotFlags from './slotFlags' ;
@@ -36,7 +37,7 @@ const getJSXAttributeValue = (
3637 return transformJSXElement ( valuePath , state ) ;
3738 }
3839 if ( valuePath . isStringLiteral ( ) ) {
39- return transformJSXText ( valuePath ) ;
40+ return t . stringLiteral ( transformText ( valuePath . node . value ) ) ;
4041 }
4142 if ( valuePath . isJSXExpressionContainer ( ) ) {
4243 return transformJSXExpressionContainer ( valuePath ) ;
Original file line number Diff line number Diff line change @@ -140,8 +140,12 @@ export const getJSXAttributeName = (path: NodePath<t.JSXAttribute>): string => {
140140export const transformJSXText = (
141141 path : NodePath < t . JSXText | t . StringLiteral >
142142) : t . StringLiteral | null => {
143- const { node } = path ;
144- const lines = node . value . split ( / \r \n | \n | \r / ) ;
143+ const str = transformText ( path . node . value ) ;
144+ return str !== '' ? t . stringLiteral ( str ) : null ;
145+ } ;
146+
147+ export const transformText = ( text : string ) => {
148+ const lines = text . split ( / \r \n | \n | \r / ) ;
145149
146150 let lastNonEmptyLine = 0 ;
147151
@@ -182,7 +186,7 @@ export const transformJSXText = (
182186 }
183187 }
184188
185- return str !== '' ? t . stringLiteral ( str ) : null ;
189+ return str ;
186190} ;
187191
188192/**
Original file line number Diff line number Diff line change @@ -254,6 +254,15 @@ describe('Transform JSX', () => {
254254
255255 expect ( calls ) . toEqual ( expect . arrayContaining ( [ 3 , 4 ] ) ) ;
256256 } ) ;
257+
258+ test ( 'empty string' , ( ) => {
259+ const wrapper = shallowMount ( {
260+ setup ( ) {
261+ return ( ) => < h1 title = "" > </ h1 > ;
262+ } ,
263+ } ) ;
264+ expect ( wrapper . html ( ) ) . toBe ( '<h1 title=""></h1>' ) ;
265+ } ) ;
257266} ) ;
258267
259268describe ( 'directive' , ( ) => {
You can’t perform that action at this time.
0 commit comments