Skip to content

Commit

Permalink
Merge branch 'main' of github.com:/reasonml/reason-react into 19
Browse files Browse the repository at this point in the history
* 'main' of github.com:/reasonml/reason-react:
  fix: type of pipeable stream to allow objects with keys (#854)
  reason-react-ppx: + lower bound in ocaml
  add missing entries to changelog
  Fix multi-child fragment (#852)
  update compiler version in makefile cmd (#851)
  Add locations-check test (#844)
  fix: re-enable failing tests + fix location tests (#850)
  test: repro #840 (#842)
  Add CSS Box Alignment Module Level 3 (#847)
  • Loading branch information
davesnx committed Nov 15, 2024
2 parents 52c8144 + c07e413 commit 05d9f44
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 267 deletions.
11 changes: 9 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Unreleased
# 0.15.0

* Add `isValidElement` (@r17x in
https://github.com/reasonml/reason-react/pull/837)
* Add `startTransition` (@r17x in
https://github.com/reasonml/reason-react/pull/838)
* Convert `ReasonReactErrorBoundary` to Reason instead of `%raw` JS. This has
the benefit of skipping a hardcoded `require('react')` call (@anmonteiro in
[#839](https://github.com/reasonml/reason-react/pull/839))

* Add CSS Box Alignment Module Level 3 (@davesnx in
https://github.com/reasonml/reason-react/pull/847)
* Fix: Remove "unique `key` prop" warnings from multi-child fragment elements
(@jchavarri in https://github.com/reasonml/reason-react/pull/852)

# 0.14.1

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ install: ## Update the package dependencies when new deps are added to dune-proj

.PHONY: init
create-switch: ## Create a local opam switch
@opam switch create . 5.1.1 --no-install
@opam switch create . 5.2.0 --no-install

.PHONY: init
init: create-switch install ## Create a local opam switch, install deps
9 changes: 5 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(reason-react-ppx
(= :version))
(reason
(>= 3.10.0))
(>= 3.12.0))
(ocaml-lsp-server :with-dev-setup)
(opam-check-npm-deps
(and
Expand All @@ -55,11 +55,12 @@
(synopsis "React.js JSX PPX")
(description "ReasonReact JSX PPX")
(depends
ocaml
(ocaml
(>= 4.14))
(reason
(>= 3.10.0))
(>= 3.12.0))
(ppxlib
(>= 0.28.0))
(>= 0.33.0))
(merlin :with-test)
(ocamlformat
(and
Expand Down
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 35 additions & 11 deletions ppx/reason_react_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,25 @@ module Binding = struct
( { loc; txt = Ldot (Lident "React", "componentLike") },
[ props; return ] )

let jsxFragment ~loc ~attrs children =
let makeJsxFragment api ~loc ~attrs children =
let fragment =
Builder.pexp_ident ~loc
{ loc; txt = Ldot (Lident "React", "jsxFragment") }
in
Builder.pexp_apply ~loc ~attrs
(Builder.pexp_ident ~loc { loc; txt = Ldot (Lident "React", "jsx") })
(Builder.pexp_ident ~loc { loc; txt = Ldot (Lident "React", api) })
[
(nolabel, fragment);
( nolabel,
ReactDOM.domProps ~applyLoc:loc ~loc
[ (labelled "children", children); (nolabel, Builder.unit) ] );
]

let jsxFragment ~loc ~attrs children =
makeJsxFragment "jsx" ~loc ~attrs children

let jsxsFragment ~loc ~attrs children =
makeJsxFragment "jsxs" ~loc ~attrs children
end
end

Expand Down Expand Up @@ -1393,13 +1399,10 @@ let jsxMapper =
transformJsxCall ~ctxt parentExpLoc self callExpression
callArguments nonJSXAttributes)
(* is it a list with jsx attribute? Reason <>foo</> desugars to
[@JSX][foo]*)
[@JSX][foo]
This will match either <> </> or <> foo </> *)
| {
pexp_desc =
( Pexp_construct
( { txt = Lident "::"; loc },
Some { pexp_desc = Pexp_tuple _; _ } )
| Pexp_construct ({ txt = Lident "[]"; loc }, None) );
pexp_desc = Pexp_construct ({ txt = Lident ("[]" | "::"); loc }, lst);
pexp_attributes;
_;
} as listItems -> (
Expand All @@ -1411,13 +1414,34 @@ let jsxMapper =
match (jsxAttribute, nonJSXAttributes) with
(* no JSX attribute *)
| [], _ -> super#expression ctxt expr
| _, nonJSXAttributes ->
| _, nonJSXAttributes -> (
let childrenExpr =
transformChildrenIfList ~loc ~ctxt ~mapper:self listItems
in
(* throw away the [@JSX] attribute and keep the others, if any *)
Binding.React.jsxFragment ~loc ~attrs:nonJSXAttributes
(Binding.React.array ~loc childrenExpr))
match lst with
| None
| Some
{
pexp_desc =
Pexp_tuple
[
_;
{
pexp_desc =
Pexp_construct ({ txt = Lident "[]"; _ }, None);
_;
};
];
_;
} ->
Binding.React.jsxFragment ~loc ~attrs:nonJSXAttributes
(Binding.React.array ~loc childrenExpr)
| Some { pexp_desc = Pexp_tuple (_ :: _); _ } ->
(* Fragment with two or more children: <> foo bar </> *)
Binding.React.jsxsFragment ~loc ~attrs:nonJSXAttributes
(Binding.React.array ~loc childrenExpr)
| _ -> assert false))
(* Delegate to the default mapper, a deep identity traversal *)
| e -> super#expression ctxt e
[@@raises Invalid_argument]
Expand Down
2 changes: 1 addition & 1 deletion ppx/test/component.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We need to output ML syntax here, otherwise refmt could not parse it.
""[@@mel.obj ]
let make =
((fun ?(name= "") ->
React.jsx React.jsxFragment
React.jsxs React.jsxFragment
(((ReactDOM.domProps)[@merlin.hide ])
~children:(React.array
[|(ReactDOM.jsx "div"
Expand Down
5 changes: 0 additions & 5 deletions ppx/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@
%{bin:jq}
%{bin:ocamlmerlin}
ppx.sh))

(cram
(applies_to simple uppercase)
;; Disabled until https://github.com/reasonml/reason/issues/2737 is fixed
(enabled_if false))
6 changes: 3 additions & 3 deletions ppx/test/fragment.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
([@merlin.hide] ReactDOM.domProps)(~children=React.array([|bar|]), ()),
);
let poly_children_fragment = (foo, bar) =>
React.jsx(
React.jsxs(
React.jsxFragment,
([@merlin.hide] ReactDOM.domProps)(
~children=React.array([|foo, bar|]),
(),
),
);
let nested_fragment = (foo, bar, baz) =>
React.jsx(
React.jsxs(
React.jsxFragment,
([@merlin.hide] ReactDOM.domProps)(
~children=
React.array([|
foo,
React.jsx(
React.jsxs(
React.jsxFragment,
([@merlin.hide] ReactDOM.domProps)(
~children=React.array([|bar, baz|]),
Expand Down
Loading

0 comments on commit 05d9f44

Please sign in to comment.