Skip to content

Commit af651a6

Browse files
IwanKaramazowchenglou
authored andcommitted
Improve printing of jsx: (reasonml#2219)
* inline Pexp_apply where possible with brace hugging * improve formatting of spread children with Pexp_apply & Pexp_fun
1 parent d3a50cd commit af651a6

File tree

3 files changed

+247
-40
lines changed

3 files changed

+247
-40
lines changed

formatTest/unit_tests/expected_output/jsx.re

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,18 @@ let y =
4343

4444
let z =
4545
<div
46-
style={
47-
ReactDOMRe.Style.make(
48-
~width,
49-
~height,
50-
~color,
51-
~backgroundColor,
52-
~margin,
53-
~padding,
54-
~border,
55-
~borderColor,
56-
~someOtherAttribute,
57-
(),
58-
)
59-
}
46+
style={ReactDOMRe.Style.make(
47+
~width,
48+
~height,
49+
~color,
50+
~backgroundColor,
51+
~margin,
52+
~padding,
53+
~border,
54+
~borderColor,
55+
~someOtherAttribute,
56+
(),
57+
)}
6058
key={string_of_int(1)}
6159
/>;
6260

@@ -174,13 +172,11 @@ let y = [
174172
child
175173
</Description>;
176174
<Description
177-
term={
178-
Text.createElement(
179-
~text="Age",
180-
~children=[],
181-
(),
182-
)
183-
}>
175+
term={Text.createElement(
176+
~text="Age",
177+
~children=[],
178+
(),
179+
)}>
184180
child
185181
</Description>;
186182
<Description
@@ -499,3 +495,79 @@ switch (foo) {
499495
</div>;
500496

501497
ReasonReact.(<> {string("Test")} </>);
498+
499+
<div
500+
style={
501+
[@foo]
502+
ReactDOMRe.Style.make(
503+
~width="20px",
504+
~height="20px",
505+
~borderRadius="100%",
506+
~backgroundColor="red",
507+
)
508+
}
509+
/>;
510+
511+
<Animated initialValue=0.0 value>
512+
...{ReactDOMRe.Style.make(
513+
~width="20px",
514+
~height="20px",
515+
~borderRadius="100%",
516+
~backgroundColor="red",
517+
)}
518+
</Animated>;
519+
520+
<Animated initialValue=0.0 value>
521+
...{value =>
522+
<div
523+
style={ReactDOMRe.Style.make(
524+
~width="20px",
525+
~height="20px",
526+
~borderRadius="100%",
527+
~backgroundColor="red",
528+
)}
529+
/>
530+
}
531+
</Animated>;
532+
533+
<Animated initialValue=0.0 value>
534+
...{(value): ReasonReact.element =>
535+
<div
536+
style={ReactDOMRe.Style.make(
537+
~width="20px",
538+
~height="20px",
539+
~borderRadius="100%",
540+
~backgroundColor="red",
541+
)}
542+
/>
543+
}
544+
</Animated>;
545+
546+
<Animated initialValue=0.0 value>
547+
...{[@foo] value =>
548+
<div
549+
style={ReactDOMRe.Style.make(
550+
~width="20px",
551+
~height="20px",
552+
~borderRadius="100%",
553+
~backgroundColor="red",
554+
)}
555+
/>
556+
}
557+
</Animated>;
558+
559+
<Animated initialValue=0.0 value>
560+
...{value => {
561+
let width = "20px";
562+
let height = "20px";
563+
564+
<div
565+
style={ReactDOMRe.Style.make(
566+
~width,
567+
~height,
568+
~borderRadius="100%",
569+
~backgroundColor="red",
570+
)}
571+
/>;
572+
}}
573+
</Animated>;

formatTest/unit_tests/input/jsx.re

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,95 @@ switch(foo) {
375375
</div>;
376376

377377
ReasonReact.(<> {string("Test")} </>);
378+
379+
<div
380+
style={
381+
[@foo]
382+
ReactDOMRe.Style.make(
383+
~width="20px",
384+
~height="20px",
385+
~borderRadius="100%",
386+
~backgroundColor="red",
387+
)
388+
}
389+
/>;
390+
391+
<Animated initialValue=0.0 value>
392+
...{
393+
ReactDOMRe.Style.make(
394+
~width="20px",
395+
~height="20px",
396+
~borderRadius="100%",
397+
~backgroundColor="red",
398+
)
399+
}
400+
</Animated>;
401+
402+
<Animated initialValue=0.0 value>
403+
...{
404+
value =>
405+
<div
406+
style={
407+
ReactDOMRe.Style.make(
408+
~width="20px",
409+
~height="20px",
410+
~borderRadius="100%",
411+
~backgroundColor="red",
412+
)
413+
}
414+
/>
415+
}
416+
</Animated>;
417+
418+
<Animated initialValue=0.0 value>
419+
...{
420+
(value) :ReasonReact.element =>
421+
<div
422+
style={
423+
ReactDOMRe.Style.make(
424+
~width="20px",
425+
~height="20px",
426+
~borderRadius="100%",
427+
~backgroundColor="red",
428+
)
429+
}
430+
/>
431+
}
432+
</Animated>;
433+
434+
435+
<Animated initialValue=0.0 value>
436+
...{
437+
[@foo] value => {
438+
<div
439+
style={
440+
ReactDOMRe.Style.make(
441+
~width="20px",
442+
~height="20px",
443+
~borderRadius="100%",
444+
~backgroundColor="red",
445+
)
446+
}
447+
/>
448+
}
449+
}
450+
</Animated>;
451+
452+
<Animated initialValue=0.0 value>
453+
...{value => {
454+
let width = "20px";
455+
let height = "20px";
456+
457+
<div
458+
style={
459+
ReactDOMRe.Style.make(
460+
~width,
461+
~height,
462+
~borderRadius="100%",
463+
~backgroundColor="red",
464+
)
465+
}
466+
/>
467+
}
468+
}
469+
</Animated>;

0 commit comments

Comments
 (0)