Fix closing parens on multi-line intersection/union type (#3436)
parent
3fa2229a62
commit
38c8286907
|
@ -2291,6 +2291,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
// | C
|
// | C
|
||||||
|
|
||||||
const parent = path.getParentNode();
|
const parent = path.getParentNode();
|
||||||
|
|
||||||
// If there's a leading comment, the parent is doing the indentation
|
// If there's a leading comment, the parent is doing the indentation
|
||||||
const shouldIndent =
|
const shouldIndent =
|
||||||
parent.type !== "TypeParameterInstantiation" &&
|
parent.type !== "TypeParameterInstantiation" &&
|
||||||
|
@ -2330,6 +2331,26 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
join(concat([line, "| "]), printed)
|
join(concat([line, "| "]), printed)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
let hasParens;
|
||||||
|
|
||||||
|
if (n.type === "TSUnionType") {
|
||||||
|
const greatGrandParent = path.getParentNode(2);
|
||||||
|
const greatGreatGrandParent = path.getParentNode(3);
|
||||||
|
|
||||||
|
hasParens =
|
||||||
|
greatGrandParent &&
|
||||||
|
greatGrandParent.type === "TSParenthesizedType" &&
|
||||||
|
greatGreatGrandParent &&
|
||||||
|
(greatGreatGrandParent.type === "TSUnionType" ||
|
||||||
|
greatGreatGrandParent.type === "TSIntersectionType");
|
||||||
|
} else {
|
||||||
|
hasParens = path.needsParens(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasParens) {
|
||||||
|
return group(concat([indent(code), softline]));
|
||||||
|
}
|
||||||
|
|
||||||
return group(shouldIndent ? indent(code) : code);
|
return group(shouldIndent ? indent(code) : code);
|
||||||
}
|
}
|
||||||
case "NullableTypeAnnotation":
|
case "NullableTypeAnnotation":
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`intersection.js 1`] = `
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any;
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO"; foo: any }
|
||||||
|
| { discriminant: "BAR"; bar: any }
|
||||||
|
| { discriminant: "BAZ"; baz: any }
|
||||||
|
);
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO", foo: any }
|
||||||
|
| { discriminant: "BAR", bar: any }
|
||||||
|
| { discriminant: "BAZ", baz: any }
|
||||||
|
);
|
||||||
|
|
||||||
|
`;
|
|
@ -0,0 +1,7 @@
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any;
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO"; foo: any }
|
||||||
|
| { discriminant: "BAR"; bar: any }
|
||||||
|
| { discriminant: "BAZ"; baz: any }
|
||||||
|
);
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, ["flow", "babylon"]);
|
|
@ -102,6 +102,14 @@ interface Interface {
|
||||||
i: (X | Y) & Z;
|
i: (X | Y) & Z;
|
||||||
j: Partial<(X | Y)>;
|
j: Partial<(X | Y)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any;
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO"; foo: any }
|
||||||
|
| { discriminant: "BAR"; bar: any }
|
||||||
|
| { discriminant: "BAZ"; baz: any }
|
||||||
|
);
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
export type A =
|
export type A =
|
||||||
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
@ -133,6 +141,13 @@ interface Interface {
|
||||||
j: Partial<X | Y>;
|
j: Partial<X | Y>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any;
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO"; foo: any }
|
||||||
|
| { discriminant: "BAR"; bar: any }
|
||||||
|
| { discriminant: "BAZ"; baz: any });
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`with-type-params.ts 1`] = `
|
exports[`with-type-params.ts 1`] = `
|
||||||
|
|
|
@ -30,3 +30,11 @@ interface Interface {
|
||||||
i: (X | Y) & Z;
|
i: (X | Y) & Z;
|
||||||
j: Partial<(X | Y)>;
|
j: Partial<(X | Y)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
sharedProperty: any;
|
||||||
|
} & (
|
||||||
|
| { discriminant: "FOO"; foo: any }
|
||||||
|
| { discriminant: "BAR"; bar: any }
|
||||||
|
| { discriminant: "BAZ"; baz: any }
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue