Fix single indented JSX comment (#596)

This one was pretty annoying to figure out but now it's working. All the crazy comments I could throw at jsx seems to be working fine now :)

Fixes #543
master
Christopher Chedeau 2017-02-04 18:37:18 -08:00 committed by James Long
parent 153bf4cad9
commit 7abd6f5f9b
3 changed files with 33 additions and 2 deletions

View File

@ -1131,12 +1131,13 @@ function genericPrintNoParens(path, options, print) {
n.expression.type === "ArrowFunctionExpression" ||
n.expression.type === "CallExpression" ||
n.expression.type === "FunctionExpression" ||
n.expression.type === "JSXEmptyExpression" ||
parent.type === "JSXElement" &&
(n.expression.type === "ConditionalExpression" ||
n.expression.type === "LogicalExpression");
if (shouldInline) {
return concat(["{", path.call(print, "expression"), "}"]);
return group(concat(["{", path.call(print, "expression"), "}"]));
}
return group(
@ -1198,7 +1199,7 @@ function genericPrintNoParens(path, options, print) {
case "JSXText":
throw new Error("JSXTest should be handled by JSXElement");
case "JSXEmptyExpression":
return comments.printDanglingComments(path, options);
return concat([comments.printDanglingComments(path, options), softline]);
case "TypeAnnotatedIdentifier":
return concat([
path.call(print, "annotation"),

View File

@ -640,6 +640,12 @@ foo(
exports[`test jsx.js 1`] = `
"<div>
{
/* comment */
}
</div>;
<div>
{/* comment */
}
</div>;
@ -672,6 +678,12 @@ exports[`test jsx.js 1`] = `
{/* comment */}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div>
{
/* comment */
}
</div>;
<div>
{/* comment */}
</div>;
@ -706,6 +718,12 @@ exports[`test jsx.js 1`] = `
exports[`test jsx.js 2`] = `
"<div>
{
/* comment */
}
</div>;
<div>
{/* comment */
}
</div>;
@ -738,6 +756,12 @@ exports[`test jsx.js 2`] = `
{/* comment */}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div>
{
/* comment */
}
</div>;
<div>
{/* comment */}
</div>;

View File

@ -1,3 +1,9 @@
<div>
{
/* comment */
}
</div>;
<div>
{/* comment */
}