Skip to content

Commit

Permalink
Allow function types in type params within arrow return types (#8954)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored and existentialism committed Nov 1, 2018
1 parent e85faec commit cd81b07
Show file tree
Hide file tree
Showing 5 changed files with 439 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -638,12 +638,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.state.inType = true;

this.expectRelational("<");
const oldNoAnonFunctionType = this.state.noAnonFunctionType;
this.state.noAnonFunctionType = false;
while (!this.isRelational(">")) {
node.params.push(this.flowParseType());
if (!this.isRelational(">")) {
this.expect(tt.comma);
}
}
this.state.noAnonFunctionType = oldNoAnonFunctionType;
this.expectRelational(">");

this.state.inType = oldInType;
Expand Down
@@ -0,0 +1 @@
type T = Array<(string) => number>
@@ -0,0 +1,183 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "TypeAlias",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"id": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "T"
},
"name": "T"
},
"typeParameters": null,
"right": {
"type": "GenericTypeAnnotation",
"start": 9,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 34
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 14,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 34
}
},
"params": [
{
"type": "FunctionTypeAnnotation",
"start": 15,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 33
}
},
"params": [
{
"type": "FunctionTypeParam",
"start": 16,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 22
}
},
"name": null,
"optional": false,
"typeAnnotation": {
"type": "StringTypeAnnotation",
"start": 16,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 22
}
}
}
}
],
"rest": null,
"returnType": {
"type": "NumberTypeAnnotation",
"start": 27,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 27
},
"end": {
"line": 1,
"column": 33
}
}
},
"typeParameters": null
}
]
},
"id": {
"type": "Identifier",
"start": 9,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 14
},
"identifierName": "Array"
},
"name": "Array"
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
let x = (): Array<(string) => number> => []

0 comments on commit cd81b07

Please sign in to comment.