Skip to content

Commit

Permalink
Fix handling of anonymous parameters in `flowParseObjectTypeMethodish…
Browse files Browse the repository at this point in the history
…`. (babel#526) (babel#528)

By analogy with `flowParseFunctionTypeParams` (cf. commit 407c97c).
  • Loading branch information
danez committed May 19, 2017
1 parent 54399ab commit b7c13a8
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/flow.js
Expand Up @@ -365,7 +365,7 @@ pp.flowParseObjectTypeMethodish = function (node) {
}

this.expect(tt.parenL);
while (this.match(tt.name)) {
while (!this.match(tt.parenR) && !this.match(tt.ellipsis)) {
node.params.push(this.flowParseFunctionTypeParam());
if (!this.match(tt.parenR)) {
this.expect(tt.comma);
Expand Down
@@ -0,0 +1 @@
type o = { m(|int|bool): void }
237 changes: 237 additions & 0 deletions test/fixtures/flow/object-types/complex-param-types/expected.json
@@ -0,0 +1,237 @@
{
"type": "File",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"program": {
"type": "Program",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"sourceType": "module",
"body": [
{
"type": "TypeAlias",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"id": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "o"
},
"name": "o"
},
"typeParameters": null,
"right": {
"type": "ObjectTypeAnnotation",
"start": 9,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 31
}
},
"callProperties": [],
"properties": [
{
"type": "ObjectTypeProperty",
"start": 11,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 29
}
},
"value": {
"type": "FunctionTypeAnnotation",
"start": 11,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 29
}
},
"params": [
{
"type": "FunctionTypeParam",
"start": 13,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 22
}
},
"name": null,
"optional": false,
"typeAnnotation": {
"type": "UnionTypeAnnotation",
"start": 13,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 22
}
},
"types": [
{
"type": "GenericTypeAnnotation",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "int"
},
"name": "int"
}
},
{
"type": "BooleanTypeAnnotation",
"start": 18,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 22
}
}
}
]
}
}
],
"rest": null,
"typeParameters": null,
"returnType": {
"type": "VoidTypeAnnotation",
"start": 25,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 29
}
}
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "m"
},
"name": "m"
},
"optional": false
}
],
"indexers": [],
"exact": false
}
}
],
"directives": []
}
}

0 comments on commit b7c13a8

Please sign in to comment.