jsonata-js / jsonata

JSONata query and transformation language - http://jsonata.org
MIT License
2.05k stars 220 forks source link

Missing Type in Interface ExprNode, lhs can be both an ExprNode and ExprNode[] #703

Closed DevDimov closed 1 week ago

DevDimov commented 3 months ago

In Interface ExprNode, lhs can be both an ExprNode and ExprNode[]

For example, jsonata('($x := 1; $y := 2;)').ast().expressions outputs

[
  {
    type: "bind",
    value: ":=",
    position: 7,
    lhs: { value: "x", type: "variable", position: 4 },
    rhs: { value: 1, type: "number", position: 9 },
  },
  {
    type: "bind",
    value: ":=",
    position: 15,
    lhs: { value: "y", type: "variable", position: 13 },
    rhs: { value: 2, type: "number", position: 16 },
  },
];

And jsonata('{"x": y, "z": 1}').ast() outputs

{
      "type": "unary",
      "value": "{",
      "position": 1,
      "lhs": [
        [
          {
            "value": "x",
            "type": "string",
            "position": 4
          },
          {
            "type": "path",
            "steps": [
              {
                "value": "y",
                "type": "name",
                "position": 7
              }
            ]
          }
        ],
        [
          {
            "value": "z",
            "type": "string",
            "position": 12
          },
          {
            "value": 1,
            "type": "number",
            "position": 15
          }
        ]
      ]
    }

Similar issue: https://github.com/jsonata-js/jsonata/issues/585

I'm using node v20.13.0 and jsonata v2.0.4. Happy to open a pull request.

mattbaileyuk commented 1 week ago

Fixed via PR (thank you!)