Skip to content

Commit e3f28e2

Browse files
authored
Copy attributes from original binding expression (#7260)
* Copy attributes from original binding expression * Add sample to test file * Remove comment * Add changelog entry
1 parent 3750ca3 commit e3f28e2

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Fix leftover assert false in code for `null != undefined`. https://github.com/rescript-lang/rescript/pull/7232
1919
- Editor: Fix issue where completions would not show up inside of object bodies. https://github.com/rescript-lang/rescript/pull/7230
2020
- Fix issue with pattern matching empty list which interferes with boolean optimisations. https://github.com/rescript-lang/rescript/pull/7237
21+
- Fix Cannot combine @react.component and @directive. https://github.com/rescript-lang/rescript/pull/7260
2122

2223
#### :house: Internal
2324

compiler/syntax/src/jsx_v4.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
10031003
(Pat.var @@ Location.mknoloc "ref")
10041004
inner_expression
10051005
else inner_expression)
1006+
~attrs:binding.pvb_expr.pexp_attributes
10061007
in
10071008
let full_expression =
10081009
full_expression

tests/tests/src/alias_default_value_test.mjs

+16
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,28 @@ let C6 = {
6767
make: Alias_default_value_test$C6
6868
};
6969

70+
function Alias_default_value_test$C7(props) {
71+
'use memo';
72+
let username = props.username;
73+
let count = props.count;
74+
let times = count !== 1 ? (
75+
count !== 2 ? String(count) + " times" : "twice"
76+
) : "once";
77+
let name = username !== undefined && username !== "" ? username : "Anonymous";
78+
return "Hello " + name + ", you clicked me " + times;
79+
}
80+
81+
let C7 = {
82+
make: Alias_default_value_test$C7
83+
};
84+
7085
export {
7186
C0,
7287
C1,
7388
C2,
7489
C3,
7590
C4,
7691
C6,
92+
C7,
7793
}
7894
/* No side effect */

tests/tests/src/alias_default_value_test.res

+21
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,24 @@ module C6 = {
4343
@react.component
4444
let make = (~comp as module(Comp: Comp), ~x as (a, b)) => Comp.xx
4545
}
46+
47+
module C7 = {
48+
@react.component
49+
let make =
50+
@directive("'use memo'")
51+
(~count, ~username=?) => {
52+
let times = switch count {
53+
| 1 => "once"
54+
| 2 => "twice"
55+
| n => Belt.Int.toString(n) ++ " times"
56+
}
57+
58+
let name = switch username {
59+
| Some("") => "Anonymous"
60+
| Some(name) => name
61+
| None => "Anonymous"
62+
}
63+
64+
React.string(`Hello ${name}, you clicked me ` ++ times)
65+
}
66+
}

0 commit comments

Comments
 (0)