---
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/error.todo-unconditional-set-state-lambda.js
---
Input:
function Component(props) {
  let y = 0;
  const [x, setX] = useState(0);

  const foo = () => {
    setX(1);
    y = 1; // TODO: force foo's mutable range to extend, but ideally we can just remove this line
  };
  foo();

  return [x, y];
}


Output:
{
  "type": "Program",
  "body": [
    {
      "type": "FunctionDeclaration",
      "id": {
        "type": "Identifier",
        "name": "Component",
        "typeAnnotation": null,
        "loc": null,
        "range": [
          9,
          18
        ]
      },
      "params": [
        {
          "type": "Identifier",
          "name": "props",
          "typeAnnotation": null,
          "loc": null,
          "range": [
            19,
            24
          ]
        }
      ],
      "body": {
        "type": "BlockStatement",
        "body": [
          {
            "type": "VariableDeclaration",
            "kind": "let",
            "declarations": [
              {
                "type": "VariableDeclarator",
                "id": {
                  "type": "Identifier",
                  "name": "y",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    34,
                    35
                  ]
                },
                "init": {
                  "type": "NumericLiteral",
                  "value": 0.0,
                  "loc": null,
                  "range": [
                    38,
                    39
                  ]
                },
                "loc": null,
                "range": [
                  34,
                  39
                ]
              }
            ],
            "loc": null,
            "range": [
              30,
              40
            ]
          },
          {
            "type": "VariableDeclaration",
            "kind": "const",
            "declarations": [
              {
                "type": "VariableDeclarator",
                "id": {
                  "type": "ArrayPattern",
                  "elements": [
                    {
                      "type": "Identifier",
                      "name": "x",
                      "typeAnnotation": null,
                      "loc": null,
                      "range": [
                        50,
                        51
                      ]
                    },
                    {
                      "type": "Identifier",
                      "name": "setX",
                      "typeAnnotation": null,
                      "loc": null,
                      "range": [
                        53,
                        57
                      ]
                    }
                  ],
                  "loc": null,
                  "range": [
                    49,
                    58
                  ]
                },
                "init": {
                  "type": "CallExpression",
                  "callee": {
                    "type": "Identifier",
                    "name": "useState",
                    "typeAnnotation": null,
                    "loc": null,
                    "range": [
                      61,
                      69
                    ]
                  },
                  "arguments": [
                    {
                      "type": "NumericLiteral",
                      "value": 0.0,
                      "loc": null,
                      "range": [
                        70,
                        71
                      ]
                    }
                  ],
                  "loc": null,
                  "range": [
                    61,
                    72
                  ]
                },
                "loc": null,
                "range": [
                  49,
                  72
                ]
              }
            ],
            "loc": null,
            "range": [
              43,
              73
            ]
          },
          {
            "type": "VariableDeclaration",
            "kind": "const",
            "declarations": [
              {
                "type": "VariableDeclarator",
                "id": {
                  "type": "Identifier",
                  "name": "foo",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    83,
                    86
                  ]
                },
                "init": {
                  "type": "ArrowFunctionExpression",
                  "id": null,
                  "params": [],
                  "body": {
                    "type": "BlockStatement",
                    "body": [
                      {
                        "type": "ExpressionStatement",
                        "expression": {
                          "type": "CallExpression",
                          "callee": {
                            "type": "Identifier",
                            "name": "setX",
                            "typeAnnotation": null,
                            "loc": null,
                            "range": [
                              101,
                              105
                            ]
                          },
                          "arguments": [
                            {
                              "type": "NumericLiteral",
                              "value": 1.0,
                              "loc": null,
                              "range": [
                                106,
                                107
                              ]
                            }
                          ],
                          "loc": null,
                          "range": [
                            101,
                            108
                          ]
                        },
                        "directive": null,
                        "loc": null,
                        "range": [
                          101,
                          109
                        ]
                      },
                      {
                        "type": "ExpressionStatement",
                        "expression": {
                          "type": "AssignmentExpression",
                          "operator": "=",
                          "left": {
                            "type": "Identifier",
                            "name": "y",
                            "typeAnnotation": null,
                            "loc": null,
                            "range": [
                              114,
                              115
                            ]
                          },
                          "right": {
                            "type": "NumericLiteral",
                            "value": 1.0,
                            "loc": null,
                            "range": [
                              118,
                              119
                            ]
                          },
                          "loc": null,
                          "range": [
                            114,
                            119
                          ]
                        },
                        "directive": null,
                        "loc": null,
                        "range": [
                          114,
                          120
                        ]
                      }
                    ],
                    "loc": null,
                    "range": [
                      95,
                      211
                    ]
                  },
                  "generator": false,
                  "async": false,
                  "loc": null,
                  "range": [
                    89,
                    211
                  ],
                  "expression": false,
                  "loc": null,
                  "range": [
                    89,
                    211
                  ]
                },
                "loc": null,
                "range": [
                  83,
                  211
                ]
              }
            ],
            "loc": null,
            "range": [
              77,
              212
            ]
          },
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "CallExpression",
              "callee": {
                "type": "Identifier",
                "name": "foo",
                "typeAnnotation": null,
                "loc": null,
                "range": [
                  215,
                  218
                ]
              },
              "arguments": [],
              "loc": null,
              "range": [
                215,
                220
              ]
            },
            "directive": null,
            "loc": null,
            "range": [
              215,
              221
            ]
          },
          {
            "type": "ReturnStatement",
            "argument": {
              "type": "ArrayExpression",
              "elements": [
                {
                  "type": "Identifier",
                  "name": "x",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    233,
                    234
                  ]
                },
                {
                  "type": "Identifier",
                  "name": "y",
                  "typeAnnotation": null,
                  "loc": null,
                  "range": [
                    236,
                    237
                  ]
                }
              ],
              "loc": null,
              "range": [
                232,
                238
              ]
            },
            "loc": null,
            "range": [
              225,
              239
            ]
          }
        ],
        "loc": null,
        "range": [
          26,
          241
        ]
      },
      "generator": false,
      "async": false,
      "loc": null,
      "range": [
        0,
        241
      ],
      "loc": null,
      "range": [
        0,
        241
      ]
    }
  ],
  "sourceType": "script",
  "loc": null,
  "range": [
    0,
    241
  ]
}
