Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions formatTest/unit_tests/expected_output/jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -623,21 +623,17 @@ ReasonReact.(<> {string("Test")} </>);
</div>;

<div>
{
let left = limit->Int.toString;
{j|$left characters left|j}->React.string;
}
{let left = limit->Int.toString;
{j|$left characters left|j}->React.string}
</div>;

<View style=styles##backgroundImageWrapper>
{
let uri = "/images/header-background.png";
<Image
resizeMode=`contain
style=styles##backgroundImage
uri
/>;
}
{let uri = "/images/header-background.png";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have this form of wrapping anywhere else (not intentionally at least). Is there a reason why this isn't breaking into multiple lines?

{
  let uri = 
  ...
}

@anmonteiro anmonteiro May 7, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been here for a while, e.g. #2208.

We did it initially to save space on JSX patterns like:

<div>
  {
    React.string("foo")
  }
</div>

<Image
resizeMode=`contain
style=styles##backgroundImage
uri
/>}
</View>;

<div>
Expand All @@ -650,3 +646,15 @@ ReasonReact.(<> {string("Test")} </>);
{ReasonReact.string("bar")}
</span>}
</div>;

let v =
<A>
<B>
...{_ => {
let renderX = x =>
{let y = x ++ x;
<div key=y />};
renderX("foo");
}}
</B>
</A>;
13 changes: 13 additions & 0 deletions formatTest/unit_tests/input/jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,16 @@ ReasonReact.(<> {string("Test")} </>);
<span> {ReasonReact.string(foo)} </span>}
: <span> {ReasonReact.string("bar")} </span>}
</div>;

let v =
<A>
<B>
...{_ => {
let renderX = x => {
let y = x ++ x;
<div key=y />;
};
renderX("foo");
}}
</B>
</A>;
8 changes: 2 additions & 6 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6096,7 +6096,7 @@ let printer = object(self:'self)
~inline:(true, inline_braces)
~wrap:("{", "}")
~postSpace:true
~sep:(if inline_braces then NoSep else (SepFinal (";", ";")))
~sep:(if inline_braces then (Sep ";") else (SepFinal (";", ";")))
(self#letList x)
in
Some layout
Expand Down Expand Up @@ -6272,11 +6272,7 @@ let printer = object(self:'self)
| head :: remaining ->
self#formatChildren
remaining
(self
#dont_preserve_braces (* the brace logic is handled here *)
#simplifyUnparseExpr ~inline:true ~wrap:("{", "}")
head
:: processedRev)
(self#inline_braces#simplifyUnparseExpr ~inline:true ~wrap:("{", "}") head :: processedRev)
| [] -> match processedRev with
| [] -> None
| _::_ -> Some (List.rev processedRev)
Expand Down