From 49948b76bdcc606c414c956626dcf9253a25e569 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Wed, 17 May 2017 04:53:14 +0800 Subject: [PATCH] Fix handling of anonymous parameters in `flowParseObjectTypeMethodish`. (#526) By analogy with `flowParseFunctionTypeParams` (cf. commit 407c97c9c2fe453fc2ae940c3d3b11c90d9dbc8e). --- src/plugins/flow.js | 2 +- .../complex-param-types/actual.js | 1 + .../complex-param-types/expected.json | 237 ++++++++++++++++++ 3 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/flow/object-types/complex-param-types/actual.js create mode 100644 test/fixtures/flow/object-types/complex-param-types/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index eac336b2d2..fe6aa0a2ff 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -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); diff --git a/test/fixtures/flow/object-types/complex-param-types/actual.js b/test/fixtures/flow/object-types/complex-param-types/actual.js new file mode 100644 index 0000000000..27fe4a3b5b --- /dev/null +++ b/test/fixtures/flow/object-types/complex-param-types/actual.js @@ -0,0 +1 @@ +type o = { m(|int|bool): void } diff --git a/test/fixtures/flow/object-types/complex-param-types/expected.json b/test/fixtures/flow/object-types/complex-param-types/expected.json new file mode 100644 index 0000000000..7f6e056851 --- /dev/null +++ b/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": [] + } +} \ No newline at end of file