Skip to content

Copy attributes from original binding expression #7260

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

Merged
merged 4 commits into from
Jan 30, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/src/alias_default_value_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,28 @@ 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,
C2,
C3,
C4,
C6,
C7,
}
/* No side effect */
21 changes: 21 additions & 0 deletions tests/tests/src/alias_default_value_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}