Remove jsx context when parsing arrow functions (#475)

This commit is contained in:
Brian Ng
2017-04-23 17:45:19 -05:00
committed by Daniel Tschinder
parent c4fb3fe742
commit 68967bf515
5 changed files with 695 additions and 8 deletions

View File

@@ -0,0 +1 @@
const functionReturningIdentityAsAField = () => ({ id: <T>(value: T): T => value });

View File

@@ -0,0 +1,346 @@
{
"type": "File",
"start": 0,
"end": 84,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 84
}
},
"program": {
"type": "Program",
"start": 0,
"end": 84,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 84
}
},
"sourceType": "module",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 84,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 84
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 83
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 39
},
"identifierName": "functionReturningIdentityAsAField"
},
"name": "functionReturningIdentityAsAField"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 42,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 83
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [],
"body": {
"type": "ObjectExpression",
"start": 49,
"end": 82,
"loc": {
"start": {
"line": 1,
"column": 49
},
"end": {
"line": 1,
"column": 82
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 51,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 51
},
"end": {
"line": 1,
"column": 80
}
},
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 51,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 51
},
"end": {
"line": 1,
"column": 53
},
"identifierName": "id"
},
"name": "id"
},
"value": {
"type": "ArrowFunctionExpression",
"start": 55,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 55
},
"end": {
"line": 1,
"column": 80
}
},
"predicate": null,
"returnType": {
"type": "TypeAnnotation",
"start": 68,
"end": 71,
"loc": {
"start": {
"line": 1,
"column": 68
},
"end": {
"line": 1,
"column": 71
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 70,
"end": 71,
"loc": {
"start": {
"line": 1,
"column": 70
},
"end": {
"line": 1,
"column": 71
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 70,
"end": 71,
"loc": {
"start": {
"line": 1,
"column": 70
},
"end": {
"line": 1,
"column": 71
},
"identifierName": "T"
},
"name": "T"
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 59,
"end": 67,
"loc": {
"start": {
"line": 1,
"column": 59
},
"end": {
"line": 1,
"column": 67
},
"identifierName": "value"
},
"name": "value",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 64,
"end": 67,
"loc": {
"start": {
"line": 1,
"column": 64
},
"end": {
"line": 1,
"column": 67
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 66,
"end": 67,
"loc": {
"start": {
"line": 1,
"column": 66
},
"end": {
"line": 1,
"column": 67
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 66,
"end": 67,
"loc": {
"start": {
"line": 1,
"column": 66
},
"end": {
"line": 1,
"column": 67
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 75,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 75
},
"end": {
"line": 1,
"column": 80
},
"identifierName": "value"
},
"name": "value"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 55,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 55
},
"end": {
"line": 1,
"column": 58
}
},
"params": [
{
"type": "TypeParameter",
"start": 56,
"end": 57,
"loc": {
"start": {
"line": 1,
"column": 56
},
"end": {
"line": 1,
"column": 57
}
},
"name": "T",
"variance": null
}
]
}
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 48
}
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
const identity = <T>(t: T): T => t;
const a = 1;

View File

@@ -0,0 +1,340 @@
{
"type": "File",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 12
}
},
"sourceType": "module",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 35
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 34
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 14
},
"identifierName": "identity"
},
"name": "identity"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 17,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 34
}
},
"predicate": null,
"returnType": {
"type": "TypeAnnotation",
"start": 26,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 29
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "T"
},
"name": "T"
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 21,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 25
},
"identifierName": "t"
},
"name": "t",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 25
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 25
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 25
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 33,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 34
},
"identifierName": "t"
},
"name": "t"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 17,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 20
}
},
"params": [
{
"type": "TypeParameter",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
}
},
"name": "T",
"variance": null
}
]
}
}
}
],
"kind": "const"
},
{
"type": "VariableDeclaration",
"start": 36,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 12
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 42,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 11
}
},
"id": {
"type": "Identifier",
"start": 42,
"end": 43,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "a"
},
"name": "a"
},
"init": {
"type": "NumericLiteral",
"start": 46,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 11
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
],
"kind": "const"
}
],
"directives": []
}
}