Fix empty line with flow union (#1511)

This commit is contained in:
Brian Ng authored and Christopher Chedeau committed 2017-05-04 19:06:30 -07:00
1 parent 1a1e6fc1dd
commit ccf509abb6
3 files changed
+37 -4

No files matched your search

+7 -4
View File
@@ -748,9 +748,9 @@ function genericPrintNoParens(path, options, print, args) {
case "TSInterfaceDeclaration":
case "TSTypeLiteral": {
var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
var isTypeScriptTypeAnnotaion = n.type === "TSTypeLiteral";
var isTypeScriptTypeAnnotation = n.type === "TSTypeLiteral";
var isTypeScriptInterfaceDeclaration = n.type === "TSInterfaceDeclaration";
var isTypeScriptType = isTypeScriptTypeAnnotaion || isTypeScriptInterfaceDeclaration;
var isTypeScriptType = isTypeScriptTypeAnnotation || isTypeScriptInterfaceDeclaration;
// Leave this here because we *might* want to make this
// configurable later -- flow accepts ";" for type separators,
// typescript accepts ";" and newlines
@@ -1903,8 +1903,11 @@ function genericPrintNoParens(path, options, print, args) {
const parent = path.getParentNode();
// If there's a leading comment, the parent is doing the indentation
const shouldIndent = !(parent.type === "TypeAlias" &&
hasLeadingOwnLineComment(options.originalText, n));
const shouldIndent = (
parent.type !== "TypeParameterInstantiation" &&
!(parent.type === "TypeAlias" &&
hasLeadingOwnLineComment(options.originalText, n))
);
//const token = isIntersection ? "&" : "|";
const code = concat([
@@ -137,3 +137,29 @@ type State = {
};
`;
exports[`union.js 1`] = `
type Foo = Promise<
{ ok: true, bar: string, baz: SomeOtherLongType } |
{ ok: false, bar: SomeOtherLongType }
>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }
>;
`;
exports[`union.js 2`] = `
type Foo = Promise<
{ ok: true, bar: string, baz: SomeOtherLongType } |
{ ok: false, bar: SomeOtherLongType }
>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType },
>;
`;
+4
View File
@@ -0,0 +1,4 @@
type Foo = Promise<
{ ok: true, bar: string, baz: SomeOtherLongType } |
{ ok: false, bar: SomeOtherLongType }
>;