Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printer for explicitly inexact Flow types #10041

Merged
merged 1 commit into from May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
...
};