diff --git a/src/printer.js b/src/printer.js index 79d12736f..5ec67505b 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2177,14 +2177,23 @@ function genericPrintNoParens(path, options, print, args) { case "IntersectionTypeAnnotation": { const types = path.map(print, "types"); const result = []; + let wasIndented = false; for (let i = 0; i < types.length; ++i) { if (i === 0) { result.push(types[i]); + } else if (isObjectType(n.types[i - 1]) && isObjectType(n.types[i])) { + // If both are objects, don't indent + result.push( + concat([" & ", wasIndented ? indent(types[i]) : types[i]]) + ); } else if (!isObjectType(n.types[i - 1]) && !isObjectType(n.types[i])) { // If no object is involved, go to the next line if it breaks result.push(indent(concat([" &", line, types[i]]))); } else { // If you go from object to non-object or vis-versa, then inline it + if (i > 1) { + wasIndented = true; + } result.push(" & ", i > 1 ? indent(types[i]) : types[i]); } } diff --git a/tests/intersection/__snapshots__/jsfmt.spec.js.snap b/tests/intersection/__snapshots__/jsfmt.spec.js.snap index 0971a5cbb..00fd4ad76 100644 --- a/tests/intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/intersection/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,16 @@ exports[`intersection.js 1`] = ` export type ReallyBigSocketServer = ReallyBigSocketServerInterface & ReallyBigSocketServerStatics; +type Props = { + propA: X +} & { + propB: X +} & { + propC: X +} & { + propD: X +}; + type Props = { focusedChildren?: React.Children, onClick: () => void, @@ -42,6 +52,16 @@ type DuplexStreamOptions = ReadableStreamOptions & export type ReallyBigSocketServer = ReallyBigSocketServerInterface & ReallyBigSocketServerStatics; +type Props = { + propA: X +} & { + propB: X +} & { + propC: X +} & { + propD: X +}; + type Props = { focusedChildren?: React.Children, onClick: () => void, diff --git a/tests/intersection/intersection.js b/tests/intersection/intersection.js index fbd7a22e6..fe7d0e18c 100644 --- a/tests/intersection/intersection.js +++ b/tests/intersection/intersection.js @@ -1,5 +1,15 @@ export type ReallyBigSocketServer = ReallyBigSocketServerInterface & ReallyBigSocketServerStatics; +type Props = { + propA: X +} & { + propB: X +} & { + propC: X +} & { + propD: X +}; + type Props = { focusedChildren?: React.Children, onClick: () => void,