swc/crates/swc_ecma_parser/tests/tsc/intersectionOfUnionNarrowing.json

694 lines
18 KiB
JSON

{
"type": "Script",
"span": {
"start": 19,
"end": 315,
"ctxt": 0
},
"body": [
{
"type": "TsInterfaceDeclaration",
"span": {
"start": 19,
"end": 84,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 29,
"end": 30,
"ctxt": 0
},
"value": "X",
"optional": false
},
"declare": false,
"typeParams": null,
"extends": [],
"body": {
"type": "TsInterfaceBody",
"span": {
"start": 31,
"end": 84,
"ctxt": 0
},
"body": [
{
"type": "TsPropertySignature",
"span": {
"start": 35,
"end": 57,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 36,
"ctxt": 0
},
"value": "a",
"optional": false
},
"computed": false,
"optional": true,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 37,
"end": 56,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 39,
"end": 56,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 41,
"end": 54,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 41,
"end": 46,
"ctxt": 0
},
"value": "aProp",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 46,
"end": 54,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 48,
"end": 54,
"ctxt": 0
},
"kind": "string"
}
},
"typeParams": null
}
]
}
},
"typeParams": null
},
{
"type": "TsPropertySignature",
"span": {
"start": 60,
"end": 82,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 60,
"end": 61,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": true,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 62,
"end": 81,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 64,
"end": 81,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 66,
"end": 79,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 66,
"end": 71,
"ctxt": 0
},
"value": "bProp",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 71,
"end": 79,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 73,
"end": 79,
"ctxt": 0
},
"kind": "string"
}
},
"typeParams": null
}
]
}
},
"typeParams": null
}
]
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 85,
"end": 155,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 90,
"end": 94,
"ctxt": 0
},
"value": "AorB",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 97,
"end": 154,
"ctxt": 0
},
"types": [
{
"type": "TsTypeLiteral",
"span": {
"start": 97,
"end": 124,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 99,
"end": 109,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 99,
"end": 100,
"ctxt": 0
},
"value": "a",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 100,
"end": 108,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 102,
"end": 108,
"ctxt": 0
},
"kind": "object"
}
},
"typeParams": null
},
{
"type": "TsPropertySignature",
"span": {
"start": 110,
"end": 122,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 110,
"end": 111,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 111,
"end": 122,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 113,
"end": 122,
"ctxt": 0
},
"kind": "undefined"
}
},
"typeParams": null
}
]
},
{
"type": "TsTypeLiteral",
"span": {
"start": 127,
"end": 154,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 129,
"end": 142,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 129,
"end": 130,
"ctxt": 0
},
"value": "a",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 130,
"end": 141,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 132,
"end": 141,
"ctxt": 0
},
"kind": "undefined"
}
},
"typeParams": null
},
{
"type": "TsPropertySignature",
"span": {
"start": 143,
"end": 152,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 143,
"end": 144,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 144,
"end": 152,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 146,
"end": 152,
"ctxt": 0
},
"kind": "object"
}
},
"typeParams": null
}
]
}
]
}
},
{
"type": "VariableDeclaration",
"span": {
"start": 157,
"end": 183,
"ctxt": 0
},
"kind": "const",
"declare": true,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 171,
"end": 182,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 171,
"end": 172,
"ctxt": 0
},
"value": "q",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 172,
"end": 182,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsIntersectionType",
"span": {
"start": 174,
"end": 182,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 174,
"end": 175,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 174,
"end": 175,
"ctxt": 0
},
"value": "X",
"optional": false
},
"typeParams": null
},
{
"type": "TsTypeReference",
"span": {
"start": 178,
"end": 182,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 178,
"end": 182,
"ctxt": 0
},
"value": "AorB",
"optional": false
},
"typeParams": null
}
]
}
}
},
"init": null,
"definite": false
}
]
},
{
"type": "IfStatement",
"span": {
"start": 185,
"end": 315,
"ctxt": 0
},
"test": {
"type": "BinaryExpression",
"span": {
"start": 189,
"end": 206,
"ctxt": 0
},
"operator": "!==",
"left": {
"type": "MemberExpression",
"span": {
"start": 189,
"end": 192,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 189,
"end": 190,
"ctxt": 0
},
"value": "q",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 191,
"end": 192,
"ctxt": 0
},
"value": "a",
"optional": false
}
},
"right": {
"type": "Identifier",
"span": {
"start": 197,
"end": 206,
"ctxt": 0
},
"value": "undefined",
"optional": false
}
},
"consequent": {
"type": "BlockStatement",
"span": {
"start": 208,
"end": 224,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 212,
"end": 222,
"ctxt": 0
},
"expression": {
"type": "MemberExpression",
"span": {
"start": 212,
"end": 221,
"ctxt": 0
},
"object": {
"type": "MemberExpression",
"span": {
"start": 212,
"end": 215,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 212,
"end": 213,
"ctxt": 0
},
"value": "q",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 214,
"end": 215,
"ctxt": 0
},
"value": "a",
"optional": false
}
},
"property": {
"type": "Identifier",
"span": {
"start": 216,
"end": 221,
"ctxt": 0
},
"value": "aProp",
"optional": false
}
}
}
]
},
"alternate": {
"type": "BlockStatement",
"span": {
"start": 230,
"end": 315,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 303,
"end": 313,
"ctxt": 0
},
"expression": {
"type": "MemberExpression",
"span": {
"start": 303,
"end": 312,
"ctxt": 0
},
"object": {
"type": "MemberExpression",
"span": {
"start": 303,
"end": 306,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 303,
"end": 304,
"ctxt": 0
},
"value": "q",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 305,
"end": 306,
"ctxt": 0
},
"value": "b",
"optional": false
}
},
"property": {
"type": "Identifier",
"span": {
"start": 307,
"end": 312,
"ctxt": 0
},
"value": "bProp",
"optional": false
}
}
}
]
}
}
],
"interpreter": null
}