Fix printer for explicitly inexact Flow types (#10041)

Closes: https://github.com/babel/babel/issues/10040
This commit is contained in:
Martin Zlámal 2019-05-29 14:17:12 -05:00 committed by Nicolò Ribaudo
parent 8d492b159b
commit ce4c374924
6 changed files with 42 additions and 2 deletions

View File

@ -409,7 +409,7 @@ export function ObjectTypeAnnotation(node: Object) {
indent: true,
statement: true,
iterator: () => {
if (props.length !== 1) {
if (props.length !== 1 || node.inexact) {
this.token(",");
this.space();
}
@ -419,6 +419,15 @@ export function ObjectTypeAnnotation(node: Object) {
this.space();
}
if (node.inexact) {
this.indent();
this.token("...");
if (props.length) {
this.newline();
}
this.dedent();
}
if (node.exact) {
this.token("|}");
} else {

View File

@ -0,0 +1,4 @@
type T1 = { ... };
type T2 = { a: { b: { c: {...}, ... }, ... } }
type T3 = { foo: number, ... };
type T4 = { foo: number, bar: string, ... };

View File

@ -0,0 +1,3 @@
{
"compact": true
}

View File

@ -0,0 +1 @@
type T1={...};type T2={a:{b:{c:{...},...},...}};type T3={foo:number,...};type T4={foo:number,bar:string,...};

View File

@ -9,3 +9,7 @@ type T6 = { foo(): number }
type T7 = { foo: () => number }
type T8 = { [string]: U };
type T9 = { [param: string]: U };
type T10 = { ... };
type T11 = { a: { b: { c: {...}, ... }, ... } }
type T12 = { foo: number, ... };
type T13 = { foo: number, bar: string, ... };

View File

@ -27,4 +27,23 @@ type T8 = {
};
type T9 = {
[param: string]: U
};
};
type T10 = {...};
type T11 = {
a: {
b: {
c: {...},
...
},
...
}
};
type T12 = {
foo: number,
...
};
type T13 = {
foo: number,
bar: string,
...
};