Skip to content

Fix binding operation evaluation in objects #665

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

Closed

Conversation

asennikov
Copy link

@asennikov asennikov commented Jan 3, 2024

The issue was originally raised here: https://stackoverflow.com/questions/77742737/jsonata-transform-operator-unexpected-change-in-variable-binding-between-versi

Before #583 a JSONata user could bind a variable within an RHS expression of one of the object entries and then reuse that variable within another object entry, e.g.:

{ 
    "foo": $bar := "x",
    "bar": $bar
}

Here's the result on 1.8.6:

image

But due to the await Promise.all added in #583, this no longer works in 2.0.3:

image

In this PR, I'm proposing a change to remove the Promise.all and iterate sequentially, which might have some performance implications for certain users of JSONata, but IMO, it would still be better to maintain compatibility between versions.

All tests are passing:

image

Copy link

@efhjones efhjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Seems reasonable to me

Copy link

@scarabaeus scarabaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fast turn-around on this @asennikov!

@andrew-coleman
Copy link
Member

Sorry, no. There is no guaranteed order of execution of expressions within an object ({...}). Although this Javascript implementation executes them in the same order as appears in the expression, other implementations (such as go) don't necessarily. See #179 for example.
The only construct in JSONata that guarantees order of execution is the block (... ; ... ; ...) expression.

@ghost
Copy link

ghost commented Jan 4, 2024

As the originator on SO, thank you for clearing that up. Will try to re-formulate my business logic.
Bit frustrating, but I still love JSONata,
Sebastian

@asennikov
Copy link
Author

Sorry, no. There is no guaranteed order of execution of expressions within an object ({...}). Although this Javascript implementation executes them in the same order as appears in the expression, other implementations (such as go) don't necessarily. See #179 for example.
The only construct in JSONata that guarantees order of execution is the block (... ; ... ; ...) expression.

Sounds reasonable.

@asennikov asennikov deleted the asennikov/transform-test-case branch January 4, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants