swc/crates/swc_ecma_parser/tests/tsc/intersectionNarrowing.json
2022-02-04 17:08:38 +09:00

1349 lines
36 KiB
JSON

{
"type": "Script",
"span": {
"start": 45,
"end": 862,
"ctxt": 0
},
"body": [
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 54,
"end": 56,
"ctxt": 0
},
"value": "f1",
"optional": false
},
"declare": false,
"params": [
{
"type": "Parameter",
"span": {
"start": 60,
"end": 89,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 60,
"end": 89,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 61,
"end": 89,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 63,
"end": 89,
"ctxt": 0
},
"types": [
{
"type": "TsIntersectionType",
"span": {
"start": 63,
"end": 73,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 63,
"end": 64,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 63,
"end": 64,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 67,
"end": 73,
"ctxt": 0
},
"kind": "string"
}
]
},
{
"type": "TsIntersectionType",
"span": {
"start": 76,
"end": 89,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 76,
"end": 77,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 76,
"end": 77,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 80,
"end": 89,
"ctxt": 0
},
"kind": "undefined"
}
]
}
]
}
}
}
}
],
"decorators": [],
"span": {
"start": 45,
"end": 160,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 91,
"end": 160,
"ctxt": 0
},
"stmts": [
{
"type": "IfStatement",
"span": {
"start": 98,
"end": 157,
"ctxt": 0
},
"test": {
"type": "Identifier",
"span": {
"start": 102,
"end": 103,
"ctxt": 0
},
"value": "x",
"optional": false
},
"consequent": {
"type": "BlockStatement",
"span": {
"start": 105,
"end": 157,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 116,
"end": 118,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 116,
"end": 117,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
},
"alternate": null
}
]
},
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 56,
"end": 59,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 57,
"end": 58,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 57,
"end": 58,
"ctxt": 0
},
"value": "T",
"optional": false
},
"constraint": null,
"default": null
}
]
},
"returnType": null
},
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 173,
"end": 175,
"ctxt": 0
},
"value": "f2",
"optional": false
},
"declare": false,
"params": [
{
"type": "Parameter",
"span": {
"start": 179,
"end": 208,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 179,
"end": 208,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 180,
"end": 208,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 182,
"end": 208,
"ctxt": 0
},
"types": [
{
"type": "TsIntersectionType",
"span": {
"start": 182,
"end": 192,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 182,
"end": 183,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 182,
"end": 183,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 186,
"end": 192,
"ctxt": 0
},
"kind": "string"
}
]
},
{
"type": "TsIntersectionType",
"span": {
"start": 195,
"end": 208,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 195,
"end": 196,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 195,
"end": 196,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 199,
"end": 208,
"ctxt": 0
},
"kind": "undefined"
}
]
}
]
}
}
}
}
],
"decorators": [],
"span": {
"start": 164,
"end": 359,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 210,
"end": 359,
"ctxt": 0
},
"stmts": [
{
"type": "IfStatement",
"span": {
"start": 217,
"end": 356,
"ctxt": 0
},
"test": {
"type": "BinaryExpression",
"span": {
"start": 221,
"end": 236,
"ctxt": 0
},
"operator": "!==",
"left": {
"type": "Identifier",
"span": {
"start": 221,
"end": 222,
"ctxt": 0
},
"value": "x",
"optional": false
},
"right": {
"type": "Identifier",
"span": {
"start": 227,
"end": 236,
"ctxt": 0
},
"value": "undefined",
"optional": false
}
},
"consequent": {
"type": "BlockStatement",
"span": {
"start": 238,
"end": 290,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 249,
"end": 251,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 249,
"end": 250,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
},
"alternate": {
"type": "BlockStatement",
"span": {
"start": 301,
"end": 356,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 312,
"end": 314,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 312,
"end": 313,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
}
}
]
},
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 175,
"end": 178,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 176,
"end": 177,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 176,
"end": 177,
"ctxt": 0
},
"value": "T",
"optional": false
},
"constraint": null,
"default": null
}
]
},
"returnType": null
},
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 372,
"end": 374,
"ctxt": 0
},
"value": "f3",
"optional": false
},
"declare": false,
"params": [
{
"type": "Parameter",
"span": {
"start": 378,
"end": 404,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 378,
"end": 404,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 379,
"end": 404,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 381,
"end": 404,
"ctxt": 0
},
"types": [
{
"type": "TsIntersectionType",
"span": {
"start": 381,
"end": 391,
"ctxt": 0
},
"types": [
{
"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
},
{
"type": "TsKeywordType",
"span": {
"start": 385,
"end": 391,
"ctxt": 0
},
"kind": "string"
}
]
},
{
"type": "TsIntersectionType",
"span": {
"start": 394,
"end": 404,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 394,
"end": 395,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 394,
"end": 395,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 398,
"end": 404,
"ctxt": 0
},
"kind": "number"
}
]
}
]
}
}
}
}
],
"decorators": [],
"span": {
"start": 363,
"end": 558,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 406,
"end": 558,
"ctxt": 0
},
"stmts": [
{
"type": "IfStatement",
"span": {
"start": 413,
"end": 555,
"ctxt": 0
},
"test": {
"type": "BinaryExpression",
"span": {
"start": 417,
"end": 438,
"ctxt": 0
},
"operator": "===",
"left": {
"type": "UnaryExpression",
"span": {
"start": 417,
"end": 425,
"ctxt": 0
},
"operator": "typeof",
"argument": {
"type": "Identifier",
"span": {
"start": 424,
"end": 425,
"ctxt": 0
},
"value": "x",
"optional": false
}
},
"right": {
"type": "StringLiteral",
"span": {
"start": 430,
"end": 438,
"ctxt": 0
},
"value": "string",
"hasEscape": false,
"kind": {
"type": "normal",
"containsQuote": true
}
}
},
"consequent": {
"type": "BlockStatement",
"span": {
"start": 440,
"end": 492,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 451,
"end": 453,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 451,
"end": 452,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
},
"alternate": {
"type": "BlockStatement",
"span": {
"start": 503,
"end": 555,
"ctxt": 0
},
"stmts": [
{
"type": "ExpressionStatement",
"span": {
"start": 514,
"end": 516,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 514,
"end": 515,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
}
}
]
},
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 374,
"end": 377,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 375,
"end": 376,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 375,
"end": 376,
"ctxt": 0
},
"value": "T",
"optional": false
},
"constraint": null,
"default": null
}
]
},
"returnType": null
},
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 571,
"end": 573,
"ctxt": 0
},
"value": "f4",
"optional": false
},
"declare": false,
"params": [
{
"type": "Parameter",
"span": {
"start": 577,
"end": 593,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 577,
"end": 593,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 578,
"end": 593,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsUnionType",
"span": {
"start": 580,
"end": 593,
"ctxt": 0
},
"types": [
{
"type": "TsIntersectionType",
"span": {
"start": 580,
"end": 585,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 580,
"end": 581,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 580,
"end": 581,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsLiteralType",
"span": {
"start": 584,
"end": 585,
"ctxt": 0
},
"literal": {
"type": "NumericLiteral",
"span": {
"start": 584,
"end": 585,
"ctxt": 0
},
"value": 1.0
}
}
]
},
{
"type": "TsIntersectionType",
"span": {
"start": 588,
"end": 593,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 588,
"end": 589,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 588,
"end": 589,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsLiteralType",
"span": {
"start": 592,
"end": 593,
"ctxt": 0
},
"literal": {
"type": "NumericLiteral",
"span": {
"start": 592,
"end": 593,
"ctxt": 0
},
"value": 2.0
}
}
]
}
]
}
}
}
}
],
"decorators": [],
"span": {
"start": 562,
"end": 746,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 595,
"end": 746,
"ctxt": 0
},
"stmts": [
{
"type": "SwitchStatement",
"span": {
"start": 602,
"end": 743,
"ctxt": 0
},
"discriminant": {
"type": "Identifier",
"span": {
"start": 610,
"end": 611,
"ctxt": 0
},
"value": "x",
"optional": false
},
"cases": [
{
"type": "SwitchCase",
"span": {
"start": 624,
"end": 641,
"ctxt": 0
},
"test": {
"type": "NumericLiteral",
"span": {
"start": 629,
"end": 630,
"ctxt": 0
},
"value": 1.0
},
"consequent": [
{
"type": "ExpressionStatement",
"span": {
"start": 632,
"end": 634,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 632,
"end": 633,
"ctxt": 0
},
"value": "x",
"optional": false
}
},
{
"type": "BreakStatement",
"span": {
"start": 635,
"end": 641,
"ctxt": 0
},
"label": null
}
]
},
{
"type": "SwitchCase",
"span": {
"start": 661,
"end": 678,
"ctxt": 0
},
"test": {
"type": "NumericLiteral",
"span": {
"start": 666,
"end": 667,
"ctxt": 0
},
"value": 2.0
},
"consequent": [
{
"type": "ExpressionStatement",
"span": {
"start": 669,
"end": 671,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 669,
"end": 670,
"ctxt": 0
},
"value": "x",
"optional": false
}
},
{
"type": "BreakStatement",
"span": {
"start": 672,
"end": 678,
"ctxt": 0
},
"label": null
}
]
},
{
"type": "SwitchCase",
"span": {
"start": 698,
"end": 709,
"ctxt": 0
},
"test": null,
"consequent": [
{
"type": "ExpressionStatement",
"span": {
"start": 707,
"end": 709,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 707,
"end": 708,
"ctxt": 0
},
"value": "x",
"optional": false
}
}
]
}
]
}
]
},
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 573,
"end": 576,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 574,
"end": 575,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 574,
"end": 575,
"ctxt": 0
},
"value": "T",
"optional": false
},
"constraint": null,
"default": null
}
]
},
"returnType": null
},
{
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 759,
"end": 761,
"ctxt": 0
},
"value": "f5",
"optional": false
},
"declare": false,
"params": [
{
"type": "Parameter",
"span": {
"start": 789,
"end": 802,
"ctxt": 0
},
"decorators": [],
"pat": {
"type": "Identifier",
"span": {
"start": 789,
"end": 802,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 790,
"end": 802,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsIntersectionType",
"span": {
"start": 792,
"end": 802,
"ctxt": 0
},
"types": [
{
"type": "TsTypeReference",
"span": {
"start": 792,
"end": 793,
"ctxt": 0
},
"typeName": {
"type": "Identifier",
"span": {
"start": 792,
"end": 793,
"ctxt": 0
},
"value": "T",
"optional": false
},
"typeParams": null
},
{
"type": "TsKeywordType",
"span": {
"start": 796,
"end": 802,
"ctxt": 0
},
"kind": "number"
}
]
}
}
}
}
],
"decorators": [],
"span": {
"start": 750,
"end": 862,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 804,
"end": 862,
"ctxt": 0
},
"stmts": [
{
"type": "VariableDeclaration",
"span": {
"start": 811,
"end": 836,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 817,
"end": 835,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 817,
"end": 819,
"ctxt": 0
},
"value": "t1",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "BinaryExpression",
"span": {
"start": 822,
"end": 835,
"ctxt": 0
},
"operator": "===",
"left": {
"type": "Identifier",
"span": {
"start": 822,
"end": 823,
"ctxt": 0
},
"value": "x",
"optional": false
},
"right": {
"type": "StringLiteral",
"span": {
"start": 828,
"end": 835,
"ctxt": 0
},
"value": "hello",
"hasEscape": false,
"kind": {
"type": "normal",
"containsQuote": true
}
}
},
"definite": false
}
]
}
]
},
"generator": false,
"async": false,
"typeParameters": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 761,
"end": 788,
"ctxt": 0
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 762,
"end": 787,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 762,
"end": 763,
"ctxt": 0
},
"value": "T",
"optional": false
},
"constraint": {
"type": "TsUnionType",
"span": {
"start": 772,
"end": 787,
"ctxt": 0
},
"types": [
{
"type": "TsKeywordType",
"span": {
"start": 772,
"end": 778,
"ctxt": 0
},
"kind": "string"
},
{
"type": "TsKeywordType",
"span": {
"start": 781,
"end": 787,
"ctxt": 0
},
"kind": "number"
}
]
},
"default": null
}
]
},
"returnType": null
}
],
"interpreter": null
}