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

std.prune prunes hidden fields #765

Open
mmonaco opened this issue Aug 18, 2024 · 0 comments
Open

std.prune prunes hidden fields #765

mmonaco opened this issue Aug 18, 2024 · 0 comments

Comments

@mmonaco
Copy link

mmonaco commented Aug 18, 2024

NOTE: This isn't go-specific.

std.prune() prunes hidden fields from objects. Is this intentional? I'm not familiar with any history here...

At the least we should document this, but it feels more like a bug. std.prune() removes whole objects that have std.length() == 0, where the length does not include hidden fields but that seems reasonable. But then, for the objects it does keep which have at least 1 non-hidden field, the hidden members are removed.

Currently in stdast.go:

                "\n",
                "  prune(a)::\n",
                "    local isContent(b) =\n",
                "      if b == null then\n",
                "        false\n",
                "      else if std.isArray(b) then\n",
                "        std.length(b) > 0\n",
                "      else if std.isObject(b) then\n",
                "        std.length(b) > 0\n",
                "      else\n",
                "        true;\n",
                "    if std.isArray(a) then\n",
                "      [std.prune(x) for x in a if isContent($.prune(x))]\n",
                "    else if std.isObject(a) then {\n",
                "      [x]: $.prune(a[x])\n",
                "      for x in std.objectFields(a)\n",
                "      if isContent(std.prune(a[x]))\n",
                "    } else\n",
                "      a,\n",
                "\n",

IMO that last bit should be for x in std.objectFieldsAll(a)\n.

Is a patch welcome? :)

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

No branches or pull requests

1 participant