Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 0.26.0
version = 0.27.0
47 changes: 27 additions & 20 deletions ppx/reason_react_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let constantString ~loc str =

let safeTypeFromValue valueStr =
match getLabel valueStr with
| Some valueStr when String.sub valueStr 0 1 = "_" -> ("T" ^ valueStr)
| Some valueStr when String.sub valueStr 0 1 = "_" -> "T" ^ valueStr
| Some valueStr -> valueStr
| None -> ""

Expand Down Expand Up @@ -229,8 +229,10 @@ let hasAttrOnBinding { pvb_attributes; _ } =
let getFnName binding =
match binding with
| { pvb_pat = { ppat_desc = Ppat_var { txt; _ }; _ }; _ } -> txt
| { pvb_loc; _} ->
Location.raise_errorf ~loc:pvb_loc "[@react.component] cannot be used with a destructured binding. Please use it on a `let make = ...` binding instead."
| { pvb_loc; _ } ->
Location.raise_errorf ~loc:pvb_loc
"[@react.component] cannot be used with a destructured binding. Please \
use it on a `let make = ...` binding instead."

let makeNewBinding binding expression newName =
match binding with
Expand All @@ -243,7 +245,9 @@ let makeNewBinding binding expression newName =
pvb_attributes = [ merlinFocus ];
}
| { pvb_loc; _ } ->
Location.raise_errorf ~loc:pvb_loc "[@react.component] cannot be used with a destructured binding. Please use it on a `let make = ...` binding instead."
Location.raise_errorf ~loc:pvb_loc
"[@react.component] cannot be used with a destructured binding. Please \
use it on a `let make = ...` binding instead."

(* Lookup the value of `props` otherwise raise errorf *)
let getPropsNameValue _acc (loc, expr) =
Expand All @@ -252,7 +256,9 @@ let getPropsNameValue _acc (loc, expr) =
{ pexp_desc = Pexp_ident { txt = Lident str; _ }; _ } ) ->
{ propsName = str }
| { txt; loc }, _ ->
Location.raise_errorf ~loc "[@react.component] only accepts 'props' as a field, given: %s" (Longident.last_exn txt)
Location.raise_errorf ~loc
"[@react.component] only accepts 'props' as a field, given: %s"
(Longident.last_exn txt)

(* Lookup the `props` record or string as part of [@react.component] and store
the name for use when rewriting *)
Expand All @@ -261,22 +267,22 @@ let getPropsAttr payload =
match payload with
| Some
(PStr
({
pstr_desc =
Pstr_eval ({ pexp_desc = Pexp_record (recordFields, None); _ }, _);
_;
}
:: _rest)) ->
({
pstr_desc =
Pstr_eval ({ pexp_desc = Pexp_record (recordFields, None); _ }, _);
_;
}
:: _rest)) ->
List.fold_left getPropsNameValue defaultProps recordFields
| Some
(PStr
({
pstr_desc =
Pstr_eval
({ pexp_desc = Pexp_ident { txt = Lident "props"; _ }; _ }, _);
_;
}
:: _rest)) ->
({
pstr_desc =
Pstr_eval
({ pexp_desc = Pexp_ident { txt = Lident "props"; _ }; _ }, _);
_;
}
:: _rest)) ->
{ propsName = "props" }
| Some (PStr ({ pstr_desc = Pstr_eval (_, _); pstr_loc; _ } :: _rest)) ->
Location.raise_errorf ~loc:pstr_loc
Expand Down Expand Up @@ -487,7 +493,7 @@ let jsxExprAndChildren ~component_type ~loc ~ctxt mapper ~keyProps children =
children *)
( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxs") },
None,
Some (Binding.React.array ~loc children))
Some (Binding.React.array ~loc children) )
| None, (label, key) :: _ ->
( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxKeyed") },
Some (label, key),
Expand Down Expand Up @@ -645,7 +651,8 @@ let jsxMapper =
match expr.pexp_desc with
| Pexp_fun (Labelled "key", _, _, _) | Pexp_fun (Optional "key", _, _, _) ->
Location.raise_errorf ~loc:expr.pexp_loc
("~key cannot be accessed from the component props. Please set the key where the component is being used.")
"~key cannot be accessed from the component props. Please set the \
key where the component is being used."
| Pexp_fun
( ((Optional label | Labelled label) as arg),
default,
Expand Down
77 changes: 50 additions & 27 deletions src/ReactDOM.re
Original file line number Diff line number Diff line change
Expand Up @@ -484,30 +484,35 @@ module Experimental = {
external preloadOptions:
(
~_as: [
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
~fetchPriority: [ | `auto | `high | `low]=?,
~referrerPolicy: [
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"]
`noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"]
`originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]
=?,
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
~fetchPriority:
[
| `auto
| `high
| `low
]
=?,
~referrerPolicy:
[
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]
=?,
~imageSrcSet: string=?,
~imageSizes: string=?,
~crossOrigin: string=?,
Expand All @@ -520,11 +525,29 @@ module Experimental = {
[@deriving jsProperties]
type preinitOptions = {
[@mel.as "as"]
_as: [ | `script | `style],
_as: [
| `script
| `style
],
[@mel.optional]
fetchPriority: option([ | `auto | `high | `low]),
fetchPriority:
option(
[
| `auto
| `high
| `low
],
),
[@mel.optional]
precedence: option([ | `reset | `low | `medium | `high]),
precedence:
option(
[
| `reset
| `low
| `medium
| `high
],
),
[@mel.optional]
crossOrigin: option(string),
[@mel.optional]
Expand Down
79 changes: 51 additions & 28 deletions src/ReactDOM.rei
Original file line number Diff line number Diff line change
Expand Up @@ -490,42 +490,47 @@ module Experimental: {
type preloadOptions;

[@mel.obj]
/* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */
external preloadOptions:
/* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */
(
~_as: [
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
/*
Suggests a relative priority for fetching the resource.
The possible values are auto (the default), high, and low.
*/
~fetchPriority: [ | `auto | `high | `low]=?,
~fetchPriority:
[
| `auto
| `high
| `low
]
=?,
/*
The Referrer header to send when fetching.
Its possible values are no-referrer-when-downgrade (the default), no-referrer, origin, origin-when-cross-origin, and unsafe-url.
*/
~referrerPolicy: [
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"]
`noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"]
`originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]
=?,
~referrerPolicy:
[
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]
=?,
/*
For use only with as: "image". Specifies the source set of the image.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
Expand Down Expand Up @@ -563,20 +568,38 @@ module Experimental: {
type preinitOptions = {
/* possible values: "script" or "style" */
[@mel.as "as"]
_as: [ | `script | `style],
_as: [
| `script
| `style
],
/*
Suggests a relative priority for fetching the resource.
The possible values are auto (the default), high, and low.
*/
[@mel.optional]
fetchPriority: option([ | `auto | `high | `low]),
fetchPriority:
option(
[
| `auto
| `high
| `low
],
),
/*
Required with Stylesheets (`style). Says where to insert the stylesheet relative to others.
Stylesheets with higher precedence can override those with lower precedence.
The possible values are reset, low, medium, high.
*/
[@mel.optional]
precedence: option([ | `reset | `low | `medium | `high]),
precedence:
option(
[
| `reset
| `low
| `medium
| `high
],
),
/*
a required string. It must be "anonymous", "use-credentials", and "".
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
Expand Down
Loading
Loading