@@ -63,9 +63,9 @@ const getTag = (t, path) => {
63
63
*/
64
64
const getChildren = ( t , paths ) =>
65
65
paths
66
- . map ( path => {
66
+ . map ( ( path , index ) => {
67
67
if ( path . isJSXText ( ) ) {
68
- return transformJSXText ( t , path )
68
+ return transformJSXText ( t , path , index === 0 ? - 1 : index === paths . length - 1 ? 1 : 0 )
69
69
}
70
70
if ( path . isJSXExpressionContainer ( ) ) {
71
71
return transformJSXExpressionContainer ( t , path )
@@ -360,14 +360,25 @@ const transformJSXMemberExpression = (t, path) => {
360
360
return t . memberExpression ( transformedObject , transformedProperty )
361
361
}
362
362
363
+ /**
364
+ * Trim text from JSX expressions depending on position
365
+ * @param string string
366
+ * @param position -1 for left, 0 for middle and 1 for right
367
+ * @returns string
368
+ */
369
+ const trimText = ( string , position ) => ( position === 0 ? string : string . replace ( position === - 1 ? / ^ \s * / : / \s * $ / , '' ) )
370
+
363
371
/**
364
372
* Transform JSXText to StringLiteral
365
373
* @param t
366
374
* @param path JSXText
375
+ * @param position -1 for left, 0 for middle and 1 for right
367
376
* @returns StringLiteral
368
377
*/
369
- const transformJSXText = ( t , path ) =>
370
- path . get ( 'value' ) . node . match ( / ^ \s * $ / ) ? null : t . stringLiteral ( path . get ( 'value' ) . node )
378
+ const transformJSXText = ( t , path , position ) => {
379
+ const string = trimText ( path . get ( 'value' ) . node , position )
380
+ return string ? t . stringLiteral ( string ) : null
381
+ }
371
382
372
383
/**
373
384
* Transform JSXExpressionContainer to Expression
0 commit comments