Skip to content

Introduce a mechanism to duplicate/clone a node and all it's children? #560

Open

Description

@ioquatix

When manipulating ASTs using nodes, sometimes you need to copy parts of the AST to a different place or part of the document.

The most naive approach I can think of is converting a document to a markdown string and parsing it again, but I'm sure there are subtle differences. It might be good for an initial implementation.

It might be nice to introduce a clone function which takes a node and returns a copy, including all children.

Activity

  1. jgm commented on Aug 22, 2024

    @jgm
    Member

    This seems reasonable to me. @nwellnhof what do you think?

  2. nwellnhof commented on Aug 28, 2024

    @nwellnhof
    Contributor

    The most naive approach I can think of is converting a document to a markdown string and parsing it again, but I'm sure there are subtle differences.

    This should result in a perfect copy (except for source positions), but it's inefficient. A clone function certainly seems useful.

  3. ioquatix commented on Aug 28, 2024

    @ioquatix
    ContributorAuthor

    Okay can I submit a PR?

  4. jgm commented on Aug 28, 2024

    @jgm
    Member

    Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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