diff --git a/CHANGELOG.md b/CHANGELOG.md index 07615aa2ef..66b7fda9a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Fix leftover assert false in code for `null != undefined`. https://github.com/rescript-lang/rescript/pull/7232 - Editor: Fix issue where completions would not show up inside of object bodies. https://github.com/rescript-lang/rescript/pull/7230 - Fix issue with pattern matching empty list which interferes with boolean optimisations. https://github.com/rescript-lang/rescript/pull/7237 +- Fix Cannot combine @react.component and @directive. https://github.com/rescript-lang/rescript/pull/7260 #### :house: Internal diff --git a/compiler/syntax/src/jsx_v4.ml b/compiler/syntax/src/jsx_v4.ml index d2a2307508..cb5fc27470 100644 --- a/compiler/syntax/src/jsx_v4.ml +++ b/compiler/syntax/src/jsx_v4.ml @@ -1003,6 +1003,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = (Pat.var @@ Location.mknoloc "ref") inner_expression else inner_expression) + ~attrs:binding.pvb_expr.pexp_attributes in let full_expression = full_expression diff --git a/tests/tests/src/alias_default_value_test.mjs b/tests/tests/src/alias_default_value_test.mjs index ba7e994132..434e2b9763 100644 --- a/tests/tests/src/alias_default_value_test.mjs +++ b/tests/tests/src/alias_default_value_test.mjs @@ -67,6 +67,21 @@ let C6 = { make: Alias_default_value_test$C6 }; +function Alias_default_value_test$C7(props) { + 'use memo'; + let username = props.username; + let count = props.count; + let times = count !== 1 ? ( + count !== 2 ? String(count) + " times" : "twice" + ) : "once"; + let name = username !== undefined && username !== "" ? username : "Anonymous"; + return "Hello " + name + ", you clicked me " + times; +} + +let C7 = { + make: Alias_default_value_test$C7 +}; + export { C0, C1, @@ -74,5 +89,6 @@ export { C3, C4, C6, + C7, } /* No side effect */ diff --git a/tests/tests/src/alias_default_value_test.res b/tests/tests/src/alias_default_value_test.res index 6d8fce486b..1ebe9f00fa 100644 --- a/tests/tests/src/alias_default_value_test.res +++ b/tests/tests/src/alias_default_value_test.res @@ -43,3 +43,24 @@ module C6 = { @react.component let make = (~comp as module(Comp: Comp), ~x as (a, b)) => Comp.xx } + +module C7 = { + @react.component + let make = + @directive("'use memo'") + (~count, ~username=?) => { + let times = switch count { + | 1 => "once" + | 2 => "twice" + | n => Belt.Int.toString(n) ++ " times" + } + + let name = switch username { + | Some("") => "Anonymous" + | Some(name) => name + | None => "Anonymous" + } + + React.string(`Hello ${name}, you clicked me ` ++ times) + } +}