Skip to content

Commit

Permalink
Add support for object type spread (#5525)
Browse files Browse the repository at this point in the history
* Add support for object type spread

* Type spread: remove variance and add stripping test
  • Loading branch information
conartist6 authored and hzoo committed Apr 20, 2017
1 parent 14ed031 commit 8434f89
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-generator/src/generators/flow.js
Expand Up @@ -331,6 +331,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(".");
Expand Down
@@ -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, }};
@@ -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 } };
Expand Up @@ -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; };
Expand Down
Expand Up @@ -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 {};
Expand Down
8 changes: 8 additions & 0 deletions packages/babel-types/src/definitions/flow.js
Expand Up @@ -308,6 +308,14 @@ defineType("ObjectTypeProperty", {
},
});

defineType("ObjectTypeSpreadProperty", {
visitor: ["argument"],
aliases: ["Flow", "UserWhitespacable"],
fields: {
// todo
},
});

defineType("QualifiedTypeIdentifier", {
visitor: ["id", "qualification"],
aliases: ["Flow"],
Expand Down

0 comments on commit 8434f89

Please sign in to comment.