Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 392c100

Browse files
authored
JSX4: Fix missing attributes from props type (#731)
1 parent 380440e commit 392c100

File tree

4 files changed

+88
-11
lines changed

4 files changed

+88
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
- Fix dropping attributes from props in make function in JSX V4 https://github.com/rescript-lang/syntax/pull/723
5858
- Fix an issue where error messages related to duplicate props were displayed without a loc and were unclear https://github.com/rescript-lang/syntax/pull/728
5959
- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730
60+
- Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/syntax/pull/731
6061

6162
#### :eyeglasses: Spec Compliance
6263

cli/reactjs_jsx_v4.ml

+2-11
Original file line numberDiff line numberDiff line change
@@ -719,19 +719,10 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
719719
in
720720
match (type_, name, default) with
721721
| Some type_, name, _ when isOptional name ->
722-
( true,
723-
getLabel name,
724-
attrs,
725-
loc,
726-
{type_ with ptyp_attributes = optionalAttrs} )
727-
:: types
722+
(true, getLabel name, attrs, loc, type_) :: types
728723
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
729724
| None, name, _ when isOptional name ->
730-
( true,
731-
getLabel name,
732-
attrs,
733-
loc,
734-
Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) )
725+
(true, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
735726
:: types
736727
| None, name, _ when isLabelled name ->
737728
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@@jsxConfig({version: 4})
2+
type props<'a> = {a?: 'a}
3+
4+
@react.component
5+
let make = ({?a, _}: props<(. unit) => unit>) => {
6+
let a = switch a {
7+
| Some(a) => a
8+
| None => (. ()) => ()
9+
}
10+
11+
React.null
12+
}
13+
let make = {
14+
let \"UncurriedProps" = (props: props<_>) => make(props)
15+
16+
\"UncurriedProps"
17+
}
18+
19+
let func = (~callback: (. string, bool, bool) => unit=(. _, _, _) => (), ()) => {
20+
let _ = callback
21+
}
22+
23+
func(~callback=(. str, a, b) => {
24+
let _ = str
25+
let _ = a
26+
let _ = b
27+
}, ())
28+
29+
module Foo = {
30+
type props<'callback> = {callback?: 'callback}
31+
32+
@react.component
33+
let make = ({?callback, _}: props<(. string, bool, bool) => unit>) => {
34+
let callback = switch callback {
35+
| Some(callback) => callback
36+
| None => (. _, _, _) => ()
37+
}
38+
39+
{
40+
React.null
41+
}
42+
}
43+
let make = {
44+
let \"UncurriedProps$Foo" = (props: props<_>) => make(props)
45+
46+
\"UncurriedProps$Foo"
47+
}
48+
}
49+
50+
module Bar = {
51+
type props = {}
52+
53+
@react.component let make = (_: props) => React.jsx(Foo.make, {callback: (. _, _, _) => ()})
54+
let make = {
55+
let \"UncurriedProps$Bar" = props => make(props)
56+
57+
\"UncurriedProps$Bar"
58+
}
59+
}

tests/ppx/react/uncurriedProps.res

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@@jsxConfig({ version: 4 })
2+
3+
@react.component
4+
let make = (~a: (. unit) => unit=(. ) => ()) => React.null
5+
6+
let func = (~callback: (. string, bool, bool) => unit=(. _, _, _) => (), ()) => {
7+
let _ = callback
8+
}
9+
10+
func(~callback=(. str, a, b) => {
11+
let _ = str
12+
let _ = a
13+
let _ = b
14+
}, ())
15+
16+
module Foo = {
17+
@react.component
18+
let make = (~callback: (. string, bool, bool) => unit=(. _, _, _) => ()) => {
19+
React.null
20+
}
21+
}
22+
23+
module Bar = {
24+
@react.component
25+
let make = () => <Foo callback={(. _, _, _) => ()} />
26+
}

0 commit comments

Comments
 (0)