Merge pull request #83 from gabelevi/flow
Small fix for parsing type parameter declarations
This commit is contained in:
commit
c9a7bed6d0
@ -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;
|
||||
|
||||
@ -19,3 +19,4 @@ interface A<T = string> {}
|
||||
interface A<T: ?string = string> {}
|
||||
interface A<S, T: ?string = string> {}
|
||||
interface A<S = number, T: ?string = string> {}
|
||||
type A<T = void> = T
|
||||
|
||||
@ -1,29 +1,29 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 743,
|
||||
"end": 764,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 21,
|
||||
"column": 47
|
||||
"line": 22,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 743,
|
||||
"end": 764,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 21,
|
||||
"column": 47
|
||||
"line": 22,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
@ -3122,6 +3122,117 @@
|
||||
"properties": [],
|
||||
"indexers": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TypeAlias",
|
||||
"start": 744,
|
||||
"end": 764,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 749,
|
||||
"end": 750,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 6
|
||||
}
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start": 750,
|
||||
"end": 760,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "TypeParameter",
|
||||
"start": 751,
|
||||
"end": 759,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"name": "T",
|
||||
"default": {
|
||||
"type": "VoidTypeAnnotation",
|
||||
"start": 755,
|
||||
"end": 759,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 15
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"right": {
|
||||
"type": "GenericTypeAnnotation",
|
||||
"start": 763,
|
||||
"end": 764,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"typeParameters": null,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 763,
|
||||
"end": 764,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 22,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 22,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"name": "T"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user