From 03b3b39b17af9ebc3bf7e1963dea4f22cdc582d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 28 Jun 2017 16:17:51 +0200 Subject: [PATCH] Allow jsx to be the body of a typed arrow function (#595) Fixes #593 --- src/plugins/flow.js | 3 +- .../flow/regression/issue-593/actual.js | 1 + .../flow/regression/issue-593/expected.json | 203 ++++++++++++++++++ 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/flow/regression/issue-593/actual.js create mode 100644 test/fixtures/flow/regression/issue-593/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 164ea6ae41..7da0bf784e 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -958,7 +958,8 @@ export default (superClass: Class): Class => class extends super this.state.inType = true; const type = this.flowParseUnionType(); this.state.inType = oldInType; - this.state.exprAllowed = false; + // noAnonFunctionType is true when parsing an arrow function + this.state.exprAllowed = this.state.noAnonFunctionType; return type; } diff --git a/test/fixtures/flow/regression/issue-593/actual.js b/test/fixtures/flow/regression/issue-593/actual.js new file mode 100644 index 0000000000..84266324b1 --- /dev/null +++ b/test/fixtures/flow/regression/issue-593/actual.js @@ -0,0 +1 @@ +const fail = (): X => ; \ No newline at end of file diff --git a/test/fixtures/flow/regression/issue-593/expected.json b/test/fixtures/flow/regression/issue-593/expected.json new file mode 100644 index 0000000000..03be1e5167 --- /dev/null +++ b/test/fixtures/flow/regression/issue-593/expected.json @@ -0,0 +1,203 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "fail" + }, + "name": "fail" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 13, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "predicate": null, + "returnType": { + "type": "TypeAnnotation", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "X" + }, + "name": "X" + } + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "JSXElement", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "x" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file