Skip to content

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

Open
WojciechMatuszewskiStedi wants to merge 2 commits intosaasquatch:mainfrom
WojciechMatuszewskiStedi:master
Open

fix: Ensure the keepArray node parameter is taken into the account.#13
WojciechMatuszewskiStedi wants to merge 2 commits intosaasquatch:mainfrom
WojciechMatuszewskiStedi:master

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