diff --git a/src/printer.js b/src/printer.js index 336cec09c..d57947a64 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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 ? "" : ">" ]) ); } diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap index b00a46528..0f462d487 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap @@ -838,6 +838,13 @@ onClick={() => {}}> ; +
+ {foo} +
; + + {} @@ -916,6 +923,12 @@ onClick={() => {}}> onClick={() => {}} />; +
+ {foo} +
; + {} diff --git a/tests/comments/jsx.js b/tests/comments/jsx.js index f135ccc1b..bff243611 100644 --- a/tests/comments/jsx.js +++ b/tests/comments/jsx.js @@ -89,6 +89,13 @@ onClick={() => {}}> ; +
+ {foo} +
; + + {} diff --git a/tests/comments_jsx_same_line/__snapshots__/jsfmt.spec.js.snap b/tests/comments_jsx_same_line/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..a6bd40911 --- /dev/null +++ b/tests/comments_jsx_same_line/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`jsx_same_line.js 1`] = ` +
+ {foo} +
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
+ {foo} +
; + +`; diff --git a/tests/comments_jsx_same_line/jsfmt.spec.js b/tests/comments_jsx_same_line/jsfmt.spec.js new file mode 100644 index 000000000..d0c9c5f94 --- /dev/null +++ b/tests/comments_jsx_same_line/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { jsxBracketSameLine: true }, ["babylon", "typescript"]); diff --git a/tests/comments_jsx_same_line/jsx_same_line.js b/tests/comments_jsx_same_line/jsx_same_line.js new file mode 100644 index 000000000..ed1fb27e1 --- /dev/null +++ b/tests/comments_jsx_same_line/jsx_same_line.js @@ -0,0 +1,5 @@ +
+ {foo} +
;