From d3a1813520f033282caa99a3df3904f4b71c17be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 15 Jun 2017 00:21:14 +0200 Subject: [PATCH] The { after a function generic type annotation is a statement This would have previously been interpreted as an expression, because usually after ">" there can't be a statement. Fixes #36 --- src/plugins/flow.js | 1 + .../actual.js | 1 + .../expected.json | 281 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/actual.js create mode 100644 test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 5329fef875..164ea6ae41 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -958,6 +958,7 @@ export default (superClass: Class): Class => class extends super this.state.inType = true; const type = this.flowParseUnionType(); this.state.inType = oldInType; + this.state.exprAllowed = false; return type; } diff --git a/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/actual.js b/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/actual.js new file mode 100644 index 0000000000..a4cfe8e70f --- /dev/null +++ b/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/actual.js @@ -0,0 +1 @@ + {}} /> \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/expected.json b/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/expected.json new file mode 100644 index 0000000000..75d1eb85f5 --- /dev/null +++ b/test/fixtures/flow/type-annotations/function-expression-inside-jsx-attr/expected.json @@ -0,0 +1,281 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "expression": { + "type": "JSXElement", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "start": 5, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "name": "x" + }, + "value": { + "type": "JSXExpressionContainer", + "start": 7, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "predicate": null, + "returnType": { + "type": "TypeAnnotation", + "start": 20, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 22, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 27, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "params": [ + { + "type": "StringTypeAnnotation", + "start": 28, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 34 + } + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "Array" + }, + "name": "Array" + } + } + }, + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": [], + "directives": [] + } + } + } + } + ], + "name": { + "type": "JSXIdentifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "name": "bar" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file