Skip to content

Commit

Permalink
Fix printer for explicitly inexact Flow types (#10041)
Browse files Browse the repository at this point in the history
Closes: #10040
  • Loading branch information
Martin Zl谩mal authored and nicolo-ribaudo committed May 29, 2019
1 parent 8d492b1 commit ce4c374
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/babel-generator/src/generators/flow.js
Expand Up @@ -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();
}
Expand All @@ -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 {
Expand Down
@@ -0,0 +1,4 @@
type T1 = { ... };
type T2 = { a: { b: { c: {...}, ... }, ... } }
type T3 = { foo: number, ... };
type T4 = { foo: number, bar: string, ... };
@@ -0,0 +1,3 @@
{
"compact": true
}
@@ -0,0 +1 @@
type T1={...};type T2={a:{b:{c:{...},...},...}};type T3={foo:number,...};type T4={foo:number,bar:string,...};
Expand Up @@ -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, ... };
Expand Up @@ -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,
...
};

0 comments on commit ce4c374

Please sign in to comment.