Add support of shorthand property syntax#746
Add support of shorthand property syntax#746ericleib wants to merge 2 commits intojsonata-js:masterfrom
Conversation
|
I believe it's quite a Javascript-y syntax concept, but one I do find convenient, and the implementation is not tied to Javascript, so I've got nothing against including this 🙂 Thoughts, @andrew-coleman? |
There was a problem hiding this comment.
I love this idea! I think there's a small bug that needs fixing still.
I'm a daily user of jsonata, so while this is my first contribution/review for this repo, I have a decent idea of what quirks to look out for.
The short of it is that I created a test scenario that doesn't work as I'd expect:
{
"expr": "{and, in, or, `true`, `false`, `null`, function, λ}",
"data": {
"and": "Logical AND operator",
"in": "Membership operator",
"or": "Logical OR operator",
"true": "Boolean true literal",
"false": "Boolean false literal",
"null": "Null literal",
"function": "Function keyword",
"λ": "Cooler function keyword"
},
"bindings": {},
"result": {
"and": "Logical AND operator", <-- Fail
"in": "Membership operator", <-- Fail
"or": "Logical OR operator", <-- Fail
"true": "Boolean true literal", <-- Fail
"false": "Boolean false literal", <-- Fail
"null": "Null literal", <-- Fail
"function": "Function keyword",
"λ": "Cooler function keyword"
}
}Only the lambda function keywords are able to use this shorthand. (See /test/test-suite/groups/boolean-expresssions for similar examples using keywords).
I created a few more tests that seemed useful. I've attached them to this review (I don't know how to work off your branch, so this seemed like the next best option).
If you can get it to pass all these tests, I think it's good to go. I tried hard to break it, and only the keywords method was successful!
case006.json
case007.json
case008.json
case009.json
case010.json
case011.json <- This one fails!
case012.json
case013.json
case014.json
case015.json
keywords.json
I would try to write up a solution for this myself, but I honestly wouldn't know where to start. This was fun to test, and I hope to see this feature in a future release!
This Pull Request adds support for the shorthand property notation.
This allows to simplify an expression from:
to:
This also works for variables:
output: