Add support for Flow def-site variance syntax
This syntax allows you to specify whether a type variable can appear in a covariant or contravariant position, and is super useful for, say, Promise. Right now this is hacked in jankily, but in the next major release we should stop using Identifier nodes for type parameters.
This commit is contained in:
@@ -624,9 +624,23 @@ pp.flowParseTypeAnnotation = function () {
|
||||
};
|
||||
|
||||
pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOptionalParam) {
|
||||
let variance;
|
||||
if (this.match(tt.plusMin)) {
|
||||
if (this.state.value === "+") {
|
||||
variance = "plus";
|
||||
} else if (this.state.value === "-") {
|
||||
variance = "minus";
|
||||
}
|
||||
this.eat(tt.plusMin);
|
||||
}
|
||||
|
||||
let ident = this.parseIdentifier();
|
||||
let isOptionalParam = false;
|
||||
|
||||
if (variance) {
|
||||
ident.variance = variance;
|
||||
}
|
||||
|
||||
if (canBeOptionalParam && this.eat(tt.question)) {
|
||||
this.expect(tt.question);
|
||||
isOptionalParam = true;
|
||||
|
||||
Reference in New Issue
Block a user