Merge pull request #3520 from babel/babylon-update
Support changes in flow parsing
This commit is contained in:
commit
0dc1a69017
@ -187,6 +187,27 @@ export function TypeAnnotation(node: Object) {
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
|
||||
export function TypeParameter(node: Object) {
|
||||
if (node.variance === "plus") {
|
||||
this.push("+");
|
||||
} else if (node.variance === "minus") {
|
||||
this.push("-");
|
||||
}
|
||||
|
||||
this.push(node.name);
|
||||
|
||||
if (node.bound) {
|
||||
this.print(node.bound, node);
|
||||
}
|
||||
|
||||
if (node.default) {
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
this.print(node.default, node);
|
||||
}
|
||||
}
|
||||
|
||||
export function TypeParameterInstantiation(node: Object) {
|
||||
this.push("<");
|
||||
this.printJoin(node.params, node, {
|
||||
|
||||
@ -8,10 +8,12 @@ export function Identifier(node: Object) {
|
||||
// This is a terrible hack, but changing type annotations to use a new,
|
||||
// dedicated node would be a breaking change. This should be cleaned up in
|
||||
// the next major.
|
||||
if (node.variance === "plus") {
|
||||
this.push("+");
|
||||
} else if (node.variance === "minus") {
|
||||
this.push("-");
|
||||
if (node.variance) {
|
||||
if (node.variance === "plus") {
|
||||
this.push("+");
|
||||
} else if (node.variance === "minus") {
|
||||
this.push("-");
|
||||
}
|
||||
}
|
||||
|
||||
this.push(node.name);
|
||||
|
||||
21
packages/babel-generator/test/fixtures/flow/type-parameters/actual.js
vendored
Normal file
21
packages/babel-generator/test/fixtures/flow/type-parameters/actual.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
type A<T = string> = T;
|
||||
type A<T = *> = T;
|
||||
type A<T: ?string = string> = T;
|
||||
type A<S, T: ?string = string> = T;
|
||||
type A<S = number, T: ?string = string> = T;
|
||||
class A<T = string> {};
|
||||
class A<T: ?string = string> {};
|
||||
class A<S, T: ?string = string> {};
|
||||
class A<S = number, T: ?string = string> {};
|
||||
(class A<T = string> {});
|
||||
(class A<T: ?string = string> {});
|
||||
(class A<S, T: ?string = string> {});
|
||||
(class A<S = number, T: ?string = string> {});
|
||||
declare class A<T = string> {};
|
||||
declare class A<T: ?string = string> {};
|
||||
declare class A<S, T: ?string = string> {};
|
||||
declare class A<S = number, T: ?string = string> {};
|
||||
interface A<T = string> {};
|
||||
interface A<T: ?string = string> {};
|
||||
interface A<S, T: ?string = string> {};
|
||||
interface A<S = number, T: ?string = string> {};
|
||||
21
packages/babel-generator/test/fixtures/flow/type-parameters/expected.js
vendored
Normal file
21
packages/babel-generator/test/fixtures/flow/type-parameters/expected.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
type A<T = string> = T;
|
||||
type A<T = *> = T;
|
||||
type A<T: ?string = string> = T;
|
||||
type A<S, T: ?string = string> = T;
|
||||
type A<S = number, T: ?string = string> = T;
|
||||
class A<T = string> {};
|
||||
class A<T: ?string = string> {};
|
||||
class A<S, T: ?string = string> {};
|
||||
class A<S = number, T: ?string = string> {};
|
||||
(class A<T = string> {});
|
||||
(class A<T: ?string = string> {});
|
||||
(class A<S, T: ?string = string> {});
|
||||
(class A<S = number, T: ?string = string> {});
|
||||
declare class A<T = string> {};
|
||||
declare class A<T: ?string = string> {};
|
||||
declare class A<S, T: ?string = string> {};
|
||||
declare class A<S = number, T: ?string = string> {};
|
||||
interface A<T = string> {};
|
||||
interface A<T: ?string = string> {};
|
||||
interface A<S, T: ?string = string> {};
|
||||
interface A<S = number, T: ?string = string> {};
|
||||
@ -233,6 +233,14 @@ defineType("TypeCastExpression", {
|
||||
}
|
||||
});
|
||||
|
||||
defineType("TypeParameter", {
|
||||
visitor: ["name", "bound"],
|
||||
aliases: ["Flow"],
|
||||
fields: {
|
||||
// todo
|
||||
}
|
||||
});
|
||||
|
||||
defineType("TypeParameterDeclaration", {
|
||||
visitor: ["params"],
|
||||
aliases: ["Flow"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user