diff --git a/src/printer.js b/src/printer.js
index 7399a9418..fb719b99e 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1156,7 +1156,7 @@ function genericPrintNoParens(path, options, print) {
} else if (n.variance === "minus") {
key = concat([ "-", key ]);
}
- }
+ }
parts.push(key);
@@ -2049,12 +2049,19 @@ function printJSXElement(path, options, print) {
var mostChildren = children.slice(0, -1);
var closingLines = path.call(print, "closingElement");
- elem = concat([
+
+ const firstChild = children[0];
+ const lastChild = util.getLast(children);
+ const beginBreak = firstChild && firstChild.type === "line";
+ const endBreak = lastChild && lastChild.type === "line";
+
+ elem = multilineGroup(concat([
openingLines,
- indent(options.tabWidth, concat(mostChildren)),
- util.getLast(children) || "",
- closingLines
- ]);
+ indent(options.tabWidth, concat([ beginBreak ? "" : softline ].concat(mostChildren))),
+ lastChild || "",
+ endBreak ? "" : softline,
+ closingLines,
+ ]));
}
const parent = path.getParentNode();
diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
index 446860d16..2c6174281 100644
--- a/tests/prettier/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
@@ -70,10 +70,9 @@ const comp3 = (
);
const comp4 = (
-
Create wrapping parens and indent all the things.
+
+ Create wrapping parens and indent all the things.
+
);
const comp5 = Keep it on one line.
;
@@ -157,6 +156,15 @@ const render4 = ({ styles }) => Create wra
const render5 = ({ styles }) =>
Keep it on one line.
;
+const render6 = ({ styles }) => (
+
+
ddd d dd d d dddd dddd hello
+
ddd d dd d d dddd dddd hello
+
+
ddd d dd d d dddd dddd hello
hello
+
+)
+
const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const render1 = ({ styles }) => (
@@ -176,14 +184,49 @@ const render3 = ({ styles }) => (
);
const render4 = ({ styles }) => (
-
Create wrapping parens and indent all the things.
+
+ Create wrapping parens and indent all the things.
+
);
const render5 = ({ styles }) =>
Keep it on one line.
;
+const render6 = ({ styles }) => (
+
+
+ ddd d dd d d dddd dddd hello
+
+
+ ddd d dd d d dddd dddd hello
+
+
+
+ ddd d dd d d dddd dddd hello
+
hello
+
+
+);
+
const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) =>
this
.someLongCallWithParams(aaaaaa, bbbbbbb)
diff --git a/tests/prettier/jsx-stateless-arrow-fn.js b/tests/prettier/jsx-stateless-arrow-fn.js
index 859c0aeef..893074582 100644
--- a/tests/prettier/jsx-stateless-arrow-fn.js
+++ b/tests/prettier/jsx-stateless-arrow-fn.js
@@ -14,4 +14,13 @@ const render4 = ({ styles }) =>
Create wrapp
const render5 = ({ styles }) =>
Keep it on one line.
;
+const render6 = ({ styles }) => (
+
+
ddd d dd d d dddd dddd hello
+
ddd d dd d d dddd dddd hello
+
+
ddd d dd d d dddd dddd hello
hello
+
+)
+
const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd)