Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure the keepArray node parameter is taken into the account. #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WojciechMatuszewskiStedi
Copy link

@WojciechMatuszewskiStedi WojciechMatuszewskiStedi commented Sep 7, 2021

Description

First of all, thank you for this library. It's very helpful!

When I was playing with the expression to AST conversion back and forth, I noticed that the keepArray properties on a given node are not considered during the conversion from AST to a string expression.

Reproduction

Given the expression

foo.{bar: "baz"}[]

The produced AST using jsonata v1.7 yields:

{
  "type": "path",
  "steps": [
    { "value": "foo", "type": "name", "position": 3 },
    {
      "type": "unary",
      "value": "{",
      "position": 5,
      "lhs": [
        [
          { "type": "path", "steps": [{ "value": "bar", "type": "name", "position": 8 }] },
          { "value": "baz", "type": "string", "position": 15 }
        ]
      ],
      "keepArray": true
    }
  ],
  "keepSingletonArray": true
}

Now, if we serialize the above AST back to an expression form, the result is as follows:

foo.{bar: "baz"}

As you can see, we are missing the [] at the end of the expression

Uncertainty

I'm not sure what keepSingletonArray is responsible for. I would be grateful for any guidance regarding this property - mainly is my contribution correct in relation to the keepSingletonArray property as well?

@WojciechMatuszewskiStedi
Copy link
Author

cc @loganvolkers , @00salmon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant