From 91546623ba1d4590475eaad653d0f53b17f45f46 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Thu, 8 Dec 2022 01:18:55 +0900 Subject: [PATCH 1/3] add test --- tests/ppx/react/aliasProps.res | 11 +++++ tests/ppx/react/expected/aliasProps.res.txt | 45 +++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/ppx/react/aliasProps.res create mode 100644 tests/ppx/react/expected/aliasProps.res.txt diff --git a/tests/ppx/react/aliasProps.res b/tests/ppx/react/aliasProps.res new file mode 100644 index 00000000..71734f50 --- /dev/null +++ b/tests/ppx/react/aliasProps.res @@ -0,0 +1,11 @@ +@@jsxConfig({version: 4, mode: "automatic"}) + +module C0 = { + @react.component + let make = (~priority as _, ~text="Test") => React.string(text) +} + +module C1 = { + @react.component + let make = (~priority as p, ~text="Test") => React.string(p ++ text) +} diff --git a/tests/ppx/react/expected/aliasProps.res.txt b/tests/ppx/react/expected/aliasProps.res.txt new file mode 100644 index 00000000..00103f5d --- /dev/null +++ b/tests/ppx/react/expected/aliasProps.res.txt @@ -0,0 +1,45 @@ +@@jsxConfig({version: 4, mode: "automatic"}) + +module C0 = { + type props<'priority, 'text> = { + priority: 'priority, + text?: 'text, + } + + @react.component + let make = (_: props<'priority, 'text>) => { + let text = switch text { + | Some(text) => text + | None => "Test" + } + + (~text="Test") => React.string(text) + } + let make = { + let \"AliasProps$C0" = (props: props<_>) => make(props) + + \"AliasProps$C0" + } +} + +module C1 = { + type props<'priority, 'text> = { + priority: 'priority, + text?: 'text, + } + + @react.component + let make = ({priority: p, ?text, _}: props<'priority, 'text>) => { + let text = switch text { + | Some(text) => text + | None => "Test" + } + + React.string(p ++ text) + } + let make = { + let \"AliasProps$C1" = (props: props<_>) => make(props) + + \"AliasProps$C1" + } +} From 4716f75715a1a8305fb8d1933bae959b385dc8f1 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Thu, 8 Dec 2022 01:21:39 +0900 Subject: [PATCH 2/3] fix alias props to any case in jsx v4 --- cli/reactjs_jsx_v4.ml | 5 +---- tests/ppx/react/expected/aliasProps.res.txt | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index ef478ecc..040bc54c 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -1082,10 +1082,7 @@ let transformStructureItem ~config mapper item = | Pexp_fun ( _arg_label, _default, - { - ppat_desc = - Ppat_construct ({txt = Lident "()"}, _) | Ppat_any; - }, + {ppat_desc = Ppat_construct ({txt = Lident "()"}, _)}, expr ) -> (patternsWithLabel, patternsWithNolabel, expr) | Pexp_fun diff --git a/tests/ppx/react/expected/aliasProps.res.txt b/tests/ppx/react/expected/aliasProps.res.txt index 00103f5d..d99b8e22 100644 --- a/tests/ppx/react/expected/aliasProps.res.txt +++ b/tests/ppx/react/expected/aliasProps.res.txt @@ -7,13 +7,13 @@ module C0 = { } @react.component - let make = (_: props<'priority, 'text>) => { + let make = ({priority: _, ?text, _}: props<'priority, 'text>) => { let text = switch text { | Some(text) => text | None => "Test" } - (~text="Test") => React.string(text) + React.string(text) } let make = { let \"AliasProps$C0" = (props: props<_>) => make(props) From 11955fb94386b0f4bcc6a6b808c20770ea0b5298 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Thu, 8 Dec 2022 01:24:24 +0900 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e12a2885..5d5e5820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ - Fix issue where the JSX fragment without children build error https://github.com/rescript-lang/syntax/pull/704 - Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707 - Treat await as almost-unary operator weaker than pipe so `await foo->bar` means `await (foo->bar)` https://github.com/rescript-lang/syntax/pull/711 +- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/syntax/pull/720 #### :eyeglasses: Spec Compliance