From a6be47b85ab88fafc261d3b47e7dfc830431f344 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 4 Feb 2023 03:19:34 +0900 Subject: [PATCH 1/4] add tests --- .../ppx/react/expected/uncurriedProps.res.txt | 59 +++++++++++++++++++ tests/ppx/react/uncurriedProps.res | 26 ++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/ppx/react/expected/uncurriedProps.res.txt create mode 100644 tests/ppx/react/uncurriedProps.res diff --git a/tests/ppx/react/expected/uncurriedProps.res.txt b/tests/ppx/react/expected/uncurriedProps.res.txt new file mode 100644 index 00000000..9719e308 --- /dev/null +++ b/tests/ppx/react/expected/uncurriedProps.res.txt @@ -0,0 +1,59 @@ +@@jsxConfig({version: 4}) +type props<'a> = {a?: 'a} + +@react.component +let make = ({?a, _}: props<(unit => unit)>) => { + let a = switch a { + | Some(a) => a + | None => (. ()) => () + } + + React.null +} +let make = { + let \"UncurriedProps" = (props: props<_>) => make(props) + + \"UncurriedProps" +} + +let func = (~callback: (. string, bool, bool) => unit=(. _, _, _) => (), ()) => { + let _ = callback +} + +func(~callback=(. str, a, b) => { + let _ = str + let _ = a + let _ = b +}, ()) + +module Foo = { + type props<'callback> = {callback?: 'callback} + + @react.component + let make = ({?callback, _}: props<(string, bool, bool) => unit>) => { + let callback = switch callback { + | Some(callback) => callback + | None => (. _, _, _) => () + } + + { + React.null + } + } + let make = { + let \"UncurriedProps$Foo" = (props: props<_>) => make(props) + + \"UncurriedProps$Foo" + } +} + +module Bar = { + type props = {} + + @react.component let make = (_: props) => React.jsx(Foo.make, {callback: (. _, _, _) => ()}) + let make = { + let \"UncurriedProps$Bar" = props => make(props) + + \"UncurriedProps$Bar" + } +} diff --git a/tests/ppx/react/uncurriedProps.res b/tests/ppx/react/uncurriedProps.res new file mode 100644 index 00000000..d0bcd3e2 --- /dev/null +++ b/tests/ppx/react/uncurriedProps.res @@ -0,0 +1,26 @@ +@@jsxConfig({ version: 4 }) + +@react.component +let make = (~a: (. unit) => unit=(. ) => ()) => React.null + +let func = (~callback: (. string, bool, bool) => unit=(. _, _, _) => (), ()) => { + let _ = callback +} + +func(~callback=(. str, a, b) => { + let _ = str + let _ = a + let _ = b +}, ()) + +module Foo = { + @react.component + let make = (~callback: (. string, bool, bool) => unit=(. _, _, _) => ()) => { + React.null + } +} + +module Bar = { + @react.component + let make = () => ()} /> +} From 13c17532ba57fd91a82a607dd456db88ab0b4b4f Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 4 Feb 2023 03:20:25 +0900 Subject: [PATCH 2/4] fix missing attributes from props type --- cli/reactjs_jsx_v4.ml | 2 +- tests/ppx/react/expected/uncurriedProps.res.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index 1ff40cc3..2eb1dd51 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -723,7 +723,7 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types getLabel name, attrs, loc, - {type_ with ptyp_attributes = optionalAttrs} ) + {type_ with ptyp_attributes = optionalAttr :: type_.ptyp_attributes} ) :: types | Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types | None, name, _ when isOptional name -> diff --git a/tests/ppx/react/expected/uncurriedProps.res.txt b/tests/ppx/react/expected/uncurriedProps.res.txt index 9719e308..cf50e101 100644 --- a/tests/ppx/react/expected/uncurriedProps.res.txt +++ b/tests/ppx/react/expected/uncurriedProps.res.txt @@ -2,7 +2,7 @@ type props<'a> = {a?: 'a} @react.component -let make = ({?a, _}: props<(unit => unit)>) => { +let make = ({?a, _}: props<(. unit) => unit>) => { let a = switch a { | Some(a) => a | None => (. ()) => () @@ -30,7 +30,7 @@ module Foo = { type props<'callback> = {callback?: 'callback} @react.component - let make = ({?callback, _}: props<(string, bool, bool) => unit>) => { + let make = ({?callback, _}: props<(. string, bool, bool) => unit>) => { let callback = switch callback { | Some(callback) => callback | None => (. _, _, _) => () From cb061215e1a359646c3e577e777634234666ca23 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 4 Feb 2023 03:26:57 +0900 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0badee4..e92c49b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ - Fix dropping attributes from props in make function in JSX V4 https://github.com/rescript-lang/syntax/pull/723 - 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 - Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730 +- 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 #### :eyeglasses: Spec Compliance From 32812855302d7e5fe194b6ef770b4fdc6c3aef90 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 4 Feb 2023 03:45:10 +0900 Subject: [PATCH 4/4] remove unnecessary optional attrs --- cli/reactjs_jsx_v4.ml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index 2eb1dd51..68fa27c1 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -719,19 +719,10 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types in match (type_, name, default) with | Some type_, name, _ when isOptional name -> - ( true, - getLabel name, - attrs, - loc, - {type_ with ptyp_attributes = optionalAttr :: type_.ptyp_attributes} ) - :: types + (true, getLabel name, attrs, loc, type_) :: types | Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types | None, name, _ when isOptional name -> - ( true, - getLabel name, - attrs, - loc, - Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) ) + (true, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name)) :: types | None, name, _ when isLabelled name -> (false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))