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

1419 lines
36 KiB
JSON

{
"type": "Script",
"span": {
"start": 41,
"end": 482,
"ctxt": 0
},
"body": [
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 41,
"end": 80,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 46,
"end": 49,
"ctxt": 0
},
"value": "Foo",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 49,
"end": 52,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 50,
"end": 51,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 50,
"end": 51,
"ctxt": 0
},
"value": "A",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 55,
"end": 79,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 57,
"end": 69,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 57,
"end": 61,
"ctxt": 0
},
"value": "type",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 61,
"end": 68,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsLiteralType",
"span": {
"start": 63,
"end": 68,
"ctxt": 0
},
"literal": {
"type": "StringLiteral",
"span": {
"start": 63,
"end": 68,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
}
}
},
"typeParams": null
},
{
"type": "TsCallSignatureDeclaration",
"span": {
"start": 70,
"end": 77,
"ctxt": 0
},
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 72,
"end": 77,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 74,
"end": 77,
"ctxt": 0
},
"elemType": {
"type": "TsTypeReference",
"span": {
"start": 74,
"end": 75,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 74,
"end": 75,
"ctxt": 0
},
"value": "A",
"optional": false
},
"typeParams": null
}
}
},
"typeParams": null
}
]
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 81,
"end": 118,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 86,
"end": 89,
"ctxt": 0
},
"value": "Bar",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 89,
"end": 92,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 90,
"end": 91,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 90,
"end": 91,
"ctxt": 0
},
"value": "A",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 95,
"end": 117,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 97,
"end": 109,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 97,
"end": 101,
"ctxt": 0
},
"value": "type",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 101,
"end": 108,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsLiteralType",
"span": {
"start": 103,
"end": 108,
"ctxt": 0
},
"literal": {
"type": "StringLiteral",
"span": {
"start": 103,
"end": 108,
"ctxt": 0
},
"value": "bar",
"raw": "\"bar\""
}
}
},
"typeParams": null
},
{
"type": "TsCallSignatureDeclaration",
"span": {
"start": 110,
"end": 115,
"ctxt": 0
},
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 112,
"end": 115,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeReference",
"span": {
"start": 114,
"end": 115,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 114,
"end": 115,
"ctxt": 0
},
"value": "A",
"optional": false
},
"typeParams": null
}
},
"typeParams": null
}
]
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 120,
"end": 153,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 125,
"end": 131,
"ctxt": 0
},
"value": "FooBar",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 131,
"end": 134,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 132,
"end": 133,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 132,
"end": 133,
"ctxt": 0
},
"value": "A",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 137,
"end": 152,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 137,
"end": 143,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 137,
"end": 140,
"ctxt": 0
},
"value": "Foo",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 140,
"end": 143,
"ctxt": 0
},
"params": [
{
"type": "TsTypeReference",
"span": {
"start": 141,
"end": 142,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 141,
"end": 142,
"ctxt": 0
},
"value": "A",
"optional": false
},
"typeParams": null
}
]
}
},
{
"type": "TsTypeReference",
"span": {
"start": 146,
"end": 152,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 146,
"end": 149,
"ctxt": 0
},
"value": "Bar",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 149,
"end": 152,
"ctxt": 0
},
"params": [
{
"type": "TsTypeReference",
"span": {
"start": 150,
"end": 151,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 150,
"end": 151,
"ctxt": 0
},
"value": "A",
"optional": false
},
"typeParams": null
}
]
}
}
]
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 155,
"end": 210,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 160,
"end": 166,
"ctxt": 0
},
"value": "InferA",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 166,
"end": 169,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 167,
"end": 168,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 167,
"end": 168,
"ctxt": 0
},
"value": "T",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"typeAnnotation": {
"type": "TsConditionalType",
"span": {
"start": 172,
"end": 209,
"ctxt": 0
},
"checkType": {
"type": "TsTypeReference",
"span": {
"start": 172,
"end": 173,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 172,
"end": 173,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
"extendsType": {
"type": "TsTypeReference",
"span": {
"start": 182,
"end": 197,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 182,
"end": 188,
"ctxt": 0
},
"value": "FooBar",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 188,
"end": 197,
"ctxt": 0
},
"params": [
{
"type": "TsInferType",
"span": {
"start": 189,
"end": 196,
"ctxt": 0
},
"typeParam": {
"type": "TsTypeParameter",
"span": {
"start": 195,
"end": 196,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 195,
"end": 196,
"ctxt": 0
},
"value": "A",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
}
]
}
},
"trueType": {
"type": "TsTypeReference",
"span": {
"start": 200,
"end": 201,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 200,
"end": 201,
"ctxt": 0
},
"value": "A",
"optional": false
},
"typeParams": null
},
"falseType": {
"type": "TsKeywordType",
"span": {
"start": 204,
"end": 209,
"ctxt": 0
},
"kind": "never"
}
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 212,
"end": 244,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 217,
"end": 221,
"ctxt": 0
},
"value": "FooA",
"optional": false
},
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeReference",
"span": {
"start": 224,
"end": 243,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 224,
"end": 230,
"ctxt": 0
},
"value": "InferA",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 230,
"end": 243,
"ctxt": 0
},
"params": [
{
"type": "TsTypeReference",
"span": {
"start": 231,
"end": 242,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 231,
"end": 234,
"ctxt": 0
},
"value": "Foo",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 234,
"end": 242,
"ctxt": 0
},
"params": [
{
"type": "TsKeywordType",
"span": {
"start": 235,
"end": 241,
"ctxt": 0
},
"kind": "number"
}
]
}
}
]
}
}
},
{
"type": "TsTypeAliasDeclaration",
"span": {
"start": 279,
"end": 344,
"ctxt": 0
},
"declare": false,
"id": {
"type": "Identifier",
"span": {
"start": 284,
"end": 288,
"ctxt": 0
},
"value": "Item",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 288,
"end": 291,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 289,
"end": 290,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 289,
"end": 290,
"ctxt": 0
},
"value": "T",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 294,
"end": 343,
"ctxt": 0
},
"types": [
{
"type": "TsTypeLiteral",
"span": {
"start": 294,
"end": 316,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 296,
"end": 306,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 296,
"end": 300,
"ctxt": 0
},
"value": "kind",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 300,
"end": 305,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsLiteralType",
"span": {
"start": 302,
"end": 305,
"ctxt": 0
},
"literal": {
"type": "StringLiteral",
"span": {
"start": 302,
"end": 305,
"ctxt": 0
},
"value": "a",
"raw": "'a'"
}
}
},
"typeParams": null
},
{
"type": "TsPropertySignature",
"span": {
"start": 307,
"end": 314,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 307,
"end": 311,
"ctxt": 0
},
"value": "data",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 311,
"end": 314,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeReference",
"span": {
"start": 313,
"end": 314,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 313,
"end": 314,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
}
},
"typeParams": null
}
]
},
{
"type": "TsTypeLiteral",
"span": {
"start": 319,
"end": 343,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 321,
"end": 331,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 321,
"end": 325,
"ctxt": 0
},
"value": "kind",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 325,
"end": 330,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsLiteralType",
"span": {
"start": 327,
"end": 330,
"ctxt": 0
},
"literal": {
"type": "StringLiteral",
"span": {
"start": 327,
"end": 330,
"ctxt": 0
},
"value": "b",
"raw": "'b'"
}
}
},
"typeParams": null
},
{
"type": "TsPropertySignature",
"span": {
"start": 332,
"end": 341,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 332,
"end": 336,
"ctxt": 0
},
"value": "data",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 336,
"end": 341,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 338,
"end": 341,
"ctxt": 0
},
"elemType": {
"type": "TsTypeReference",
"span": {
"start": 338,
"end": 339,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 338,
"end": 339,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
}
}
},
"typeParams": null
}
]
}
]
}
},
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 363,
"end": 366,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"declare": true,
"params": [
{
"type": "Parameter",
"span": {
"start": 370,
"end": 383,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 370,
"end": 383,
"ctxt": 0
},
"value": "item",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 374,
"end": 383,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeReference",
"span": {
"start": 376,
"end": 383,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 376,
"end": 380,
"ctxt": 0
},
"value": "Item",
"optional": false
},
"typeParams": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 380,
"end": 383,
"ctxt": 0
},
"params": [
{
"type": "TsTypeReference",
"span": {
"start": 381,
"end": 382,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 381,
"end": 382,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
}
]
}
}
}
}
}
],
"decorators": [],
"span": {
"start": 346,
"end": 388,
"ctxt": 0
},
"body": null,
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 366,
"end": 369,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 367,
"end": 368,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 367,
"end": 368,
"ctxt": 0
},
"value": "T",
"optional": false
},
"in": false,
"out": false,
"constraint": null,
"default": null
}
]
},
"returnType": {
"type": "TsTypeAnnotation",
"span": {
"start": 384,
"end": 387,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeReference",
"span": {
"start": 386,
"end": 387,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 386,
"end": 387,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
}
}
},
{
"type": "VariableDeclaration",
"span": {
"start": 390,
"end": 428,
"ctxt": 0
},
"kind": "let",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 394,
"end": 427,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 394,
"end": 396,
"ctxt": 0
},
"value": "x1",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "CallExpression",
"span": {
"start": 399,
"end": 427,
"ctxt": 0
},
"callee": {
"type": "Identifier",
"span": {
"start": 399,
"end": 402,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"arguments": [
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 403,
"end": 426,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 405,
"end": 409,
"ctxt": 0
},
"value": "kind",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 411,
"end": 414,
"ctxt": 0
},
"value": "a",
"raw": "'a'"
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 416,
"end": 420,
"ctxt": 0
},
"value": "data",
"optional": false
},
"value": {
"type": "NumericLiteral",
"span": {
"start": 422,
"end": 424,
"ctxt": 0
},
"value": 42.0,
"raw": "42"
}
}
]
}
}
],
"typeArguments": null
},
"definite": false
}
]
},
{
"type": "VariableDeclaration",
"span": {
"start": 440,
"end": 482,
"ctxt": 0
},
"kind": "let",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 444,
"end": 481,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 444,
"end": 446,
"ctxt": 0
},
"value": "x2",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "CallExpression",
"span": {
"start": 449,
"end": 481,
"ctxt": 0
},
"callee": {
"type": "Identifier",
"span": {
"start": 449,
"end": 452,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"arguments": [
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 453,
"end": 480,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 455,
"end": 459,
"ctxt": 0
},
"value": "kind",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 461,
"end": 464,
"ctxt": 0
},
"value": "b",
"raw": "'b'"
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 466,
"end": 470,
"ctxt": 0
},
"value": "data",
"optional": false
},
"value": {
"type": "ArrayExpression",
"span": {
"start": 472,
"end": 478,
"ctxt": 0
},
"elements": [
{
"spread": null,
"expression": {
"type": "NumericLiteral",
"span": {
"start": 473,
"end": 474,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
},
{
"spread": null,
"expression": {
"type": "NumericLiteral",
"span": {
"start": 476,
"end": 477,
"ctxt": 0
},
"value": 2.0,
"raw": "2"
}
}
]
}
}
]
}
}
],
"typeArguments": null
},
"definite": false
}
]
}
],
"interpreter": null
}