jsonata-js/jsonata

JSONata 2.0.3 Is Not Evaluating Variable Binds Inline

RKHamilton95 opened this issue · 2 comments

Hi all, thanks for the project. I've used this extensively over the years and this is a very powerful and fun language for data mapping/manipulation!

I recently upgraded to JSONata 2.0.3 from 1.8.4. I haven't noticed any breaking or odd changes to the language until today when I came across this transform.

JSONata 1.8.6 (1.8.4 is not available in the exerciser): https://try.jsonata.org/PXuqFciEo
JSONata 2.0.3: https://try.jsonata.org/7R99rDHyw

In 1.8.6 it assigns the variable and then references it on prop "test3". In 2.0.3 it seems to assign the variable during the first iteration but doesn't apply it until the next iteration. This doesn't seem like intended behavior and I wanted to get some opinions.

Thanks!

Same basic issue as #607. Read there for insight. Here's a similar rework, using a statement block to ensure the variable bindings occur in a predictable order:

{
  "test": $.(
    $payload:={"newProp":$};
    {
      "test2": $payload,
      "test3": $payload
    }
  )
}

Thanks for the quick reply @markmelville

This is less than ideal as we use JSONata to allow people to write there own free-form scripts and don't have an easy way to go through and update them to make this change but I understand your position as this is a major version bump. We were just hoping to get the performance benefits of the async upgrade (And finally purge the codebase of those pesky generator functions!).