From 3524ad510f9927b99399c7feadb7bdfd97333bb6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 22 Jun 2016 13:43:32 +0100 Subject: [PATCH] remove grouped type arrow restriction as it seems flow no longer has it - fixes #44 --- src/plugins/flow.js | 14 - .../existential-type-param-2/actual.js | 1 + .../existential-type-param-2/expected.json | 260 ++++++++++++++++++ 3 files changed, 261 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/flow/type-annotations/existential-type-param-2/actual.js create mode 100644 test/fixtures/flow/type-annotations/existential-type-param-2/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 23aa49e175..9d0279ae99 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -517,20 +517,6 @@ pp.flowParsePrimaryType = function () { if (isGroupedType) { type = this.flowParseType(); this.expect(tt.parenR); - - // If we see a => next then someone was probably confused about - // function types, so we can provide a better error message - if (this.eat(tt.arrow)) { - this.raise(node, - "Unexpected token =>. It looks like " + - "you are trying to write a function type, but you ended up " + - "writing a grouped type followed by an =>, which is a syntax " + - "error. Remember, function type parameters are named so function " + - "types look like (name1: type1, name2: type2) => returnType. You " + - "probably wrote (type1) => returnType" - ); - } - return type; } diff --git a/test/fixtures/flow/type-annotations/existential-type-param-2/actual.js b/test/fixtures/flow/type-annotations/existential-type-param-2/actual.js new file mode 100644 index 0000000000..a97ae6fc54 --- /dev/null +++ b/test/fixtures/flow/type-annotations/existential-type-param-2/actual.js @@ -0,0 +1 @@ +let f : * = (x : null | *) : (*) => {} diff --git a/test/fixtures/flow/type-annotations/existential-type-param-2/expected.json b/test/fixtures/flow/type-annotations/existential-type-param-2/expected.json new file mode 100644 index 0000000000..c9047516f4 --- /dev/null +++ b/test/fixtures/flow/type-annotations/existential-type-param-2/expected.json @@ -0,0 +1,260 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "f", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "typeAnnotation": { + "type": "ExistentialTypeParam", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "typeAnnotation": { + "type": "ExistentialTypeParam", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + } + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "typeAnnotation": { + "type": "UnionTypeAnnotation", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "types": [ + { + "type": "NullLiteralTypeAnnotation", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "value": true + }, + { + "type": "ExistentialTypeParam", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + } + ] + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file