@@ -310,9 +310,45 @@ module E = struct
310310    in 
311311    visit e
312312
313-   let  skip_last_two_elements  elements  = 
314-     let  length =  List. length elements in 
315-     List. filteri (fun  i  _  -> i <  length -  2 ) elements
313+   let  try_map_jsx_prop  (sub  : mapper ) (lbl  : Asttypes.Noloc.arg_label )
314+       (e  : expression ) : Parsetree.jsx_prop option  = 
315+     match  (lbl, e) with 
316+     |  Asttypes.Noloc. Labelled  "_spreadProps" , expr  ->
317+       Some  (Parsetree. JSXPropSpreading  (Location. none, sub.expr sub expr))
318+     |  ( Asttypes.Noloc. Labelled  name,
319+         {pexp_desc =  Pexp_ident  {txt =  Longident. Lident  v}; pexp_loc =  name_loc}
320+       )
321+       when  name =  v ->
322+       Some  (Parsetree. JSXPropPunning  (false , {txt =  name; loc =  name_loc}))
323+     |  ( Asttypes.Noloc. Optional  name,
324+         {pexp_desc =  Pexp_ident  {txt =  Longident. Lident  v}; pexp_loc =  name_loc}
325+       )
326+       when  name =  v ->
327+       Some  (Parsetree. JSXPropPunning  (true , {txt =  name; loc =  name_loc}))
328+     |  Asttypes.Noloc. Labelled  name , exp  ->
329+       Some 
330+         (Parsetree. JSXPropValue 
331+            ({txt =  name; loc =  Location. none}, false , sub.expr sub exp))
332+     |  Asttypes.Noloc. Optional  name , exp  ->
333+       Some 
334+         (Parsetree. JSXPropValue 
335+            ({txt =  name; loc =  Location. none}, true , sub.expr sub exp))
336+     |  _  -> None 
337+ 
338+   let  extract_props_and_children  (sub  : mapper ) items  = 
339+     let  rec  visit  props  items  = 
340+       match  items with 
341+       |  []  |  [_] -> (List. rev props, None )
342+       |  [(Asttypes.Noloc. Labelled  " children" 
343+         ( List. rev props,
344+           Some  (Parsetree. JSXChildrenItems  (map_jsx_list sub children_expr)) )
345+       |  (lbl , e ) :: rest  -> (
346+         match  try_map_jsx_prop sub lbl e with 
347+         |  Some  prop  -> visit (prop :: props) rest
348+         |  None  -> visit props rest)
349+     in 
350+     let  props, children =  visit []  items in 
351+     (props, children)
316352
317353  let  map  sub  e  = 
318354    let  {pexp_loc =  loc; pexp_desc =  desc; pexp_attributes =  attrs} =  e in 
@@ -335,47 +371,14 @@ module E = struct
335371        (sub.pat sub p) (sub.expr sub e)
336372    |  Pexp_function  _  -> assert  false 
337373    |  Pexp_apply  ({pexp_desc =  Pexp_ident  tag_name}, args)
338-       when  has_jsx_attribute ()  ->
374+       when  has_jsx_attribute ()  -> ( 
339375      let  attrs =  attrs |>  List. filter (fun  ({txt} , _ ) -> txt <>  " JSX" in 
340-       let  props = 
341-         args
342-         (*  The last args are children and unit *) 
343-         |>  skip_last_two_elements
344-         |>  List. filter_map (fun  (lbl , e ) ->
345-                match  (lbl, e) with 
346-                |  Asttypes.Noloc. Labelled  "_spreadProps" , expr  ->
347-                  Some 
348-                    (Parsetree. JSXPropSpreading  (Location. none, sub.expr sub expr))
349-                |  ( Asttypes.Noloc. Labelled  name,
350-                    {
351-                      pexp_desc =  Pexp_ident  {txt =  Longident. Lident  v};
352-                      pexp_loc =  name_loc;
353-                    } )
354-                  when  name =  v ->
355-                  Some 
356-                    (Parsetree. JSXPropPunning 
357-                       (false , {txt =  name; loc =  name_loc}))
358-                |  ( Asttypes.Noloc. Optional  name,
359-                    {
360-                      pexp_desc =  Pexp_ident  {txt =  Longident. Lident  v};
361-                      pexp_loc =  name_loc;
362-                    } )
363-                  when  name =  v ->
364-                  Some 
365-                    (Parsetree. JSXPropPunning  (true , {txt =  name; loc =  name_loc}))
366-                |  Asttypes.Noloc. Labelled  name , exp  ->
367-                  Some 
368-                    (Parsetree. JSXPropValue 
369-                       ( {txt =  name; loc =  Location. none},
370-                         false ,
371-                         sub.expr sub exp ))
372-                |  Asttypes.Noloc. Optional  name , exp  ->
373-                  Some 
374-                    (Parsetree. JSXPropValue 
375-                       ({txt =  name; loc =  Location. none}, true , sub.expr sub exp))
376-                |  _  -> None )
377-       in 
378-       jsx_unary_element ~loc  ~attrs  tag_name props
376+       let  props, children =  extract_props_and_children sub args in 
377+       match  children with 
378+       |  None  -> jsx_unary_element ~loc  ~attrs  tag_name props
379+       |  Some  children  ->
380+         jsx_container_element ~loc  ~attrs  tag_name props Lexing. dummy_pos
381+           children None )
379382    |  Pexp_apply  (e , l ) ->
380383      let  e = 
381384        match  (e.pexp_desc, l) with 
0 commit comments