File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -204,4 +204,24 @@ describe("formatjs swc plugin", () => {
204
204
expect ( sha512output ) . toMatch ( / i d : " [ a - z A - Z 0 - 9 ] { 6 } " / ) ;
205
205
expect ( sha1output ) . not . toMatch ( sha512output ) ;
206
206
} ) ;
207
+
208
+ it ( "should be able to use object description" , async ( ) => {
209
+ const input = `
210
+ import { FormattedMessage } from 'react-intl';
211
+
212
+ export function Greeting() {
213
+ return (
214
+ <FormattedMessage
215
+ defaultMessage="Hello!"
216
+ description={{ text: "Greeting message" }}
217
+ />
218
+ );
219
+ }
220
+ ` ;
221
+
222
+ console . log ( input ) ;
223
+ const output = await transformCode ( input ) ;
224
+
225
+ expect ( output ) . toMatch ( / i d : " z L \/ j y T \" / ) ;
226
+ } ) ;
207
227
} ) ;
Original file line number Diff line number Diff line change @@ -570,6 +570,10 @@ fn evaluate_jsx_message_descriptor(
570
570
571
571
let content = if let Some ( MessageDescriptionValue :: Str ( description) ) = & description {
572
572
format ! ( "{}#{}" , default_message, description)
573
+ } else if let Some ( MessageDescriptionValue :: Obj ( _) ) = & description {
574
+ // When description is an object, stringify it for the hash calculation
575
+ let desc_json = serde_json:: to_string ( & description) . unwrap_or_default ( ) ;
576
+ format ! ( "{}#{}" , default_message, desc_json)
573
577
} else {
574
578
default_message. clone ( )
575
579
} ;
@@ -610,6 +614,10 @@ fn evaluate_call_expr_message_descriptor(
610
614
611
615
let content = if let Some ( MessageDescriptionValue :: Str ( description) ) = & description {
612
616
format ! ( "{}#{}" , default_message, description)
617
+ } else if let Some ( MessageDescriptionValue :: Obj ( _) ) = & description {
618
+ // When description is an object, stringify it for the hash calculation
619
+ let desc_json = serde_json:: to_string ( & description) . unwrap_or_default ( ) ;
620
+ format ! ( "{}#{}" , default_message, desc_json)
613
621
} else {
614
622
default_message. clone ( )
615
623
} ;
You can’t perform that action at this time.
0 commit comments