@@ -73,13 +73,25 @@ function toStr(children, counter = 0) {
73
73
}
74
74
} else if ( child . type === 'JSXText' ) {
75
75
// 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
+
77
89
if ( chunk ) { result . push ( chunk ) ; }
78
90
} else if (
79
91
child . type === 'JSXExpressionContainer'
80
92
&& child . expression . type === 'StringLiteral'
81
93
) {
82
- const chunk = child . expression . value . trim ( ) ;
94
+ const chunk = child . expression . value ;
83
95
if ( chunk ) { result . push ( chunk ) ; }
84
96
} else {
85
97
return [ [ ] , 0 ] ;
@@ -195,7 +207,7 @@ function babelExtractPhrases(HASHES, source, relativeFile, options) {
195
207
196
208
if ( ! string && elem . name . name === 'T' && node . children && node . children . length ) {
197
209
const [ result ] = toStr ( node . children ) ;
198
- string = result . join ( ' ' ) . trim ( ) ;
210
+ string = result . join ( '' ) ;
199
211
}
200
212
201
213
if ( ! string ) return ;
0 commit comments