@@ -315,6 +315,9 @@ module E = struct
315315 let open Exp in
316316 let loc = sub.location sub loc in
317317 let attrs = sub.attributes sub attrs in
318+ let has_jsx_attribute () =
319+ attrs |> List. exists (fun ({txt} , _ ) -> txt = " JSX" )
320+ in
318321 match desc with
319322 | Pexp_ident x -> ident ~loc ~attrs (map_loc sub x)
320323 | Pexp_constant x -> constant ~loc ~attrs (map_constant x)
@@ -327,6 +330,10 @@ module E = struct
327330 (map_opt (sub.expr sub) def)
328331 (sub.pat sub p) (sub.expr sub e)
329332 | Pexp_function _ -> assert false
333+ | Pexp_apply ({pexp_desc = Pexp_ident tag_name}, _args)
334+ when has_jsx_attribute () ->
335+ let attrs = attrs |> List. filter (fun ({txt} , _ ) -> txt <> " JSX" ) in
336+ jsx_unary_element ~loc ~attrs tag_name []
330337 | Pexp_apply (e , l ) ->
331338 let e =
332339 match (e.pexp_desc, l) with
@@ -376,7 +383,7 @@ module E = struct
376383 | Pexp_tuple el -> tuple ~loc ~attrs (List. map (sub.expr sub) el)
377384 (* <></> *)
378385 | Pexp_construct ({txt = Longident. Lident " []" | Longident. Lident " ::" }, _)
379- when attrs |> List. exists ( fun ( {txt} , _ ) -> txt = " JSX " ) ->
386+ when has_jsx_attribute ( ) ->
380387 let attrs = attrs |> List. filter (fun ({txt} , _ ) -> txt <> " JSX" ) in
381388 (* TODO: support spread *)
382389 jsx_fragment ~loc ~attrs loc.loc_start
0 commit comments