Skip to content

Incorrect types in jsonata.d.ts #585

Open
@socjalis

Description

@socjalis

According to the included types lhs in ExprNode should be of type ExprNode itself.
Meanwhile:

const JSONATA_STRING = `{"x": y}`;
const expression = jsonata(JSONATA_STRING);
console.log(JSON.stringify(expression.ast()));

resolves to:

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

As you can see, lhs is an array here.
Incorrect types make it really hard to traverse the whole expression.ast() tree without checking 2k+ lines source code files, which makes the developer experience not that fun.

Also I didn't really go that deep into the source code, but something like this seems more intuitive at the first glance and is coherent with the provided types:

{
  "type":"unary",
  "value":"{",
  "position":1,
  "steps?/stages?":[
    {
      "type":"binary",
      "value":":",
      "position":3,
      "lhs":{
        "value":"x",
        "type":"string",
        "position":4
      },
      "rhs":{
        "type":"path",
        "steps":[
          {
            "value":"y",
            "type":"name",
            "position":7
          }
        ]
      }
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions