-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Expand API for tree manipulation #5
Comments
Also, what's the use of having the ArrayExpression |
Hey, there's still holes in the API. It is still a young project, and is not complete. Every PR adding new functionnality is welcome! About the push method, you need to pass a code string representing the value. e.g.: array.push("1"); // [ 1 ]
array.push("{ bar: 1 }"); // [{ bar: 1 }]
array.push("'text'"); // [ "text" ] |
Ah, yes of course, thanks. I'd gladly help flesh out the API, but am still a bit unsure about the direction this is going, for instance: would you consider it useful to have node list iteration methods |
Yes, I believe these could be useful. |
Hi there, I haven't forgotten about this, just been swamped with work. I'll be pushing the node iteration later today normally. However, ATM I'm working on providing Is it ok I take a really close look at the entire codebase; which possibly might lead to some substantial changes? |
Hey @creynders, I'm okay with substantial changes, but try to keep them organized in their commits so they're easy to read through. That'll allow easier review and faster merge. Of course, feel free to open issue to discuss some topic that could be separated - or just some changes you're not sure about. |
So, thinking about all of this some more and digging through the code, I'm leaning towards a more versatile API (I hope), something like this: https://gist.github.com/creynders/a7e057922f20c7d188ea |
That mostly looks good to me, but how would you manage it when there's multiple nodes matching a query? And I'm not sure about auto detecting the type of node that is queried. That seems edgy to me as you won't know if |
That's already there:
I'm not sure I get what you mean. As a user of ast-query you won't know what kind of result you're getting? As long as the results are properly typed, it's not really a problem IMO. The main benefit is that it's a lot more flexible: you can do reference counting, etc. |
I wasn't very clear about the multiple nodes. I meant more how it'd be handle in the case of BTW, I added you as collaborator on the repo. |
That depends, I guess. As I see it now, which might change soon enough, there's basically the query function, the different type "classes" and some sort of collection "class" for the nodes, which will iterate through the collection of nodes to call methods directly e.g.
Wow, thanks. I'll create a new dedicated branch to explore where a possibly new API will take us. |
Maybe I'm missing something fundamental here, but it seems the API is very limited with regards to tree manipulation (or the documentation is lacking). E.g. I'd want to replace the arguments of a CallExpression, but the ArrayExpression node only provides methods to add nodes, not remove them. Obviously I can start hacking away and start doing stuff like
methodCall.arguments.nodes[0].pop()
, but that's verrrry yucky.Am I missing the point of your lib, or is this planned, or did I just somehow miss this?
The text was updated successfully, but these errors were encountered: