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

JSX V4: allow uncurried make function and treat it as usual #5802

Merged
merged 2 commits into from
Nov 14, 2022
Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#### :rocket: New Feature

- 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

- Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800

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

- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784
- Syntax: process uncurried function declarations explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5794

- PPX V4: allow uncurried `make` function and treat it like a currie one https://github.com/rescript-lang/rescript-compiler/pull/5802

# 10.1.0-rc.5

Expand Down
12 changes: 12 additions & 0 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154485,6 +154485,13 @@ let transformStructureItem ~config mapper item =
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
else (
config.hasReactComponent <- true;
let binding =
match binding.pvb_expr.pexp_desc with
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
{binding with pvb_expr = e}
| _ -> binding
in
let coreTypeOfAttr =
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
in
Expand Down Expand Up @@ -154897,6 +154904,11 @@ let transformSignatureItem ~config _mapper item =
if config.React_jsx_common.hasReactComponent then
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
else config.hasReactComponent <- true;
let pval_type =
match pval_type.ptyp_desc with
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
| _ -> pval_type
in
check_string_int_attribute_iter.signature_item
check_string_int_attribute_iter item;
let hasForwardRef = ref false in
Expand Down
21 changes: 20 additions & 1 deletion lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154485,6 +154485,13 @@ let transformStructureItem ~config mapper item =
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
else (
config.hasReactComponent <- true;
let binding =
match binding.pvb_expr.pexp_desc with
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
{binding with pvb_expr = e}
| _ -> binding
in
let coreTypeOfAttr =
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
in
Expand Down Expand Up @@ -154897,6 +154904,11 @@ let transformSignatureItem ~config _mapper item =
if config.React_jsx_common.hasReactComponent then
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
else config.hasReactComponent <- true;
let pval_type =
match pval_type.ptyp_desc with
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
| _ -> pval_type
in
check_string_int_attribute_iter.signature_item
check_string_int_attribute_iter item;
let hasForwardRef = ref false in
Expand Down Expand Up @@ -168684,7 +168696,14 @@ and parseStandaloneAttribute p =
let startPos = p.startPos in
Parser.expect AtAt p;
let attrId = parseAttributeId ~startPos p in
if attrId.txt = "uncurried" then p.uncurried_by_default <- true;
let attrId =
match attrId.txt with
| "uncurried" ->
p.uncurried_by_default <- true;
attrId
| "toUncurried" -> {attrId with txt = "uncurried"}
| _ -> attrId
in
let payload = parsePayload p in
(attrId, payload)

Expand Down
21 changes: 20 additions & 1 deletion lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164769,6 +164769,13 @@ let transformStructureItem ~config mapper item =
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
else (
config.hasReactComponent <- true;
let binding =
match binding.pvb_expr.pexp_desc with
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
{binding with pvb_expr = e}
| _ -> binding
in
let coreTypeOfAttr =
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
in
Expand Down Expand Up @@ -165181,6 +165188,11 @@ let transformSignatureItem ~config _mapper item =
if config.React_jsx_common.hasReactComponent then
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
else config.hasReactComponent <- true;
let pval_type =
match pval_type.ptyp_desc with
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
| _ -> pval_type
in
check_string_int_attribute_iter.signature_item
check_string_int_attribute_iter item;
let hasForwardRef = ref false in
Expand Down Expand Up @@ -182116,7 +182128,14 @@ and parseStandaloneAttribute p =
let startPos = p.startPos in
Parser.expect AtAt p;
let attrId = parseAttributeId ~startPos p in
if attrId.txt = "uncurried" then p.uncurried_by_default <- true;
let attrId =
match attrId.txt with
| "uncurried" ->
p.uncurried_by_default <- true;
attrId
| "toUncurried" -> {attrId with txt = "uncurried"}
| _ -> attrId
in
let payload = parsePayload p in
(attrId, payload)

Expand Down
12 changes: 12 additions & 0 deletions res_syntax/cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,13 @@ let transformStructureItem ~config mapper item =
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
else (
config.hasReactComponent <- true;
let binding =
match binding.pvb_expr.pexp_desc with
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
{binding with pvb_expr = e}
| _ -> binding
in
let coreTypeOfAttr =
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
in
Expand Down Expand Up @@ -1229,6 +1236,11 @@ let transformSignatureItem ~config _mapper item =
if config.React_jsx_common.hasReactComponent then
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
else config.hasReactComponent <- true;
let pval_type =
match pval_type.ptyp_desc with
| Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
| _ -> pval_type
in
check_string_int_attribute_iter.signature_item
check_string_int_attribute_iter item;
let hasForwardRef = ref false in
Expand Down
21 changes: 21 additions & 0 deletions res_syntax/tests/ppx/react/expected/v4.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,24 @@ module AnotherName = {
\"V4$AnotherName$anotherName"
}
}

module Uncurried = {
type props<'x> = {
x: 'x,
}

@react.component let make = ({x, _}: props<'x>) => React.string(x)
let make = {
let \"V4$Uncurried" = (props: props<_>) => make(props)

\"V4$Uncurried"
}
}

module type TUncurried = {
type props<'x> = {
x: 'x,
}

let make: React.componentLike<props<string>, React.element>
}
10 changes: 10 additions & 0 deletions res_syntax/tests/ppx/react/v4.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ module AnotherName = {
@react.component
let anotherName = (~x) => React.string(x)
}

module Uncurried = {
@react.component
let make = (. ~x) => React.string(x)
}

module type TUncurried = {
@react.component
let make: (. ~x: string) => React.element
}