Small fix for parsing type parameter declarations

This commit is contained in:
Gabe Levi
2016-07-29 12:45:20 -04:00
parent 4811d617ce
commit 859ed04be9
3 changed files with 123 additions and 12 deletions

View File

@@ -230,9 +230,12 @@ pp.flowParseTypeParameter = function () {
};
pp.flowParseTypeParameterDeclaration = function () {
const oldInType = this.state.inType;
let node = this.startNode();
node.params = [];
this.state.inType = true;
if (this.isRelational("<") || this.match(tt.jsxTagStart)) {
this.next();
} else {
@@ -247,6 +250,8 @@ pp.flowParseTypeParameterDeclaration = function () {
} while (!this.isRelational(">"));
this.expectRelational(">");
this.state.inType = oldInType;
return this.finishNode(node, "TypeParameterDeclaration");
};
@@ -1042,12 +1047,9 @@ export default function (instance) {
// parse function type parameters - function foo<T>() {}
instance.extend("parseFunctionParams", function (inner) {
return function (node) {
const oldInType = this.state.inType;
this.state.inType = true;
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
}
this.state.inType = oldInType;
inner.call(this, node);
};
});
@@ -1115,10 +1117,7 @@ export default function (instance) {
let arrowExpression;
let typeParameters;
try {
const oldInType = this.state.inType;
this.state.inType = true;
typeParameters = this.flowParseTypeParameterDeclaration();
this.state.inType = oldInType;
arrowExpression = inner.apply(this, args);
arrowExpression.typeParameters = typeParameters;