---
source: crates/react_hermes_parser/tests/parser_test.rs
expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
input_file: crates/react_hermes_parser/tests/fixtures/reduce-reactive-cond-memberexpr-join.js
---
Input:
// To preserve the nullthrows behavior and reactive deps of this code,
// Forget needs to add `props.a.b` or a subpath as a dependency.
//
// (1) Since the reactive block producing x unconditionally read props.a.<...>,
//     reading `props.a.b` outside of the block would still preserve nullthrows
//     semantics of source code
// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
//     However, `props.a?.b` is only dependent on whether `props.a` is nullish,
//     not its actual value. Since we already preserve nullthrows on `props.a`,
//     we technically do not need to add `props.a` as a dependency.

function Component(props) {
  let x = [];
  x.push(props.a?.b);
  x.push(props.a.b.c);
  return x;
}


Output:
{
  "type": "Program",
  "body": [
    {
      "type": "FunctionDeclaration",
      "id": {
        "type": "Identifier",
        "name": "Component",
        "typeAnnotation": null,
        "loc": null,
        "range": [
          648,
          657
        ]
      },
      "params": [
        {
          "type": "Identifier",
          "name": "props",
          "typeAnnotation": null,
          "loc": null,
          "range": [
            658,
            663
          ]
        }
      ],
      "body": {
        "type": "BlockStatement",
        "body": [
          {
            "type": "VariableDeclaration",
            "kind": "let",
            "declarations": [
              {
                "type": "VariableDeclarator",
                "id": {
                  "type": "Identifier",
                  "name": "x",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    673,
                    674
                  ]
                },
                "init": {
                  "type": "ArrayExpression",
                  "elements": [],
                  "loc": null,
                  "range": [
                    677,
                    679
                  ]
                },
                "loc": null,
                "range": [
                  673,
                  679
                ]
              }
            ],
            "loc": null,
            "range": [
              669,
              680
            ]
          },
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "CallExpression",
              "callee": {
                "type": "MemberExpression",
                "object": {
                  "type": "Identifier",
                  "name": "x",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    683,
                    684
                  ]
                },
                "property": {
                  "type": "Identifier",
                  "name": "push",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    685,
                    689
                  ]
                },
                "computed": false,
                "loc": null,
                "range": [
                  683,
                  689
                ]
              },
              "arguments": [
                {
                  "type": "OptionalMemberExpression",
                  "object": {
                    "type": "MemberExpression",
                    "object": {
                      "type": "Identifier",
                      "name": "props",
                      "typeAnnotation": null,
                      "loc": null,
                      "range": [
                        690,
                        695
                      ]
                    },
                    "property": {
                      "type": "Identifier",
                      "name": "a",
                      "typeAnnotation": null,
                      "loc": null,
                      "range": [
                        696,
                        697
                      ]
                    },
                    "computed": false,
                    "loc": null,
                    "range": [
                      690,
                      697
                    ]
                  },
                  "property": {
                    "type": "Identifier",
                    "name": "b",
                    "typeAnnotation": null,
                    "loc": null,
                    "range": [
                      699,
                      700
                    ]
                  },
                  "computed": false,
                  "optional": true,
                  "loc": null,
                  "range": [
                    690,
                    700
                  ]
                }
              ],
              "loc": null,
              "range": [
                683,
                701
              ]
            },
            "directive": null,
            "loc": null,
            "range": [
              683,
              702
            ]
          },
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "CallExpression",
              "callee": {
                "type": "MemberExpression",
                "object": {
                  "type": "Identifier",
                  "name": "x",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    705,
                    706
                  ]
                },
                "property": {
                  "type": "Identifier",
                  "name": "push",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    707,
                    711
                  ]
                },
                "computed": false,
                "loc": null,
                "range": [
                  705,
                  711
                ]
              },
              "arguments": [
                {
                  "type": "MemberExpression",
                  "object": {
                    "type": "MemberExpression",
                    "object": {
                      "type": "MemberExpression",
                      "object": {
                        "type": "Identifier",
                        "name": "props",
                        "typeAnnotation": null,
                        "loc": null,
                        "range": [
                          712,
                          717
                        ]
                      },
                      "property": {
                        "type": "Identifier",
                        "name": "a",
                        "typeAnnotation": null,
                        "loc": null,
                        "range": [
                          718,
                          719
                        ]
                      },
                      "computed": false,
                      "loc": null,
                      "range": [
                        712,
                        719
                      ]
                    },
                    "property": {
                      "type": "Identifier",
                      "name": "b",
                      "typeAnnotation": null,
                      "loc": null,
                      "range": [
                        720,
                        721
                      ]
                    },
                    "computed": false,
                    "loc": null,
                    "range": [
                      712,
                      721
                    ]
                  },
                  "property": {
                    "type": "Identifier",
                    "name": "c",
                    "typeAnnotation": null,
                    "loc": null,
                    "range": [
                      722,
                      723
                    ]
                  },
                  "computed": false,
                  "loc": null,
                  "range": [
                    712,
                    723
                  ]
                }
              ],
              "loc": null,
              "range": [
                705,
                724
              ]
            },
            "directive": null,
            "loc": null,
            "range": [
              705,
              725
            ]
          },
          {
            "type": "ReturnStatement",
            "argument": {
              "type": "Identifier",
              "name": "x",
              "typeAnnotation": null,
              "loc": null,
              "range": [
                735,
                736
              ]
            },
            "loc": null,
            "range": [
              728,
              737
            ]
          }
        ],
        "loc": null,
        "range": [
          665,
          739
        ]
      },
      "generator": false,
      "async": false,
      "loc": null,
      "range": [
        639,
        739
      ],
      "loc": null,
      "range": [
        639,
        739
      ]
    }
  ],
  "sourceType": "script",
  "loc": null,
  "range": [
    639,
    739
  ]
}
