swc/crates/swc_ecma_parser/tests/tsc/parentheses.json
Donny/강동윤 aa83584634
refactor(es/ast): Reimplement optional chaining (#7441)
**Related issue:**

 - Closes #7003.
 - Closes #7156.
2023-06-12 06:47:40 +00:00

1230 lines
40 KiB
JSON

{
"type": "Script",
"span": {
"start": 30,
"end": 364,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 30,
"end": 77,
"ctxt": 0
},
"kind": "const",
"declare": true,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 44,
"end": 76,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 44,
"end": 46,
"ctxt": 0
},
"value": "o1",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 46,
"end": 76,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsParenthesizedType",
"span": {
"start": 48,
"end": 76,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 49,
"end": 75,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 50,
"end": 64,
"ctxt": 0
},
"rest": {
"start": 50,
"end": 53,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 53,
"end": 57,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 57,
"end": 64,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 59,
"end": 64,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 59,
"end": 62,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 66,
"end": 75,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 69,
"end": 75,
"ctxt": 0
},
"kind": "number"
}
}
}
}
}
},
"init": null,
"definite": false
}
]
},
{
"type": "VariableDeclaration",
"span": {
"start": 78,
"end": 130,
"ctxt": 0
},
"kind": "const",
"declare": true,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 92,
"end": 129,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 92,
"end": 94,
"ctxt": 0
},
"value": "o2",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 94,
"end": 129,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 96,
"end": 129,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 98,
"end": 127,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 98,
"end": 99,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 99,
"end": 127,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 101,
"end": 127,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 102,
"end": 116,
"ctxt": 0
},
"rest": {
"start": 102,
"end": 105,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 105,
"end": 109,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 109,
"end": 116,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 111,
"end": 116,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 111,
"end": 114,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 118,
"end": 127,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 121,
"end": 127,
"ctxt": 0
},
"kind": "number"
}
}
}
},
"typeParams": null
}
]
}
}
},
"init": null,
"definite": false
}
]
},
{
"type": "VariableDeclaration",
"span": {
"start": 131,
"end": 205,
"ctxt": 0
},
"kind": "const",
"declare": true,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 145,
"end": 204,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 145,
"end": 147,
"ctxt": 0
},
"value": "o3",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 147,
"end": 204,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 149,
"end": 204,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 151,
"end": 202,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 151,
"end": 152,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 152,
"end": 202,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsParenthesizedType",
"span": {
"start": 154,
"end": 202,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 155,
"end": 201,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 156,
"end": 170,
"ctxt": 0
},
"rest": {
"start": 156,
"end": 159,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 159,
"end": 163,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 163,
"end": 170,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 165,
"end": 170,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 165,
"end": 168,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 172,
"end": 201,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 175,
"end": 201,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 176,
"end": 190,
"ctxt": 0
},
"rest": {
"start": 176,
"end": 179,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 179,
"end": 183,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 183,
"end": 190,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 185,
"end": 190,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 185,
"end": 188,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 192,
"end": 201,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 195,
"end": 201,
"ctxt": 0
},
"kind": "number"
}
}
}
}
}
}
},
"typeParams": null
}
]
}
}
},
"init": null,
"definite": false
}
]
},
{
"type": "VariableDeclaration",
"span": {
"start": 206,
"end": 288,
"ctxt": 0
},
"kind": "const",
"declare": true,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 220,
"end": 287,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 220,
"end": 222,
"ctxt": 0
},
"value": "o4",
"optional": false,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 222,
"end": 287,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 224,
"end": 287,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 226,
"end": 285,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 226,
"end": 227,
"ctxt": 0
},
"value": "b",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 227,
"end": 285,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsParenthesizedType",
"span": {
"start": 229,
"end": 285,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 230,
"end": 283,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 231,
"end": 245,
"ctxt": 0
},
"rest": {
"start": 231,
"end": 234,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 234,
"end": 238,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 238,
"end": 245,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 240,
"end": 245,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 240,
"end": 243,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 247,
"end": 283,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsTypeLiteral",
"span": {
"start": 250,
"end": 283,
"ctxt": 0
},
"members": [
{
"type": "TsPropertySignature",
"span": {
"start": 252,
"end": 281,
"ctxt": 0
},
"readonly": false,
"key": {
"type": "Identifier",
"span": {
"start": 252,
"end": 253,
"ctxt": 0
},
"value": "c",
"optional": false
},
"computed": false,
"optional": false,
"init": null,
"params": [],
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 253,
"end": 281,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsFunctionType",
"span": {
"start": 255,
"end": 281,
"ctxt": 0
},
"params": [
{
"type": "RestElement",
"span": {
"start": 256,
"end": 270,
"ctxt": 0
},
"rest": {
"start": 256,
"end": 259,
"ctxt": 0
},
"argument": {
"type": "Identifier",
"span": {
"start": 259,
"end": 263,
"ctxt": 0
},
"value": "args",
"optional": false,
"typeAnnotation": null
},
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 263,
"end": 270,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsArrayType",
"span": {
"start": 265,
"end": 270,
"ctxt": 0
},
"elemType": {
"type": "TsKeywordType",
"span": {
"start": 265,
"end": 268,
"ctxt": 0
},
"kind": "any"
}
}
}
}
],
"typeParams": null,
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 272,
"end": 281,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 275,
"end": 281,
"ctxt": 0
},
"kind": "number"
}
}
}
},
"typeParams": null
}
]
}
}
}
}
},
"typeParams": null
}
]
}
}
},
"init": null,
"definite": false
}
]
},
{
"type": "ExpressionStatement",
"span": {
"start": 290,
"end": 304,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 290,
"end": 303,
"ctxt": 0
},
"callee": {
"type": "ParenthesisExpression",
"span": {
"start": 290,
"end": 294,
"ctxt": 0
},
"expression": {
"type": "Identifier",
"span": {
"start": 291,
"end": 293,
"ctxt": 0
},
"value": "o1",
"optional": false
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "BinaryExpression",
"span": {
"start": 295,
"end": 302,
"ctxt": 0
},
"operator": "??",
"left": {
"type": "Identifier",
"span": {
"start": 295,
"end": 297,
"ctxt": 0
},
"value": "o1",
"optional": false
},
"right": {
"type": "NumericLiteral",
"span": {
"start": 301,
"end": 302,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
}
],
"typeArguments": null
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 305,
"end": 322,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 305,
"end": 321,
"ctxt": 0
},
"callee": {
"type": "ParenthesisExpression",
"span": {
"start": 305,
"end": 312,
"ctxt": 0
},
"expression": {
"type": "OptionalChainingExpression",
"span": {
"start": 306,
"end": 311,
"ctxt": 0
},
"optional": true,
"base": {
"type": "MemberExpression",
"span": {
"start": 306,
"end": 311,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 306,
"end": 308,
"ctxt": 0
},
"value": "o2",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 310,
"end": 311,
"ctxt": 0
},
"value": "b",
"optional": false
}
}
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "BinaryExpression",
"span": {
"start": 313,
"end": 320,
"ctxt": 0
},
"operator": "??",
"left": {
"type": "Identifier",
"span": {
"start": 313,
"end": 315,
"ctxt": 0
},
"value": "o1",
"optional": false
},
"right": {
"type": "NumericLiteral",
"span": {
"start": 319,
"end": 320,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
}
],
"typeArguments": null
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 323,
"end": 342,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 323,
"end": 341,
"ctxt": 0
},
"callee": {
"type": "ParenthesisExpression",
"span": {
"start": 323,
"end": 332,
"ctxt": 0
},
"expression": {
"type": "OptionalChainingExpression",
"span": {
"start": 324,
"end": 331,
"ctxt": 0
},
"optional": false,
"base": {
"type": "CallExpression",
"span": {
"start": 324,
"end": 331,
"ctxt": 0
},
"callee": {
"type": "OptionalChainingExpression",
"span": {
"start": 324,
"end": 329,
"ctxt": 0
},
"optional": true,
"base": {
"type": "MemberExpression",
"span": {
"start": 324,
"end": 329,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 324,
"end": 326,
"ctxt": 0
},
"value": "o3",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 328,
"end": 329,
"ctxt": 0
},
"value": "b",
"optional": false
}
}
},
"arguments": [],
"typeArguments": null
}
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "BinaryExpression",
"span": {
"start": 333,
"end": 340,
"ctxt": 0
},
"operator": "??",
"left": {
"type": "Identifier",
"span": {
"start": 333,
"end": 335,
"ctxt": 0
},
"value": "o1",
"optional": false
},
"right": {
"type": "NumericLiteral",
"span": {
"start": 339,
"end": 340,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
}
],
"typeArguments": null
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 343,
"end": 364,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 343,
"end": 363,
"ctxt": 0
},
"callee": {
"type": "ParenthesisExpression",
"span": {
"start": 343,
"end": 354,
"ctxt": 0
},
"expression": {
"type": "OptionalChainingExpression",
"span": {
"start": 344,
"end": 353,
"ctxt": 0
},
"optional": false,
"base": {
"type": "MemberExpression",
"span": {
"start": 344,
"end": 353,
"ctxt": 0
},
"object": {
"type": "OptionalChainingExpression",
"span": {
"start": 344,
"end": 351,
"ctxt": 0
},
"optional": false,
"base": {
"type": "CallExpression",
"span": {
"start": 344,
"end": 351,
"ctxt": 0
},
"callee": {
"type": "OptionalChainingExpression",
"span": {
"start": 344,
"end": 349,
"ctxt": 0
},
"optional": true,
"base": {
"type": "MemberExpression",
"span": {
"start": 344,
"end": 349,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 344,
"end": 346,
"ctxt": 0
},
"value": "o4",
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 348,
"end": 349,
"ctxt": 0
},
"value": "b",
"optional": false
}
}
},
"arguments": [],
"typeArguments": null
}
},
"property": {
"type": "Identifier",
"span": {
"start": 352,
"end": 353,
"ctxt": 0
},
"value": "c",
"optional": false
}
}
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "BinaryExpression",
"span": {
"start": 355,
"end": 362,
"ctxt": 0
},
"operator": "??",
"left": {
"type": "Identifier",
"span": {
"start": 355,
"end": 357,
"ctxt": 0
},
"value": "o1",
"optional": false
},
"right": {
"type": "NumericLiteral",
"span": {
"start": 361,
"end": 362,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}