Skip to content

Commit 39bceb6

Browse files
authored
JSX V4: allow uncurried make function and treat it as usual (#5802)
* PPX V4: allow uncurried `make` function and treat it as usual * Update CHANGELOG.md
1 parent 9d706e7 commit 39bceb6

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#### :rocket: New Feature
1616

1717
- Introduce experimental uncurried by default mode. Can be turned on mid-file by adding standalone annotation `@@uncurried`. For experimentation only. https://github.com/rescript-lang/rescript-compiler/pull/5796
18-
1918
- Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800
2019

2120
#### :boom: Breaking Change
@@ -34,7 +33,7 @@ These are only breaking changes for unformatted code.
3433

3534
- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784
3635
- Syntax: process uncurried function declarations explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5794
37-
36+
- PPX V4: allow uncurried `make` function and treat it like a currie one https://github.com/rescript-lang/rescript-compiler/pull/5802
3837

3938
# 10.1.0-rc.5
4039

lib/4.06.1/unstable/js_compiler.ml

+12
Original file line numberDiff line numberDiff line change
@@ -154485,6 +154485,13 @@ let transformStructureItem ~config mapper item =
154485154485
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
154486154486
else (
154487154487
config.hasReactComponent <- true;
154488+
let binding =
154489+
match binding.pvb_expr.pexp_desc with
154490+
| Pexp_record
154491+
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
154492+
{binding with pvb_expr = e}
154493+
| _ -> binding
154494+
in
154488154495
let coreTypeOfAttr =
154489154496
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
154490154497
in
@@ -154897,6 +154904,11 @@ let transformSignatureItem ~config _mapper item =
154897154904
if config.React_jsx_common.hasReactComponent then
154898154905
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
154899154906
else config.hasReactComponent <- true;
154907+
let pval_type =
154908+
match pval_type.ptyp_desc with
154909+
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
154910+
| _ -> pval_type
154911+
in
154900154912
check_string_int_attribute_iter.signature_item
154901154913
check_string_int_attribute_iter item;
154902154914
let hasForwardRef = ref false in

lib/4.06.1/unstable/js_playground_compiler.ml

+20-1
Original file line numberDiff line numberDiff line change
@@ -154485,6 +154485,13 @@ let transformStructureItem ~config mapper item =
154485154485
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
154486154486
else (
154487154487
config.hasReactComponent <- true;
154488+
let binding =
154489+
match binding.pvb_expr.pexp_desc with
154490+
| Pexp_record
154491+
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
154492+
{binding with pvb_expr = e}
154493+
| _ -> binding
154494+
in
154488154495
let coreTypeOfAttr =
154489154496
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
154490154497
in
@@ -154897,6 +154904,11 @@ let transformSignatureItem ~config _mapper item =
154897154904
if config.React_jsx_common.hasReactComponent then
154898154905
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
154899154906
else config.hasReactComponent <- true;
154907+
let pval_type =
154908+
match pval_type.ptyp_desc with
154909+
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
154910+
| _ -> pval_type
154911+
in
154900154912
check_string_int_attribute_iter.signature_item
154901154913
check_string_int_attribute_iter item;
154902154914
let hasForwardRef = ref false in
@@ -168684,7 +168696,14 @@ and parseStandaloneAttribute p =
168684168696
let startPos = p.startPos in
168685168697
Parser.expect AtAt p;
168686168698
let attrId = parseAttributeId ~startPos p in
168687-
if attrId.txt = "uncurried" then p.uncurried_by_default <- true;
168699+
let attrId =
168700+
match attrId.txt with
168701+
| "uncurried" ->
168702+
p.uncurried_by_default <- true;
168703+
attrId
168704+
| "toUncurried" -> {attrId with txt = "uncurried"}
168705+
| _ -> attrId
168706+
in
168688168707
let payload = parsePayload p in
168689168708
(attrId, payload)
168690168709

lib/4.06.1/whole_compiler.ml

+20-1
Original file line numberDiff line numberDiff line change
@@ -164769,6 +164769,13 @@ let transformStructureItem ~config mapper item =
164769164769
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
164770164770
else (
164771164771
config.hasReactComponent <- true;
164772+
let binding =
164773+
match binding.pvb_expr.pexp_desc with
164774+
| Pexp_record
164775+
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
164776+
{binding with pvb_expr = e}
164777+
| _ -> binding
164778+
in
164772164779
let coreTypeOfAttr =
164773164780
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
164774164781
in
@@ -165181,6 +165188,11 @@ let transformSignatureItem ~config _mapper item =
165181165188
if config.React_jsx_common.hasReactComponent then
165182165189
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
165183165190
else config.hasReactComponent <- true;
165191+
let pval_type =
165192+
match pval_type.ptyp_desc with
165193+
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
165194+
| _ -> pval_type
165195+
in
165184165196
check_string_int_attribute_iter.signature_item
165185165197
check_string_int_attribute_iter item;
165186165198
let hasForwardRef = ref false in
@@ -182116,7 +182128,14 @@ and parseStandaloneAttribute p =
182116182128
let startPos = p.startPos in
182117182129
Parser.expect AtAt p;
182118182130
let attrId = parseAttributeId ~startPos p in
182119-
if attrId.txt = "uncurried" then p.uncurried_by_default <- true;
182131+
let attrId =
182132+
match attrId.txt with
182133+
| "uncurried" ->
182134+
p.uncurried_by_default <- true;
182135+
attrId
182136+
| "toUncurried" -> {attrId with txt = "uncurried"}
182137+
| _ -> attrId
182138+
in
182120182139
let payload = parsePayload p in
182121182140
(attrId, payload)
182122182141

res_syntax/cli/reactjs_jsx_v4.ml

+12
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,13 @@ let transformStructureItem ~config mapper item =
817817
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
818818
else (
819819
config.hasReactComponent <- true;
820+
let binding =
821+
match binding.pvb_expr.pexp_desc with
822+
| Pexp_record
823+
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
824+
{binding with pvb_expr = e}
825+
| _ -> binding
826+
in
820827
let coreTypeOfAttr =
821828
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
822829
in
@@ -1229,6 +1236,11 @@ let transformSignatureItem ~config _mapper item =
12291236
if config.React_jsx_common.hasReactComponent then
12301237
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
12311238
else config.hasReactComponent <- true;
1239+
let pval_type =
1240+
match pval_type.ptyp_desc with
1241+
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
1242+
| _ -> pval_type
1243+
in
12321244
check_string_int_attribute_iter.signature_item
12331245
check_string_int_attribute_iter item;
12341246
let hasForwardRef = ref false in

res_syntax/tests/ppx/react/expected/v4.res.txt

+21
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ module AnotherName = {
2121
\"V4$AnotherName$anotherName"
2222
}
2323
}
24+
25+
module Uncurried = {
26+
type props<'x> = {
27+
x: 'x,
28+
}
29+
30+
@react.component let make = ({x, _}: props<'x>) => React.string(x)
31+
let make = {
32+
let \"V4$Uncurried" = (props: props<_>) => make(props)
33+
34+
\"V4$Uncurried"
35+
}
36+
}
37+
38+
module type TUncurried = {
39+
type props<'x> = {
40+
x: 'x,
41+
}
42+
43+
let make: React.componentLike<props<string>, React.element>
44+
}

res_syntax/tests/ppx/react/v4.res

+10
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ module AnotherName = {
77
@react.component
88
let anotherName = (~x) => React.string(x)
99
}
10+
11+
module Uncurried = {
12+
@react.component
13+
let make = (. ~x) => React.string(x)
14+
}
15+
16+
module type TUncurried = {
17+
@react.component
18+
let make: (. ~x: string) => React.element
19+
}

0 commit comments

Comments
 (0)