Merge pull request #83 from gabelevi/flow

Small fix for parsing type parameter declarations
This commit is contained in:
Sebastian McKenzie
2016-08-04 00:37:37 +10:00
committed by GitHub
3 changed files with 123 additions and 12 deletions

View File

@@ -229,9 +229,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 {
@@ -246,6 +249,8 @@ pp.flowParseTypeParameterDeclaration = function () {
} while (!this.isRelational(">"));
this.expectRelational(">");
this.state.inType = oldInType;
return this.finishNode(node, "TypeParameterDeclaration");
};
@@ -1041,12 +1046,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);
};
});
@@ -1114,10 +1116,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;