Skip to content

Commit 3d570a2

Browse files
authored
Change placement of closing > in JSX (#7803)
* Change placement of closing > in JSX * fmt of rescript code * Add changelog entry * Format ReScript code * I should have ran make build before make format
1 parent 94a7879 commit 3d570a2

File tree

9 files changed

+35
-28
lines changed

9 files changed

+35
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- Autocomplete `@react.componentWithProps` attribute. https://github.com/rescript-lang/rescript/pull/7812
4343
- Add some missing iframe attributes to `domProps`. https://github.com/rescript-lang/rescript/pull/7813
4444
- Polish error message for inline record escaping scope. https://github.com/rescript-lang/rescript/pull/7808
45+
- Formatter: Change placement of closing `>` in JSX. https://github.com/rescript-lang/rescript/pull/7803
4546

4647
#### :house: Internal
4748

compiler/syntax/src/res_printer.ml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,27 +4498,14 @@ and print_jsx_container_tag ~state tag_name
44984498
(closing_tag : Parsetree.jsx_closing_container_tag option)
44994499
(pexp_loc : Location.t) cmt_tbl =
45004500
let name = print_jsx_name tag_name.txt in
4501-
let last_prop_has_comment_after =
4502-
let rec visit props =
4503-
match props with
4504-
| [] -> None
4505-
| [x] -> Some x
4506-
| _ :: xs -> visit xs
4507-
in
4508-
let last_prop = visit props in
4509-
match last_prop with
4510-
| None -> false
4511-
| Some last_prop ->
4512-
has_trailing_comments cmt_tbl (ParsetreeViewer.get_jsx_prop_loc last_prop)
4513-
in
45144501
let opening_greater_than_loc =
45154502
{
45164503
Warnings.loc_start = opening_greater_than;
45174504
loc_end = opening_greater_than;
45184505
loc_ghost = false;
45194506
}
45204507
in
4521-
let opening_greater_than_has_leading_comments, opening_greater_than_doc =
4508+
let _opening_greater_than_has_leading_comments, opening_greater_than_doc =
45224509
let has_leading_comments =
45234510
has_leading_comments cmt_tbl opening_greater_than_loc
45244511
in
@@ -4586,11 +4573,7 @@ and print_jsx_container_tag ~state tag_name
45864573
(* if the element name has a single comment on the same line, force newline before '>' *)
45874574
if has_trailing_single_line_comment cmt_tbl tag_loc then
45884575
Doc.concat [Doc.hard_line; opening_greater_than_doc]
4589-
else if
4590-
last_prop_has_comment_after
4591-
|| opening_greater_than_has_leading_comments
4592-
then Doc.concat [Doc.soft_line; opening_greater_than_doc]
4593-
else opening_greater_than_doc
4576+
else Doc.concat [Doc.soft_line; opening_greater_than_doc]
45944577
in
45954578
Doc.concat
45964579
[

tests/gentype_tests/typescript-react-example/src/Hooks.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ let make = (~vehicle) => {
2020
{React.string("child2")}
2121
</ImportHooks>
2222
<ImportHookDefault
23-
person={name: "DefaultImport", age: 42} renderMe={x => React.string(x["randomString"])}>
23+
person={name: "DefaultImport", age: 42} renderMe={x => React.string(x["randomString"])}
24+
>
2425
{React.string("child1")}
2526
{React.string("child2")}
2627
</ImportHookDefault>

tests/syntax_benchmarks/data/HeroGraphic.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,8 @@ let make = (~width="760", ~height="380") =>
19971997
y1="180.64"
19981998
x2="362.765"
19991999
y2="435.722"
2000-
gradientUnits="userSpaceOnUse">
2000+
gradientUnits="userSpaceOnUse"
2001+
>
20012002
<stop offset="0.0658436" stopColor="#3A7DDD" />
20022003
<stop offset="0.4001" stopColor="#265291" />
20032004
<stop offset="0.571" stopColor="#1D3E6E" />

tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ let make = () => {
111111
<div
112112
className=Styles.terminal
113113
onClick={event => (event->ReactEvent.Mouse.target)["querySelector"]("input")["focus"]()}
114-
ref={containerRef->ReactDOMRe.Ref.domRef}>
114+
ref={containerRef->ReactDOMRe.Ref.domRef}
115+
>
115116
{state.history
116117
->Array.mapWithIndex((index, item) =>
117118
<div key={j`$index`} className=Styles.line>

tests/syntax_tests/data/printer/expr/expected/jsx.res.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ let avatarSection =
116116
onMouseLeave={_ => setHoveringAdmin(false)}
117117
onClick={_e => {
118118
stopImpersonating(csrfToken)
119-
}}>
119+
}}
120+
>
120121
<Avatar user={viewer} size={45} />
121122
</div>
122123
: React.nullElement}
@@ -497,7 +498,8 @@ let x =
497498
className="sdf sdfdsf sdfs sdf asdf dsf"
498499
onClick={() => {
499500
()
500-
}}>
501+
}}
502+
>
501503
<span
502504
id="2-1"
503505
className="sdf sdfdsf sdfs sdf asdf dsf"
@@ -566,3 +568,11 @@ let arrow_with_container_tag = el =>
566568
el
567569
{t(")")}
568570
</div>
571+
572+
<Component
573+
prop1
574+
//
575+
prop2
576+
>
577+
{React.string("yow")}
578+
</Component>

tests/syntax_tests/data/printer/expr/jsx.res

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,11 @@ let arrow_with_container_tag = el => <div>
546546
{t(nbsp ++ "(")}
547547
el
548548
{t(")")}
549-
</div>
549+
</div>
550+
551+
<Component
552+
prop1
553+
//
554+
prop2>
555+
{React.string("yow")}
556+
</Component>

tests/syntax_tests/data/printer/other/expected/signaturePicker.res.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ let make = () => {
2828
<div className="pr-2 font-bold text-gray-400 text-lg"> {"Signature"->string} </div>
2929
<select
3030
id="country"
31-
className="transition duration-150 ease-in-out sm:text-sm sm:leading-5 border-none font-bold text-2xl text-gray-600 bg-transparent">
31+
className="transition duration-150 ease-in-out sm:text-sm sm:leading-5 border-none font-bold text-2xl text-gray-600 bg-transparent"
32+
>
3233
{options
3334
->Belt.List.map(option =>
3435
<option key={option->TimeSignature.toString}>
@@ -47,7 +48,8 @@ let make = () => {
4748
fill="none"
4849
strokeLinecap="round"
4950
strokeLinejoin="round"
50-
className="text-gray-400">
51+
className="text-gray-400"
52+
>
5153
<polyline points="6 9 12 15 18 9" />
5254
</svg>
5355
</label>

tests/tests/src/jsx_preserve_test.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ let _youtube_iframe =
150150
frameBorder={0}
151151
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
152152
referrerPolicy="strict-origin-when-cross-origin"
153-
allowFullScreen={true}>
153+
allowFullScreen={true}
154+
>
154155
</iframe>

0 commit comments

Comments
 (0)