Skip to content

Commit e446ae1

Browse files
committed
Try support children spreading
1 parent d6c9fa8 commit e446ae1

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

compiler/ml/ast_mapper_from0.ml

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

298-
let map_jsx_list sub (e : expression) : Pt.expression list =
298+
let map_jsx_children sub (e : expression) : Pt.jsx_children =
299299
let rec visit (e : expression) : Pt.expression list =
300300
match e.pexp_desc with
301301
| Pexp_construct
@@ -308,7 +308,11 @@ module E = struct
308308
| Some e -> visit e)
309309
| _ -> [sub.expr sub e]
310310
in
311-
visit e
311+
match e.pexp_desc with
312+
| Pexp_construct ({txt = Longident.Lident "[]" | Longident.Lident "::"}, _)
313+
->
314+
JSXChildrenItems (visit e)
315+
| _ -> JSXChildrenSpreading (sub.expr sub e)
312316

313317
let try_map_jsx_prop (sub : mapper) (lbl : Asttypes.Noloc.arg_label)
314318
(e : expression) : Parsetree.jsx_prop option =
@@ -340,8 +344,7 @@ module E = struct
340344
match items with
341345
| [] | [_] -> (List.rev props, None)
342346
| [(Asttypes.Noloc.Labelled "children", children_expr); _] ->
343-
( List.rev props,
344-
Some (Parsetree.JSXChildrenItems (map_jsx_list sub children_expr)) )
347+
(List.rev props, Some (map_jsx_children sub children_expr))
345348
| (lbl, e) :: rest -> (
346349
match try_map_jsx_prop sub lbl e with
347350
| Some prop -> visit (prop :: props) rest
@@ -431,8 +434,7 @@ module E = struct
431434
when has_jsx_attribute () ->
432435
let attrs = attrs |> List.filter (fun ({txt}, _) -> txt <> "JSX") in
433436
(* TODO: support spread *)
434-
jsx_fragment ~loc ~attrs loc.loc_start
435-
(Parsetree.JSXChildrenItems (map_jsx_list sub e))
437+
jsx_fragment ~loc ~attrs loc.loc_start (map_jsx_children sub e)
436438
loc.loc_end
437439
| Pexp_construct (lid, arg) -> (
438440
let lid1 = map_loc sub lid in

compiler/ml/ast_mapper_to0.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,11 @@ module E = struct
335335
(Asttypes.Noloc.Labelled "_spreadProps", sub.expr sub value))
336336

337337
let map_jsx_children sub loc children =
338-
let xs =
339-
match children with
340-
| JSXChildrenSpreading e -> [e]
341-
| JSXChildrenItems xs -> xs
342-
in
343-
let list_expr = Ast_helper.Exp.make_list_expression loc xs None in
344-
sub.expr sub list_expr
338+
match children with
339+
| JSXChildrenSpreading e -> sub.expr sub e
340+
| JSXChildrenItems xs ->
341+
let list_expr = Ast_helper.Exp.make_list_expression loc xs None in
342+
sub.expr sub list_expr
345343

346344
(* Value expressions for the core language *)
347345

0 commit comments

Comments
 (0)