Merge pull request #3520 from babel/babylon-update

Support changes in flow parsing
This commit is contained in:
Henry Zhu 2016-06-11 00:00:36 -04:00 committed by GitHub
commit 0dc1a69017
5 changed files with 77 additions and 4 deletions

View File

@ -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, {

View File

@ -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);

View 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> {};

View 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> {};

View File

@ -233,6 +233,14 @@ defineType("TypeCastExpression", {
}
});
defineType("TypeParameter", {
visitor: ["name", "bound"],
aliases: ["Flow"],
fields: {
// todo
}
});
defineType("TypeParameterDeclaration", {
visitor: ["params"],
aliases: ["Flow"],