From 7247bbf6af9a9f13ab42804fe8d78273bad3ee91 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Thu, 23 Jun 2016 13:41:44 -0700 Subject: [PATCH] [Flow] Arrow function type parameter declarations --- src/plugins/flow.js | 73 ++- .../arrow/expected.json | 33 ++ .../arrow_error_with_jsx/actual.js | 1 + .../arrow_error_with_jsx/options.json | 4 + .../arrow_error_without_jsx/.options.json.swn | Bin 0 -> 12288 bytes .../arrow_error_without_jsx/actual.js | 1 + .../arrow_error_without_jsx/options.json | 4 + .../arrow_with_jsx/actual.js | 5 + .../arrow_with_jsx/expected.json | 530 ++++++++++++++++++ .../arrow_with_jsx/options.json | 3 + .../arrow_without_jsx/actual.js | 5 + .../arrow_without_jsx/expected.json | 530 ++++++++++++++++++ .../arrow_without_jsx/options.json | 4 + 13 files changed, 1192 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow/expected.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/.options.json.swn create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json create mode 100644 test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 9d0279ae99..a89b56aa0d 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -2,6 +2,7 @@ /* eslint max-len: 0 */ import { types as tt } from "../tokenizer/types"; +import { types as ct } from "../tokenizer/context"; import Parser from "../parser"; let pp = Parser.prototype; @@ -220,7 +221,12 @@ pp.flowParseTypeParameterDeclaration = function () { let node = this.startNode(); node.params = []; - this.expectRelational("<"); + if (this.isRelational("<") || this.match(tt.jsxTagStart)) { + this.next(); + } else { + this.unexpected(); + } + do { node.params.push(this.flowParseTypeParameter()); if (!this.isRelational(">")) { @@ -1017,9 +1023,12 @@ export default function (instance) { // parse function type parameters - function foo() {} instance.extend("parseFunctionParams", function (inner) { return function (node) { + const oldInType = this.state.inType; + this.state.inType = true; if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); } + this.state.inType = oldInType; inner.call(this, node); }; }); @@ -1053,6 +1062,68 @@ export default function (instance) { }; }); + // We need to support type parameter declarations for arrow functions. This + // is tricky. There are three situations we need to handle + // + // 1. This is either JSX or an arrow function. We'll try JSX first. If that + // fails, we'll try an arrow function. If that fails, we'll throw the JSX + // error. + // 2. This is an arrow function. We'll parse the type parameter declaration, + // parse the rest, make sure the rest is an arrow function, and go from + // there + // 3. This is neither. Just call the inner function + instance.extend("parseMaybeAssign", function (inner) { + return function (...args) { + let jsxError = null; + let state = this.state.clone(); + if (tt.jsxTagStart && this.match(tt.jsxTagStart)) { + try { + return inner.apply(this, args); + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + jsxError = err; + } else { + throw err; + } + } + } + + // Need to push something onto the context to stop + // the JSX plugin from messing with the tokens + this.state.context.push(ct.parenExpression); + if (jsxError != null || this.isRelational("<")) { + let arrowExpression; + let typeParameters; + try { + const oldInType = this.state.inType; + this.state.inType = true; + typeParameters = this.flowParseTypeParameterDeclaration(); + this.state.inType = oldInType; + + arrowExpression = inner.apply(this, args); + arrowExpression.typeParameters = typeParameters; + } catch (err) { + throw jsxError || err; + } + + if (arrowExpression.type === "ArrowFunctionExpression") { + return arrowExpression; + } else if (jsxError != null) { + throw jsxError; + } else { + this.raise( + typeParameters.start, + "Expected an arrow function after this type parameter declaration", + ); + } + } + this.state.context.pop(); + + return inner.apply(this, args); + }; + }); + // handle return types for arrow functions instance.extend("parseArrow", function (inner) { return function (node) { diff --git a/test/fixtures/flow/type-parameter-declaration/arrow/expected.json b/test/fixtures/flow/type-parameter-declaration/arrow/expected.json new file mode 100644 index 0000000000..016fc254c0 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow/expected.json @@ -0,0 +1,33 @@ +{ + "type": "File", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "sourceType": "module", + "body": [], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js b/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js new file mode 100644 index 0000000000..6ada1841b7 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js @@ -0,0 +1 @@ +"I'm not an arrow function" diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json b/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json new file mode 100644 index 0000000000..c6b625d25a --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["flow", "jsx"], + "throws": "Unterminated JSX contents (1:3)" +} diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/.options.json.swn b/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/.options.json.swn new file mode 100644 index 0000000000000000000000000000000000000000..8e5031b13dadd205c97bda7a40653d43bee19ae3 GIT binary patch literal 12288 zcmeI&!Aiq07zgl7ybV$G1!BE8u*>EYWk+ulJn2*r8EKbo9cfdN)NP3R06vUI@d11m z-$G1Ay~x0uAo~Z>kMGMDXnwcSM2*YN89k~W5H~gmIk}KmX{}RzuU5!Vio3+ue;M<> zFpcu&p{`36bGdlK` zLWg}3OPAP0WsGaBCOzSvx;IJeNENm>HdCf@zijGbqq4;>fhq)+QJ}Dc@OX{1_L~iV z{GDK%Zf$m#Q37X%00bZa0SG_<0uX?}(hAtTLY~~|S4x4^GFE=XGDUy@1Rwwb2tWV= z5P$##AOHafK;Rz=@IE2W>x8_z>Hq(KfB%2F{KL(+a_z;hV?Y1`5P$##AOHafKmY;| zfB*y_@FxNfgwnu{%HS@+o1jgDZssn?r%A@G=+o2lYZ@z8$*iHf&33C6_)WPihDqkz OZvub4KDgZ@_v8zURb8F{ literal 0 HcmV?d00001 diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js b/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js new file mode 100644 index 0000000000..6ada1841b7 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js @@ -0,0 +1 @@ +"I'm not an arrow function" diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json b/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json new file mode 100644 index 0000000000..cf72e7dfca --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["flow"], + "throws": "Expected an arrow function after this type parameter declaration (1:0)" +} diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js new file mode 100644 index 0000000000..b20a1a5f62 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js @@ -0,0 +1,5 @@ +() => 123; +(x) => 123; +(x: number) => 123; +(x: number) => { 123 }; + diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json new file mode 100644 index 0000000000..6316556c6e --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json @@ -0,0 +1,530 @@ +{ + "type": "File", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "NumericLiteral", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "name": "x" + } + ], + "body": { + "type": "NumericLiteral", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 29, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 32, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 34, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + } + } + ], + "body": { + "type": "NumericLiteral", + "start": 47, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 52, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 57, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 13 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 70, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 72, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 72, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 52, + "end": 55, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json new file mode 100644 index 0000000000..6533ea2c86 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["flow", "jsx"] +} diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js new file mode 100644 index 0000000000..b20a1a5f62 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js @@ -0,0 +1,5 @@ +() => 123; +(x) => 123; +(x: number) => 123; +(x: number) => { 123 }; + diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json new file mode 100644 index 0000000000..6316556c6e --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json @@ -0,0 +1,530 @@ +{ + "type": "File", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "NumericLiteral", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 14, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "name": "x" + } + ], + "body": { + "type": "NumericLiteral", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 29, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 32, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 34, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + } + } + ], + "body": { + "type": "NumericLiteral", + "start": 47, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 52, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 57, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 13 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 70, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 72, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 72, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 52, + "end": 55, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "name": "T" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json new file mode 100644 index 0000000000..ccabc4fdd6 --- /dev/null +++ b/test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["flow"] +} +