Merge pull request #54 from gabelevi/arrow
[Flow] Arrow function type parameter declarations
This commit is contained in:
commit
d976b56bbe
@ -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<T>() {}
|
||||
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;
|
||||
if (tt.jsxTagStart && this.match(tt.jsxTagStart)) {
|
||||
const state = this.state.clone();
|
||||
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) {
|
||||
|
||||
33
test/fixtures/flow/type-parameter-declaration/arrow/expected.json
vendored
Normal file
33
test/fixtures/flow/type-parameter-declaration/arrow/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
1
test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js
vendored
Normal file
1
test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<T>"I'm not an arrow function"
|
||||
4
test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json
vendored
Normal file
4
test/fixtures/flow/type-parameter-declaration/arrow_error_with_jsx/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["flow", "jsx"],
|
||||
"throws": "Unterminated JSX contents (1:3)"
|
||||
}
|
||||
1
test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js
vendored
Normal file
1
test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<T>"I'm not an arrow function"
|
||||
4
test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json
vendored
Normal file
4
test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["flow"],
|
||||
"throws": "Expected an arrow function after this type parameter declaration (1:0)"
|
||||
}
|
||||
5
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js
vendored
Normal file
5
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<T>() => 123;
|
||||
<T>(x) => 123;
|
||||
<T>(x: number) => 123;
|
||||
<T>(x: number) => { 123 };
|
||||
|
||||
530
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json
vendored
Normal file
530
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json
vendored
Normal file
3
test/fixtures/flow/type-parameter-declaration/arrow_with_jsx/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["flow", "jsx"]
|
||||
}
|
||||
5
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js
vendored
Normal file
5
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<T>() => 123;
|
||||
<T>(x) => 123;
|
||||
<T>(x: number) => 123;
|
||||
<T>(x: number) => { 123 };
|
||||
|
||||
530
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json
vendored
Normal file
530
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
4
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json
vendored
Normal file
4
test/fixtures/flow/type-parameter-declaration/arrow_without_jsx/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["flow"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user