@@ -284,6 +284,29 @@ module E = struct
284284  let  jsx_attr  sub  = 
285285    sub.attribute sub (Location. mknoloc " JSX" Parsetree. PStr  [] )
286286
287+   let  offset_position  (pos  : Lexing.position ) (offset  : int ) : Lexing.position  = 
288+     if  offset < =  0  then  pos
289+     else 
290+       let  open  Lexing  in 
291+       let  rec  aux  pos  offset  = 
292+         if  offset < =  0  then  pos
293+         else  if  offset < =  pos.pos_cnum -  pos.pos_bol then 
294+           (*  We're on the same line *) 
295+           {pos with  pos_cnum =  pos.pos_cnum -  offset}
296+         else 
297+           (*  Move to previous line and continue *) 
298+           let  remaining =  offset -  (pos.pos_cnum -  pos.pos_bol) in 
299+           aux
300+             {
301+               pos with 
302+               pos_lnum =  pos.pos_lnum -  1 ;
303+               pos_cnum =  pos.pos_bol;
304+               pos_bol =  max 0  (pos.pos_bol -  remaining);
305+             }
306+             remaining
307+       in 
308+       aux pos offset
309+ 
287310  (*  Value expressions for the core language *) 
288311
289312  let  map  sub  {pexp_loc  = loc ; pexp_desc  = desc ; pexp_attributes  = attrs }  = 
@@ -426,24 +449,45 @@ module E = struct
426449
427450      {mapped with  pexp_attributes =  jsx_attr sub  :: attrs }
428451    |  Pexp_jsx_unary_element 
429-         {
430-           jsx_unary_element_tag_name =  tag_name;
431-           jsx_unary_element_props =  _props;
432-         } ->
452+         {jsx_unary_element_tag_name =  tag_name; jsx_unary_element_props =  props}
453+       ->
433454      let  tag_ident =  map_loc sub tag_name in 
455+       let  props = 
456+         props
457+         |>  List. map (function 
458+              |  JSXPropPunning  (is_optional , name ) ->
459+                let  ident = 
460+                  ident ~loc: name.loc
461+                    {txt =  Longident. Lident  name.txt; loc =  name.loc}
462+                in 
463+                let  label = 
464+                  if  is_optional then  Asttypes.Noloc. Optional  name.txt
465+                  else  Asttypes.Noloc. Labelled  name.txt
466+                in 
467+                (label, ident)
468+              |  _  -> failwith " todo" 
469+       in 
434470      let  children_expr = 
435-         Ast_helper0.Exp. construct ~loc  {txt =  Lident  " ()" None 
471+         let  loc = 
472+           {
473+             loc_ghost =  true ;
474+             loc_start =  offset_position loc.loc_end 2 ;
475+             loc_end =  offset_position loc.loc_end 1 ;
476+           }
477+         in 
478+         Ast_helper0.Exp. construct ~loc  {txt =  Lident  " []" None 
436479      in 
437480      let  unit_expr = 
438481        Ast_helper0.Exp. construct ~loc: ! Ast_helper0. default_loc
439482          {txt =  Lident  " ()" =  ! Ast_helper0. default_loc}
440483          None 
441484      in 
442485      apply ~loc  ~attrs: (jsx_attr sub :: attrs) (ident tag_ident)
443-         [
444-           (Asttypes.Noloc. Labelled  " children" 
445-           (Asttypes.Noloc. Nolabel , unit_expr);
446-         ]
486+         (props
487+         @  [
488+             (Asttypes.Noloc. Labelled  " children" 
489+             (Asttypes.Noloc. Nolabel , unit_expr);
490+           ])
447491    |  Pexp_jsx_container_element  _  ->
448492      failwith " TODO: Pexp_jsx_container_element 1" 
449493end 
0 commit comments