syntax-tree/unist-builder

Changed build result in v1.0.3

bodia-uz opened this issue · 3 comments

Build result changed in v1.0.3

code:

u('blockquote', {
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "x"
        }
      ]
    }
  ]
})

v1.0.2:

{"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"x"}]}]}

v1.0.3

{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"x"}]}]}

PS: root type is passed from code like this:

u('blockquote', remark().parse('x'))

Hmm, what you’re doing here is weird! A lot of stuff is going on.

  • You’re passing a root node “as a child” of a blockquote. That’s not valid. root should never be in another node
  • You’re passing a node (the root) as props, so all the props of of the root are extended onto the blockquote. If you would like to add a node as a child, you should use a children array: u('blockquote', remark().parse('x').children)

It’s an interesting case 🤔

Thanks for the clarification.
Works ok, with suggested updates.

Good, I’m glad!