@@ -205,7 +205,7 @@ let makePropsRecordType propsName loc namedTypeList =
205205 namedTypeList
206206 |> List. map (fun (isOptional , label , _ , _interiorType ) ->
207207 if label = " key" then Type. field ~loc ~attrs: optionalAttr { txt = label; loc } (keyType Location. none)
208- else if label = " ref" then Type. field ~loc ~attrs: optionalAttr { txt = label; loc } (refType Location. none)
208+ else if label = " ref" then Type. field ~loc ~attrs: ( if isOptional then optionalAttr else [] ) { txt = label; loc } (refType Location. none)
209209 else if isOptional then Type. field ~loc ~attrs: optionalAttr { txt = label; loc } (Typ. var label)
210210 else Type. field ~loc { txt = label; loc } (Typ. var label))
211211 in
@@ -485,7 +485,7 @@ let jsxMapper () =
485485 (* type props<'id, 'name> = { @optional key: string, @optional id: 'id, ... } *)
486486 let propsRecordType =
487487 makePropsRecordType " props" Location. none
488- ((true , " key" , [] , keyType pstr_loc) :: ( true , " ref " , [] , refType pstr_loc) :: namedTypeList)
488+ ((true , " key" , [] , keyType pstr_loc) :: namedTypeList)
489489 in
490490 (* can't be an arrow because it will defensively uncurry *)
491491 let newExternalType =
@@ -645,7 +645,8 @@ let jsxMapper () =
645645 (* type props = { ... } *)
646646 let propsRecordType =
647647 makePropsRecordType " props" emptyLoc
648- ((true , " key" , [] , keyType emptyLoc) :: (true , " ref" , [] , refType pstr_loc) :: namedTypeList)
648+ (((true , " key" , [] , keyType emptyLoc) :: namedTypeList)
649+ @ if hasForwardRef then [ (true , " ref" , [] , refType pstr_loc) ] else [] )
649650 in
650651 let innerExpression = if hasForwardRef then
651652 Exp. apply (Exp. ident @@ Location. mknoloc @@ Lident " make" )
@@ -693,13 +694,23 @@ let jsxMapper () =
693694 | _ -> (patterns, expr)
694695 in
695696 let patternsWithLid, expression = returnedExpression [] expression in
696- let pattern = (Pat. record ((List. rev patternsWithLid) @ [(Location. mknoloc (Lident " ref" ), Pat. var (Location. mknoloc " ref" ))]) Closed )
697+ let patternsWithLid = ((List. rev patternsWithLid)
698+ @
699+ (if hasForwardRef then [(Location. mknoloc (Lident " ref" ), Pat. var (Location. mknoloc " ref" ))] else [] ))
700+ in
701+ let pattern = match patternsWithLid with
702+ | [] -> Pat. any ()
703+ | _ -> (Pat. record patternsWithLid Closed )
697704 in
698705 (* add patttern matching for optional prop value *)
699706 let expression = if List. length vbMatchList = 0 then expression else (Exp. let_ Nonrecursive vbMatchList expression) in
700707 (* add let _ = ref to ignore unused warning *)
701- let expression = Exp. let_ Nonrecursive [ vbIgnoreUnusedRef ] expression in
702- let expression = Exp. let_ Nonrecursive [ vbRefFromOption ] expression in
708+ let expression = match hasForwardRef with
709+ | true ->
710+ let expression = Exp. let_ Nonrecursive [ vbIgnoreUnusedRef ] expression in
711+ Exp. let_ Nonrecursive [ vbRefFromOption ] expression
712+ | false -> expression
713+ in
703714 let expression = Exp. fun_ Nolabel None
704715 begin
705716 Pat. constraint_ pattern
@@ -776,7 +787,7 @@ let jsxMapper () =
776787 in
777788 let propsRecordType =
778789 makePropsRecordTypeSig " props" Location. none
779- ((true , " key" , [] , keyType Location. none) :: ( true , " ref " , [] , refType Location. none) :: namedTypeList)
790+ ((true , " key" , [] , keyType Location. none) :: namedTypeList)
780791 in
781792 (* can't be an arrow because it will defensively uncurry *)
782793 let newExternalType =
0 commit comments