From 8434f89bc040897e1fa8f098dad0f5e236961ca8 Mon Sep 17 00:00:00 2001 From: Conrad Buck Date: Thu, 20 Apr 2017 08:59:45 -0700 Subject: [PATCH] Add support for object type spread (#5525) * Add support for object type spread * Type spread: remove variance and add stripping test --- packages/babel-generator/src/generators/flow.js | 5 +++++ .../test/fixtures/flow/object-literal-types/actual.js | 7 +++++++ .../test/fixtures/flow/object-literal-types/expected.js | 7 +++++++ .../fixtures/strip-types/strip-type-annotations/actual.js | 1 + .../strip-types/strip-type-annotations/expected.js | 1 + packages/babel-types/src/definitions/flow.js | 8 ++++++++ 6 files changed, 29 insertions(+) create mode 100644 packages/babel-generator/test/fixtures/flow/object-literal-types/actual.js create mode 100644 packages/babel-generator/test/fixtures/flow/object-literal-types/expected.js diff --git a/packages/babel-generator/src/generators/flow.js b/packages/babel-generator/src/generators/flow.js index 279502b928..4fc45faeda 100644 --- a/packages/babel-generator/src/generators/flow.js +++ b/packages/babel-generator/src/generators/flow.js @@ -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("."); diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types/actual.js b/packages/babel-generator/test/fixtures/flow/object-literal-types/actual.js new file mode 100644 index 0000000000..80d29c99ee --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types/actual.js @@ -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, }}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types/expected.js b/packages/babel-generator/test/fixtures/flow/object-literal-types/expected.js new file mode 100644 index 0000000000..fbb4871061 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types/expected.js @@ -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 } }; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js index f602db2cbc..3d96731ccf 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js @@ -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): void }; var a: { id(x: T): T; }; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js index a6c982a6a3..adec467fc7 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js @@ -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 {}; diff --git a/packages/babel-types/src/definitions/flow.js b/packages/babel-types/src/definitions/flow.js index 75388fb4a3..3781435e26 100644 --- a/packages/babel-types/src/definitions/flow.js +++ b/packages/babel-types/src/definitions/flow.js @@ -308,6 +308,14 @@ defineType("ObjectTypeProperty", { }, }); +defineType("ObjectTypeSpreadProperty", { + visitor: ["argument"], + aliases: ["Flow", "UserWhitespacable"], + fields: { + // todo + }, +}); + defineType("QualifiedTypeIdentifier", { visitor: ["id", "qualification"], aliases: ["Flow"],