| 
295 | 295 | module E = struct  | 
296 | 296 |   (* Value expressions for the core language *)  | 
297 | 297 | 
 
  | 
298 |  | -  let map sub {pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} =  | 
 | 298 | +  let map_jsx_list sub (e : expression) : Pt.expression list =  | 
 | 299 | +    let rec visit (e : expression) : Pt.expression list =  | 
 | 300 | +      match e.pexp_desc with  | 
 | 301 | +      | Pexp_construct  | 
 | 302 | +          ({txt = Longident.Lident "::"}, Some {pexp_desc = Pexp_tuple [e1; e2]})  | 
 | 303 | +        ->  | 
 | 304 | +        sub.expr sub e1 :: visit e2  | 
 | 305 | +      | Pexp_construct ({txt = Longident.Lident "[]"}, ext_opt) -> (  | 
 | 306 | +        match ext_opt with  | 
 | 307 | +        | None -> []  | 
 | 308 | +        | Some e -> visit e)  | 
 | 309 | +      | _ -> [sub.expr sub e]  | 
 | 310 | +    in  | 
 | 311 | +    visit e  | 
 | 312 | + | 
 | 313 | +  let map sub e =  | 
 | 314 | +    let {pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} = e in  | 
299 | 315 |     let open Exp in  | 
300 | 316 |     let loc = sub.location sub loc in  | 
301 | 317 |     let attrs = sub.attributes sub attrs in  | 
@@ -358,10 +374,11 @@ module E = struct  | 
358 | 374 |       match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)  | 
359 | 375 |     | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)  | 
360 | 376 |     | Pexp_tuple el -> tuple ~loc ~attrs (List.map (sub.expr sub) el)  | 
361 |  | -    | Pexp_construct ({txt = Longident.Lident "[]"}, None)  | 
362 |  | -      when attrs |> List.exists (fun ({txt}, _) -> txt == "JSX") ->  | 
363 |  | -      let attrs = attrs |> List.filter (fun ({txt}, _) -> txt != "JSX") in  | 
364 |  | -      jsx_fragment ~loc ~attrs loc.loc_start [] loc.loc_end  | 
 | 377 | +    (* <></> *)  | 
 | 378 | +    | Pexp_construct ({txt = Longident.Lident "[]" | Longident.Lident "::"}, _)  | 
 | 379 | +      when attrs |> List.exists (fun ({txt}, _) -> txt = "JSX") ->  | 
 | 380 | +      let attrs = attrs |> List.filter (fun ({txt}, _) -> txt <> "JSX") in  | 
 | 381 | +      jsx_fragment ~loc ~attrs loc.loc_start (map_jsx_list sub e) loc.loc_end  | 
365 | 382 |     | Pexp_construct (lid, arg) -> (  | 
366 | 383 |       let lid1 = map_loc sub lid in  | 
367 | 384 |       let arg1 = map_opt (sub.expr sub) arg in  | 
 | 
0 commit comments