diff --git a/compiler/core/js_dump.ml b/compiler/core/js_dump.ml index e4c9f47736..c862052b25 100644 --- a/compiler/core/js_dump.ml +++ b/compiler/core/js_dump.ml @@ -1123,23 +1123,13 @@ and print_jsx cxt ?(spread_props : J.expression option) fields in let print_props cxt props = - let print_prop_value (x : J.expression) ctx = - let needs_braces = - match x.expression_desc with - | Str _ | Optional_block ({expression_desc = Str _}, _) -> false - | _ -> true - in - if needs_braces then P.string f "{"; - let next_cxt = expression ~level:0 ctx f x in - if needs_braces then P.string f "}"; - next_cxt - in - (* If a key is present, should be printed before the spread props, This is to ensure tools like ESBuild use the automatic JSX runtime *) let print_key key cxt = - P.string f "key="; - print_prop_value key cxt + P.string f "key={"; + let cxt_k = expression ~level:0 cxt f key in + P.string f "} "; + cxt_k in let print_spread_props spread cxt = @@ -1153,7 +1143,10 @@ and print_jsx cxt ?(spread_props : J.expression option) let prop_name = Ext_ident.unwrap_uppercase_exotic n in P.string f prop_name; P.string f "="; - print_prop_value x ctx + P.string f "{"; + let next_cxt = expression ~level:0 ctx f x in + P.string f "}"; + next_cxt in let printable_props = (match key with diff --git a/tests/tests/src/jsx_preserve_test.mjs b/tests/tests/src/jsx_preserve_test.mjs index 5a3ddc0ca0..3c71b71dc7 100644 --- a/tests/tests/src/jsx_preserve_test.mjs +++ b/tests/tests/src/jsx_preserve_test.mjs @@ -29,21 +29,21 @@ let _single_element_fragment = <> let _multiple_element_fragment = <> >; let _unary_element_with_props = ; let _container_element_with_props_and_children =
{}} onMouseDown={param => {}} > {"Hello, world!"}
{}} onMouseDown={param => {}} > @@ -199,13 +199,13 @@ let ComponentWithOptionalProps = { let _optional_props =