ml-in-barcelona / jsoo-react

js_of_ocaml bindings for ReactJS. Based on ReasonReact.
https://ml-in-barcelona.github.io/jsoo-react
MIT License
137 stars 19 forks source link

allow locally abstract type and type constraint on component definitions #151

Closed glennsl closed 2 years ago

glennsl commented 2 years ago

This makes the ppx not reject locally abstract type definitions (e.g. (type a)) and type constraints on component definitions.

For example, these used to be rejected:

let%component make (type a) ~(foo : a) : _ = div [||] []
let%component make : type a. foo:a -> _ = fun ~foo:_ -> div [||] []

with the error

react.component calls can only be on function definitions or component wrappers (forward_ref, memo).

The latter also produced the error:

Fatal error: exception (Invalid_argument "react.component calls cannot be destructured.")

Which has been improved, along with a few other errors, by using Location.raise_errorf instead of invalid_arg.

tjltjl commented 2 years ago

Really great! I just bumped into this yesterday :D