@@ -73,13 +73,25 @@ function toStr(children, counter = 0) {
7373 }
7474 } else if ( child . type === 'JSXText' ) {
7575 // Child is not a React element, append as-is
76- const chunk = child . value . trim ( ) . replace ( / \s + / g, ' ' ) ;
76+ let chunk = child . value ;
77+
78+ // Try to mimic how JSX is parsed in runtime React
79+ const [ startMatch ] = / ^ [ \s \n ] * / . exec ( child . value ) ;
80+ if ( startMatch . includes ( '\n' ) ) {
81+ chunk = chunk . substring ( startMatch . length ) ;
82+ }
83+
84+ const [ endMatch ] = / [ \s \n ] * $ / . exec ( child . value ) ;
85+ if ( endMatch . includes ( '\n' ) ) {
86+ chunk = chunk . substring ( 0 , chunk . length - endMatch . length ) ;
87+ }
88+
7789 if ( chunk ) { result . push ( chunk ) ; }
7890 } else if (
7991 child . type === 'JSXExpressionContainer'
8092 && child . expression . type === 'StringLiteral'
8193 ) {
82- const chunk = child . expression . value . trim ( ) ;
94+ const chunk = child . expression . value ;
8395 if ( chunk ) { result . push ( chunk ) ; }
8496 } else {
8597 return [ [ ] , 0 ] ;
@@ -195,7 +207,7 @@ function babelExtractPhrases(HASHES, source, relativeFile, options) {
195207
196208 if ( ! string && elem . name . name === 'T' && node . children && node . children . length ) {
197209 const [ result ] = toStr ( node . children ) ;
198- string = result . join ( ' ' ) . trim ( ) ;
210+ string = result . join ( '' ) . trim ( ) ;
199211 }
200212
201213 if ( ! string ) return ;
0 commit comments