Skip to content
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

Keep hidden fields in std.prune #1174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ricardbejarano
Copy link

According to the docs, std.prune:

Recursively remove all "empty" members of a. "Empty" is defined as zero length arrays, zero length objects, or null values. The argument a may have any type.

However, it also removes hidden fields from objects because it uses std.objectFields to traverse it. This PR changes that to use std.objectFieldsAll instead, which keeps hidden fields as promised by the docs.

Sort of relates to #1167.

Copy link

google-cla bot commented Sep 19, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ricardbejarano
Copy link
Author

CLA signed!

@@ -1625,7 +1625,7 @@ limitations under the License.
[std.prune(x) for x in a if isContent($.prune(x))]
else if std.isObject(a) then {
[x]: $.prune(a[x])
Copy link
Contributor

Choose a reason for hiding this comment

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

This way, every hidden field will be unhidden, and this will be a breaking change.

Also, fields referencing self/super will be frozen, and I don't think this is an useful thing after that?

Copy link
Author

Choose a reason for hiding this comment

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

What about these other options?

  1. std.prune(a, keep_hidden=false)
  2. std.prune(a, arrays=true, objects=true, nulls=true, hidden=true)
  3. std.pruneEx(a, arrays=true, objects=true, nulls=true, hidden=true)

Showing the default-state function headers here, users would then be able to override whatever they want to be pruned or not.

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.

3 participants