Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

ast utility function to create selector from passing a root and a leaf node. #2

Closed
lifeiscontent opened this issue Feb 3, 2018 · 4 comments
Labels
🧘 status/waiting This may go somewhere but needs more information 💬 type/discussion This is a request for comments

Comments

@lifeiscontent
Copy link

lifeiscontent commented Feb 3, 2018

it would be nice to have a utility to create a selector from a root.

E.g. selectorFromTree(root, node); // returns html > body > div:nth-child(1) > h1

which in turn you could then use something like https://github.com/syntax-tree/hast-util-select

later to find that same node.

the use case I'm using this for is dragging and dropping AST Nodes in a tree and looking them up by paths for mutation of the AST.

CC: @wooorm

I would personally work on this, but I don't think I know enough about AST manipulation to write a helper like this efficiently.

@wooorm wooorm added the concept label May 11, 2018
@wooorm
Copy link
Member

wooorm commented Jul 22, 2018

Sorry I never responded (other than an emoji), but I think this is cool! Still up for building it, or anyone else?

How can I help?

@lifeiscontent
Copy link
Author

@wooorm if you can either teach me how to write a function that traverses the AST, or maybe we could pair and I could setup the expectations for the function?

@wooorm wooorm added 🧘 status/waiting This may go somewhere but needs more information 💬 type/discussion This is a request for comments and removed concept labels Aug 10, 2019
@ChristianMurphy
Copy link
Member

@lifeiscontent you could use https://unifiedjs.com/explore/package/unist-util-visit-parents as a building block or as a template for walking the tree.

@lifeiscontent lifeiscontent reopened this Jan 3, 2020
@ChristianMurphy
Copy link
Member

Thanks for starting the discussion @lifeiscontent!
We're in the process unifying ideas in with discussions unifiedjs/collective#44
If you'd like to continue this thread, or start a new one https://github.com/syntax-tree/unist/discussions/categories/ideas will be the home for ideas going forward.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧘 status/waiting This may go somewhere but needs more information 💬 type/discussion This is a request for comments
Development

No branches or pull requests

3 participants