Skip to content

Commit bd5d4f1

Browse files
committed
Try improve printing
1 parent 58ea87c commit bd5d4f1

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,11 +4404,16 @@ and print_jsx_expression ~state lident args cmt_tbl =
44044404
and print_jsx_fragment ~state (children : Parsetree.expression list) cmt_tbl =
44054405
let opening = Doc.text "<>" in
44064406
let closing = Doc.text "</>" in
4407-
let line_sep = if List.length children > 0 then Doc.hard_line else Doc.line in
4407+
let line_sep =
4408+
if
4409+
List.length children > 0
4410+
|| List.exists ParsetreeViewer.is_jsx_expression children
4411+
then Doc.hard_line
4412+
else Doc.line
4413+
in
44084414
Doc.group
44094415
(Doc.concat
44104416
[
4411-
line_sep;
44124417
opening;
44134418
(match children with
44144419
| [] -> Doc.nil
@@ -4418,9 +4423,9 @@ and print_jsx_fragment ~state (children : Parsetree.expression list) cmt_tbl =
44184423
[
44194424
Doc.line;
44204425
Doc.join ~sep:line_sep
4421-
(List.map
4422-
(fun e ->
4423-
print_jsx_child ~spread:false ~state e ~cmt_tbl)
4426+
(List.map
4427+
(fun e ->
4428+
print_jsx_child ~spread:false ~state e ~cmt_tbl)
44244429
children);
44254430
]));
44264431
line_sep;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ carriage return`
88
let x = "\""
99
let y = "\n"
1010

11-
1211
<>
1312
{"\n"->React.string}
1413
</>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ module Cite = {
6565
React.string("Hello, World!")}
6666
</div>
6767

68-
let x =
69-
<>
68+
let x = <>
7069
{a}
7170
{b}
7271
</>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,9 @@ let x = {
318318
}
319319

320320
// string constant should be printed correct
321-
322321
<>
323322
{"\n"->React.string}
324323
</>
325-
326324
<>
327325
{"\""->React.string}
328326
</>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ let f = () => {
202202
| Loading => "Loading ..."->React.string
203203
| Done(Error(_)) => "Error"->React.string
204204
| Done(Ok(users)) =>
205-
206205
<>
207206
<ul>
208207
{users

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ let nav3 =
9999
</NavContent>
100100
</Nav>
101101

102-
let avatarSection =
103-
<>
102+
let avatarSection = <>
104103
<div style={{"zIndex": "1", "opacity": opacityUser}}>
105104
<Avatar user={user} size={45} />
106105
</div>
@@ -122,7 +121,7 @@ let avatarSection =
122121
: React.nullElement}
123122
</>
124123

125-
let x = <> </>
124+
let x = <> </>
126125

127126
let x =
128127
<div
@@ -315,7 +314,6 @@ let x = <MyComponent sidebar={<div> test </div>} nav={<Navbar />} />
315314
module App = {
316315
@react.component
317316
let make = () => {
318-
319317
<>
320318
1
321319
</>
@@ -325,7 +323,6 @@ module App = {
325323
module App = {
326324
@react.component
327325
let make = () => {
328-
329326
<>
330327
<div />
331328
</>
@@ -439,8 +436,7 @@ let x = <C> ...{() => msg->React.string} </C>
439436

440437
let x = <C> ...{array->Array.map(React.string)} </C>
441438

442-
let x =
443-
<>
439+
let x = <>
444440
{array->Array.map(React.string)}
445441
</>
446442

@@ -455,8 +451,7 @@ let x = {
455451
}
456452

457453
let x = {
458-
let _ =
459-
<>
454+
let _ = <>
460455
{children}
461456
</>
462457
msg->React.string

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ switch route {
4949
<div> {React.string("Second A div")} </div>
5050
</div>
5151
| B =>
52-
5352
<>
5453
<div> {React.string("First B div")} </div>
5554
<div> {React.string("Second B div")} </div>

0 commit comments

Comments
 (0)