@@ -477,9 +477,10 @@ let jsxMapper () =
477
477
recursivelyTransformNamedArgsForMake mapper expression ((arg, default, pattern, alias, pattern.ppat_loc, type_) :: list )
478
478
| Pexp_fun (Nolabel , _ , { ppat_desc = (Ppat_construct ({txt = Lident "()" } , _ ) | Ppat_any )} , _expression ) ->
479
479
(list , None )
480
- | Pexp_fun (Nolabel, _ , { ppat_desc = Ppat_var ({txt} )} , _expression ) ->
480
+ | Pexp_fun (Nolabel , _ , { ppat_desc = Ppat_var ({txt} ) | Ppat_constraint ( { ppat_desc = Ppat_var ( {txt} )} , _ ) } , _expression ) ->
481
481
(list , Some txt)
482
-
482
+ | Pexp_fun (Nolabel, _ , pattern , _expression ) ->
483
+ Location. raise_errorf ~loc: pattern.ppat_loc " ReasonReact: react.component refs only support plain arguments and type annotations."
483
484
| _ -> (list , None )
484
485
in
485
486
@@ -618,6 +619,7 @@ let jsxMapper () =
618
619
spelunkForFunExpression expression
619
620
in
620
621
let modifiedBinding binding =
622
+ let hasApplication = ref (false ) in
621
623
let wrapExpressionWithBinding expressionFn expression =
622
624
Vb. mk
623
625
~loc: bindingLoc
@@ -641,14 +643,16 @@ let jsxMapper () =
641
643
(* let make = (~prop) => ... *)
642
644
| {
643
645
pexp_desc = Pexp_fun ((Labelled (_) | Optional (_)), _default, _pattern, _internalExpression)
644
- } -> ((fun a -> a), false , unerasableIgnoreExp expression)
646
+ } -> ((fun a -> a), false , unerasableIgnoreExp expression)
645
647
(* let make = (prop) => ... *)
646
648
| {
647
649
pexp_desc = Pexp_fun (_nolabel, _default, _pattern, _internalExpression);
648
650
pexp_loc
649
651
} ->
650
- Location. raise_errorf ~loc: pexp_loc
651
- " Make sure to use labeled arguments for props, if your component doesn't take any props use () or _ instead of a name as your argument"
652
+ if (hasApplication.contents) then
653
+ ((fun a -> a), false , unerasableIgnoreExp expression)
654
+ else
655
+ Location. raise_errorf ~loc: pattern.ppat_loc " ReasonReact: props need to be labelled arguments.\n If you are working with refs be sure to wrap with React.forwardRef.\n If your component doesn't have any props use () or _ instead of a name."
652
656
(* let make = {let foo = bar in (~prop) => ...} *)
653
657
| {
654
658
pexp_desc = Pexp_let (recursive, vbs, internalExpression)
@@ -658,6 +662,7 @@ let jsxMapper () =
658
662
(wrap, hasUnit, {expression with pexp_desc = Pexp_let (recursive, vbs, exp)})
659
663
(* let make = React.forwardRef((~prop) => ...) *)
660
664
| { pexp_desc = Pexp_apply (wrapperExpression , [(Nolabel, internalExpression )]) } ->
665
+ let () = hasApplication := true in
661
666
let (_, hasUnit, exp) = spelunkForFunExpression internalExpression in
662
667
((fun exp -> Exp. apply wrapperExpression [(nolabel, exp)]), hasUnit, exp)
663
668
| {
0 commit comments