Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variance node type and generate property variance annotations #4697

Merged
merged 4 commits into from Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-generator/src/generators/classes.js
Expand Up @@ -60,6 +60,7 @@ export function ClassProperty(node: Object) {
this.print(node.key, node);
this.token("]");
} else {
this._variance(node);
this.print(node.key, node);
}
this.print(node.typeAnnotation, node);
Expand Down
16 changes: 11 additions & 5 deletions packages/babel-generator/src/generators/flow.js
Expand Up @@ -147,6 +147,14 @@ export function _interfaceish(node: Object) {
this.print(node.body, node);
}

export function _variance(node) {
if (node.variance === "plus") {
this.token("+");
} else if (node.variance === "minus") {
this.token("-");
}
}

export function InterfaceDeclaration(node: Object) {
this.word("interface");
this.space();
Expand Down Expand Up @@ -221,11 +229,7 @@ export function TypeAnnotation(node: Object) {
}

export function TypeParameter(node: Object) {
if (node.variance === "plus") {
this.token("+");
} else if (node.variance === "minus") {
this.token("-");
}
this._variance(node);

this.word(node.name);

Expand Down Expand Up @@ -295,6 +299,7 @@ export function ObjectTypeIndexer(node: Object) {
this.word("static");
this.space();
}
this._variance(node);
this.token("[");
this.print(node.id, node);
this.token(":");
Expand All @@ -311,6 +316,7 @@ export function ObjectTypeProperty(node: Object) {
this.word("static");
this.space();
}
this._variance(node);
this.print(node.key, node);
if (node.optional) this.token("?");
this.token(":");
Expand Down
@@ -1,3 +1,17 @@
class C<+T, -U> {}
class C1<+T, -U> {}
function f<+T, -U>() {}
type T<+T, -U> = {};
type T = { +p: T };
type T = { -p: T };
type T = { +[k:K]: V };
type T = { -[k:K]: V };
interface I { +p: T };
interface I { -p: T };
interface I { +[k:K]: V };
interface I { -[k:K]: V };
declare class I { +p: T };
declare class I { -p: T };
declare class I { +[k:K]: V };
declare class I { -[k:K]: V };
class C2 { +p: T = e };
class C3 { -p: T = e };
@@ -1,3 +1,21 @@
class C<+T, -U> {}
class C1<+T, -U> {}
function f<+T, -U>() {}
type T<+T, -U> = {};
type T = { +p: T };
type T = { -p: T };
type T = { +[k: K]: V };
type T = { -[k: K]: V };
interface I { +p: T };
interface I { -p: T };
interface I { +[k: K]: V };
interface I { -[k: K]: V };
declare class I { +p: T };
declare class I { -p: T };
declare class I { +[k: K]: V };
declare class I { -[k: K]: V };
class C2 {
+p: T = e;
};
class C3 {
-p: T = e;
};
@@ -1,3 +1,17 @@
class C<+T, -U> {}
class C1<+T, -U> {}
function f<+T, -U>() {}
type T<+T, -U> = {};
type T<+T, -U> = {}
type T = { +p: T }
type T = { -p: T }
type T = { +[k:K]: V }
type T = { -[k:K]: V }
interface I { +p: T }
interface I { -p: T }
interface I { +[k:K]: V }
interface I { -[k:K]: V }
declare class I { +p: T }
declare class I { -p: T }
declare class I { +[k:K]: V }
declare class I { -[k:K]: V }
class C2 { +p: T }
class C3 { -p: T }
@@ -1,2 +1,5 @@
class C {}
class C1 {}
function f() {}

class C2 {}
class C3 {}