Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove raise annotations and fix locations on errors #863

Merged
merged 14 commits into from
Nov 25, 2024
Next Next commit
Enable ref in ppx
  • Loading branch information
davesnx committed Nov 25, 2024
commit 27402210edeb0b8b1d29899c18eef32dfa0ffca1
5 changes: 0 additions & 5 deletions ppx/reason_react_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,6 @@ let jsxMapper =
(Invalid_argument
"Key cannot be accessed inside of a component. Don't worry - you \
can always key a component from its parent!")
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _) ->
raise
(Invalid_argument
"Ref cannot be passed as a normal prop. Please use `forwardRef` \
API instead.")
| Pexp_fun
( ((Optional label | Labelled label) as arg),
default,
Expand Down
7 changes: 7 additions & 0 deletions ppx/test/component.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ module Forward_Ref = {
});
};

module Ref_as_prop = {
[@react.component]
let make = (~children, ~ref) => {
<button ref className="FancyButton"> children </button>;
};
};

module Onclick_handler_button = {
[@react.component]
let make = (~name, ~isDisabled=?) => {
Expand Down
21 changes: 21 additions & 0 deletions ppx/test/component.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ We need to output ML syntax here, otherwise refmt could not parse it.
make ~buttonRef:(Props ## buttonRef) ~children:(Props ## children) in
Output$Forward_Ref)
end
module Ref_as_prop =
struct
external makeProps :
children:'children ->
ref:'ref ->
?key:string -> unit -> < children: 'children ;ref: 'ref > Js.t
= ""[@@mel.obj ]
let make =
((fun ~children ->
((fun ~ref ->
ReactDOM.jsx "button"
(((ReactDOM.domProps)[@merlin.hide ]) ~children ~ref
~className:"FancyButton" ()))
[@warning "-16"]))
[@warning "-16"])
let make =
let Output$Ref_as_prop
(Props : < children: 'children ;ref: 'ref > Js.t) =
make ~ref:(Props ## ref) ~children:(Props ## children) in
Output$Ref_as_prop
end
module Onclick_handler_button =
struct
external makeProps :
Expand Down