Skip to content

std.prune prunes hidden fields #765

@mmonaco

Description

@mmonaco

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? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions