Skip to content

Commit d714829

Browse files
committed
Fix jsx fragment mapping
1 parent 32161a3 commit d714829

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

compiler/ml/ast_mapper_from0.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,23 @@ end
295295
module E = struct
296296
(* Value expressions for the core language *)
297297

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
299315
let open Exp in
300316
let loc = sub.location sub loc in
301317
let attrs = sub.attributes sub attrs in
@@ -358,10 +374,11 @@ module E = struct
358374
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)
359375
| Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)
360376
| 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
365382
| Pexp_construct (lid, arg) -> (
366383
let lid1 = map_loc sub lid in
367384
let arg1 = map_opt (sub.expr sub) arg in

0 commit comments

Comments
 (0)