Don't print JSX bracket on same line when it has trailing comments (#3088)

master
Lucas Azzola 2017-10-23 17:13:12 +11:00 committed by GitHub
parent 11d7213862
commit c0aaa0fa52
6 changed files with 52 additions and 2 deletions

View File

@ -1774,6 +1774,14 @@ function genericPrintNoParens(path, options, print, args) {
);
}
const bracketSameLine =
options.jsxBracketSameLine &&
!(
n.name &&
((n.name.trailingComments && n.name.trailingComments.length) ||
(n.name.comments && n.name.comments.length))
);
return group(
concat([
"<",
@ -1784,9 +1792,9 @@ function genericPrintNoParens(path, options, print, args) {
path.map(attr => concat([line, print(attr)]), "attributes")
)
),
n.selfClosing ? line : options.jsxBracketSameLine ? ">" : softline
n.selfClosing ? line : bracketSameLine ? ">" : softline
]),
n.selfClosing ? "/>" : options.jsxBracketSameLine ? "" : ">"
n.selfClosing ? "/>" : bracketSameLine ? "" : ">"
])
);
}

View File

@ -838,6 +838,13 @@ onClick={() => {}}>
</div>;
<div
// comment
>
{foo}
</div>;
<Wrapper>
{}
<Component />
@ -916,6 +923,12 @@ onClick={() => {}}>
onClick={() => {}}
/>;
<div
// comment
>
{foo}
</div>;
<Wrapper>
{}
<Component />

View File

@ -89,6 +89,13 @@ onClick={() => {}}>
</div>;
<div
// comment
>
{foo}
</div>;
<Wrapper>
{}
<Component />

View File

@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`jsx_same_line.js 1`] = `
<div
// comment
>
{foo}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
// comment
>
{foo}
</div>;
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, { jsxBracketSameLine: true }, ["babylon", "typescript"]);

View File

@ -0,0 +1,5 @@
<div
// comment
>
{foo}
</div>;