diff --git a/CHANGELOG.md b/CHANGELOG.md index b5025db44b..61d24dde24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - Autocomplete `@react.componentWithProps` attribute. https://github.com/rescript-lang/rescript/pull/7812 - Add some missing iframe attributes to `domProps`. https://github.com/rescript-lang/rescript/pull/7813 - Polish error message for inline record escaping scope. https://github.com/rescript-lang/rescript/pull/7808 +- Formatter: Change placement of closing `>` in JSX. https://github.com/rescript-lang/rescript/pull/7803 #### :house: Internal diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index cf790f8201..1bf0a714ed 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -4498,19 +4498,6 @@ and print_jsx_container_tag ~state tag_name (closing_tag : Parsetree.jsx_closing_container_tag option) (pexp_loc : Location.t) cmt_tbl = let name = print_jsx_name tag_name.txt in - let last_prop_has_comment_after = - let rec visit props = - match props with - | [] -> None - | [x] -> Some x - | _ :: xs -> visit xs - in - let last_prop = visit props in - match last_prop with - | None -> false - | Some last_prop -> - has_trailing_comments cmt_tbl (ParsetreeViewer.get_jsx_prop_loc last_prop) - in let opening_greater_than_loc = { Warnings.loc_start = opening_greater_than; @@ -4518,7 +4505,7 @@ and print_jsx_container_tag ~state tag_name loc_ghost = false; } in - let opening_greater_than_has_leading_comments, opening_greater_than_doc = + let _opening_greater_than_has_leading_comments, opening_greater_than_doc = let has_leading_comments = has_leading_comments cmt_tbl opening_greater_than_loc in @@ -4586,11 +4573,7 @@ and print_jsx_container_tag ~state tag_name (* if the element name has a single comment on the same line, force newline before '>' *) if has_trailing_single_line_comment cmt_tbl tag_loc then Doc.concat [Doc.hard_line; opening_greater_than_doc] - else if - last_prop_has_comment_after - || opening_greater_than_has_leading_comments - then Doc.concat [Doc.soft_line; opening_greater_than_doc] - else opening_greater_than_doc + else Doc.concat [Doc.soft_line; opening_greater_than_doc] in Doc.concat [ diff --git a/tests/gentype_tests/typescript-react-example/src/Hooks.res b/tests/gentype_tests/typescript-react-example/src/Hooks.res index 5468269e3a..0fb4c048b0 100644 --- a/tests/gentype_tests/typescript-react-example/src/Hooks.res +++ b/tests/gentype_tests/typescript-react-example/src/Hooks.res @@ -20,7 +20,8 @@ let make = (~vehicle) => { {React.string("child2")} React.string(x["randomString"])}> + person={name: "DefaultImport", age: 42} renderMe={x => React.string(x["randomString"])} + > {React.string("child1")} {React.string("child2")} diff --git a/tests/syntax_benchmarks/data/HeroGraphic.res b/tests/syntax_benchmarks/data/HeroGraphic.res index 22927a7fd1..9c0772682a 100644 --- a/tests/syntax_benchmarks/data/HeroGraphic.res +++ b/tests/syntax_benchmarks/data/HeroGraphic.res @@ -1997,7 +1997,8 @@ let make = (~width="760", ~height="380") => y1="180.64" x2="362.765" y2="435.722" - gradientUnits="userSpaceOnUse"> + gradientUnits="userSpaceOnUse" + > diff --git a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt index b49e82fece..17d75e3d9a 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt @@ -111,7 +111,8 @@ let make = () => {
(event->ReactEvent.Mouse.target)["querySelector"]("input")["focus"]()} - ref={containerRef->ReactDOMRe.Ref.domRef}> + ref={containerRef->ReactDOMRe.Ref.domRef} + > {state.history ->Array.mapWithIndex((index, item) =>
diff --git a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt index 2bf6cdf045..5817e35ee5 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt @@ -116,7 +116,8 @@ let avatarSection = onMouseLeave={_ => setHoveringAdmin(false)} onClick={_e => { stopImpersonating(csrfToken) - }}> + }} + >
: React.nullElement} @@ -497,7 +498,8 @@ let x = className="sdf sdfdsf sdfs sdf asdf dsf" onClick={() => { () - }}> + }} + > el {t(")")}
+ + + {React.string("yow")} + diff --git a/tests/syntax_tests/data/printer/expr/jsx.res b/tests/syntax_tests/data/printer/expr/jsx.res index a76d07981c..87f04e2c66 100644 --- a/tests/syntax_tests/data/printer/expr/jsx.res +++ b/tests/syntax_tests/data/printer/expr/jsx.res @@ -546,4 +546,11 @@ let arrow_with_container_tag = el =>
{t(nbsp ++ "(")} el {t(")")} -
\ No newline at end of file + + + + {React.string("yow")} + \ No newline at end of file diff --git a/tests/syntax_tests/data/printer/other/expected/signaturePicker.res.txt b/tests/syntax_tests/data/printer/other/expected/signaturePicker.res.txt index f73d98b8cb..fe32b18e3c 100644 --- a/tests/syntax_tests/data/printer/other/expected/signaturePicker.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/signaturePicker.res.txt @@ -28,7 +28,8 @@ let make = () => {
{"Signature"->string}