Fix indentation of intersection object types (#3074)
parent
12f028cd46
commit
465729685f
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue