* Property variance type annotations for Flow plugin Non-method properties and indexers of object types, declare class, and interfaces can be "positive" or "negative." Class fields, but again not methods, can also have variance. This PR generalizes the variance annotations for type parameters into a new node type, and reuses that node for those properties. The code for object types is reused for interfaces and declare classes. The changes there are straightfoward. The code for class fields is reused for object literals, which do not support variance annotations (currently). This code is a bit sketchy, because we always parse variance annotations in the `parsePropertyName` extension, then error in a the subsequent parse phase for object literals (`parseObjPropValue`) or class methods (`parseClassMethod`). * Remove bogus unreachable code, clarify variance parsing conditional * Don't use a new node type for variance annotations Adding a new node type, specifically changing the TypeParameter node's variance property to be node-valued, is a breaking change. We might choose to make this breaking change in a later version. * s/start/variancePos
152 lines
3.3 KiB
JSON
152 lines
3.3 KiB
JSON
{
|
|
"type": "File",
|
|
"start": 0,
|
|
"end": 34,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 34
|
|
}
|
|
},
|
|
"program": {
|
|
"type": "Program",
|
|
"start": 0,
|
|
"end": 34,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 34
|
|
}
|
|
},
|
|
"sourceType": "module",
|
|
"body": [
|
|
{
|
|
"type": "InterfaceDeclaration",
|
|
"start": 0,
|
|
"end": 34,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 0
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 34
|
|
}
|
|
},
|
|
"id": {
|
|
"type": "Identifier",
|
|
"start": 10,
|
|
"end": 11,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 10
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 11
|
|
}
|
|
},
|
|
"name": "A"
|
|
},
|
|
"typeParameters": null,
|
|
"extends": [],
|
|
"body": {
|
|
"type": "ObjectTypeAnnotation",
|
|
"start": 12,
|
|
"end": 34,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 12
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 34
|
|
}
|
|
},
|
|
"callProperties": [],
|
|
"properties": [
|
|
{
|
|
"type": "ObjectTypeProperty",
|
|
"start": 14,
|
|
"end": 32,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 14
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 32
|
|
}
|
|
},
|
|
"key": {
|
|
"type": "Identifier",
|
|
"start": 14,
|
|
"end": 17,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 14
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 17
|
|
}
|
|
},
|
|
"name": "foo"
|
|
},
|
|
"value": {
|
|
"type": "FunctionTypeAnnotation",
|
|
"start": 19,
|
|
"end": 31,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 19
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 31
|
|
}
|
|
},
|
|
"params": [],
|
|
"rest": null,
|
|
"returnType": {
|
|
"type": "NumberTypeAnnotation",
|
|
"start": 25,
|
|
"end": 31,
|
|
"loc": {
|
|
"start": {
|
|
"line": 1,
|
|
"column": 25
|
|
},
|
|
"end": {
|
|
"line": 1,
|
|
"column": 31
|
|
}
|
|
}
|
|
},
|
|
"typeParameters": null
|
|
},
|
|
"optional": false,
|
|
"variance": null
|
|
}
|
|
],
|
|
"indexers": []
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"comments": []
|
|
} |