Port flow object spread from #418 to 6.x (#5653)

* Add support for object type spread

* Type spread: remove variance and add stripping test

* Fix tests
This commit is contained in:
Sebastian McKenzie 2017-04-26 22:16:38 +01:00 committed by Henry Zhu
parent a1a795321a
commit 60adcd68a0
6 changed files with 29 additions and 0 deletions

View File

@ -333,6 +333,11 @@ export function ObjectTypeProperty(node: Object) {
this.print(node.value, node);
}
export function ObjectTypeSpreadProperty(node: Object) {
this.token("...");
this.print(node.argument, node);
}
export function QualifiedTypeIdentifier(node: Object) {
this.print(node.qualification, node);
this.token(".");

View File

@ -0,0 +1,7 @@
type U = {};
type V = {};
type T = { ...U, };
type T = { ...U, ...V };
type T = { p: V, ...U };
type T = { ...U, p: V, };
type T = { ...{}|{ p: V, }};

View File

@ -0,0 +1,7 @@
type U = {};
type V = {};
type T = { ...U };
type T = { ...U; ...V; };
type T = { p: V; ...U; };
type T = { ...U; p: V; };
type T = { ...{} | { p: V } };

View File

@ -44,6 +44,7 @@ var a: { subObj: {strVal: string} }
var a: { subObj: ?{strVal: string} }
var a: { param1: number; param2: string }
var a: { param1: number; param2?: string }
var a: { ...any; ...{}|{p: void} };
var a: { [a: number]: string; [b: number]: string; };
var a: { add(x: number, ...y: Array<string>): void };
var a: { id<T>(x: T): T; };

View File

@ -47,6 +47,7 @@ var a;
var a;
var a;
var a;
var a;
var a = [1, 2, 3];
a = class Foo {};
a = class Foo extends Bar {};

View File

@ -308,6 +308,14 @@ defineType("ObjectTypeProperty", {
}
});
defineType("ObjectTypeSpreadProperty", {
visitor: ["argument"],
aliases: ["Flow", "UserWhitespacable"],
fields: {
// todo
},
});
defineType("QualifiedTypeIdentifier", {
visitor: ["id", "qualification"],
aliases: ["Flow"],