Skip to content

Commit

Permalink
Copy attributes from original binding expression (#7260)
Browse files Browse the repository at this point in the history
* Copy attributes from original binding expression

* Add sample to test file

* Remove comment

* Add changelog entry
  • Loading branch information
nojaf authored Jan 30, 2025
1 parent 3750ca3 commit e3f28e2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
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)
}
}

1 comment on commit e3f28e2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Syntax Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: e3f28e2 Previous: e1b7fb7 Ratio
Parse RedBlackTree.res - time/run 1.3611299533333332 ms 1.2123143266666667 ms 1.12
Parse Napkinscript.res - time/run 42.3050655 ms 39.28006235333333 ms 1.08
Parse HeroGraphic.res - time/run 6.398748053333333 ms 5.13472718 ms 1.25

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.