Fix printer for explicitly inexact Flow types (#10041)
Closes: https://github.com/babel/babel/issues/10040
This commit is contained in:
parent
8d492b159b
commit
ce4c374924
@ -409,7 +409,7 @@ export function ObjectTypeAnnotation(node: Object) {
|
|||||||
indent: true,
|
indent: true,
|
||||||
statement: true,
|
statement: true,
|
||||||
iterator: () => {
|
iterator: () => {
|
||||||
if (props.length !== 1) {
|
if (props.length !== 1 || node.inexact) {
|
||||||
this.token(",");
|
this.token(",");
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
@ -419,6 +419,15 @@ export function ObjectTypeAnnotation(node: Object) {
|
|||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.inexact) {
|
||||||
|
this.indent();
|
||||||
|
this.token("...");
|
||||||
|
if (props.length) {
|
||||||
|
this.newline();
|
||||||
|
}
|
||||||
|
this.dedent();
|
||||||
|
}
|
||||||
|
|
||||||
if (node.exact) {
|
if (node.exact) {
|
||||||
this.token("|}");
|
this.token("|}");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
4
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/input.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/input.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
type T1 = { ... };
|
||||||
|
type T2 = { a: { b: { c: {...}, ... }, ... } }
|
||||||
|
type T3 = { foo: number, ... };
|
||||||
|
type T4 = { foo: number, bar: string, ... };
|
||||||
3
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"compact": true
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/flow/object-literal-types-compact/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
type T1={...};type T2={a:{b:{c:{...},...},...}};type T3={foo:number,...};type T4={foo:number,bar:string,...};
|
||||||
@ -9,3 +9,7 @@ type T6 = { foo(): number }
|
|||||||
type T7 = { foo: () => number }
|
type T7 = { foo: () => number }
|
||||||
type T8 = { [string]: U };
|
type T8 = { [string]: U };
|
||||||
type T9 = { [param: string]: U };
|
type T9 = { [param: string]: U };
|
||||||
|
type T10 = { ... };
|
||||||
|
type T11 = { a: { b: { c: {...}, ... }, ... } }
|
||||||
|
type T12 = { foo: number, ... };
|
||||||
|
type T13 = { foo: number, bar: string, ... };
|
||||||
|
|||||||
@ -28,3 +28,22 @@ type T8 = {
|
|||||||
type T9 = {
|
type T9 = {
|
||||||
[param: string]: U
|
[param: string]: U
|
||||||
};
|
};
|
||||||
|
type T10 = {...};
|
||||||
|
type T11 = {
|
||||||
|
a: {
|
||||||
|
b: {
|
||||||
|
c: {...},
|
||||||
|
...
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
};
|
||||||
|
type T12 = {
|
||||||
|
foo: number,
|
||||||
|
...
|
||||||
|
};
|
||||||
|
type T13 = {
|
||||||
|
foo: number,
|
||||||
|
bar: string,
|
||||||
|
...
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user