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 {
16
16
transformJSXSpreadAttribute ,
17
17
transformJSXSpreadChild ,
18
18
transformJSXText ,
19
+ transformText ,
19
20
walksScope ,
20
21
} from './utils' ;
21
22
import SlotFlags from './slotFlags' ;
@@ -36,7 +37,7 @@ const getJSXAttributeValue = (
36
37
return transformJSXElement ( valuePath , state ) ;
37
38
}
38
39
if ( valuePath . isStringLiteral ( ) ) {
39
- return transformJSXText ( valuePath ) ;
40
+ return t . stringLiteral ( transformText ( valuePath . node . value ) ) ;
40
41
}
41
42
if ( valuePath . isJSXExpressionContainer ( ) ) {
42
43
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 => {
140
140
export const transformJSXText = (
141
141
path : NodePath < t . JSXText | t . StringLiteral >
142
142
) : 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 / ) ;
145
149
146
150
let lastNonEmptyLine = 0 ;
147
151
@@ -182,7 +186,7 @@ export const transformJSXText = (
182
186
}
183
187
}
184
188
185
- return str !== '' ? t . stringLiteral ( str ) : null ;
189
+ return str ;
186
190
} ;
187
191
188
192
/**
Original file line number Diff line number Diff line change @@ -254,6 +254,15 @@ describe('Transform JSX', () => {
254
254
255
255
expect ( calls ) . toEqual ( expect . arrayContaining ( [ 3 , 4 ] ) ) ;
256
256
} ) ;
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
+ } ) ;
257
266
} ) ;
258
267
259
268
describe ( 'directive' , ( ) => {
You can’t perform that action at this time.
0 commit comments