Implement support of spread operator#745
Conversation
|
Thank you for raising this. On the face of it, this looks like a great proposal. What's concerning me though is the implied order of execution of the items within the object. Although not a problem for this Javascript implementation, it could be a problem for other implementations. Take a look at this issue for reference. Although that issue was only relating to the test suite, I think this proposal would bring it into the language itself. I'm not saying that a feature like this is not possible, but we need to be very mindful of this potential problem. |
|
Thank you for looking into it! I understand your concern. It does bring a change to the language. In fact when implementing it, I could see the potential inconsistency of behavior with this error "Multiple key definitions evaluate to same key" (which prevents any key overriding mechanism). |
This Pull Request adds support of the spread operator
...in the Jsonata syntax.The implementation works the same way as in Javascript:
This copies the key/value pairs from object
footo a new object, in this case potentially overriding propertiesaandb. Conversely, ifaandbwere added AFTERfoo, then their values would override theaandbentries offoo.Please let me know if this is something that the community would be interested in. In my case (an avid Jsonata user), this feature would make a big difference.