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
File node #91
Comments
I don't understand this request at all. |
How about asking for clarification then? You have a visitor. You need to traverse a tree. If you want to visit |
I've written a few different kinds of visitors for trees, and I have never had to introduce an extra node to visit the root node. Why does a node have to have a parent to be visited? |
Have you never had to replace the root node? |
I'm also not sure it's required as proper solution on spec level. If you add yet another root node, you just wrap the old problem and get new one as one day you might want to replace the |
@RReverser There's no reason to touch |
Just like
Also - I know this was addressed to @michaelficarra, but hadn't such experience really. Usually either manipulating Can you please show any example where having yet another top-level wrapper would be necessary? |
Not really.
That's if Also I'm not really trying imposing this on anyone, just wanting to get feedback. I'd rather not have to make an AST superset if possible so was just probing whether or not anyone else sees the merit in standardising it. |
ESLint uses the visitor pattern and is able to visit the Program node. I haven't encountered a need for a root node above it in order to accomplish this. 👎 I think this is really just an implementation detail and shouldn't be part of the spec. |
Isn't that what you're asking for |
Ok closing this as the consensus seems to be against this. To address the remaining points:
It's not comparable since
Not really comparable. Completely different requirements and ESLint rule visitors don't even get access to the When you're doing code transforms there's usually a lot of metaprogramming to reduce repetition and increase stability so having the AST be very neutral (eg. always having a |
I'm just curious, can you explain in what use case(s) would you need to replace the |
@getify When you're replacing a set of nodes from a map of others. Having to special case root nodes and replace their props is bizarre. The main reason for the |
@sebmck In my visitors, I usually pass in a list of ancestors. An empty list for the root node's ancestors is just fine. |
Also thanks for the discussion guys, I'll just leave it as footnote in the Babel docs or something justifying it's existence. @michaelficarra It's mostly due to one of the requirements of my visitor pattern where it's very strict about relationships so you can accurately resolve a node. I've abstracted a node's position in the tree with a "path", very similar to the one in ast-types. The biggest benefit of this that I've found, is that it allows you to easily do type inference, constant folding, dead code elimination and more on an AST easily without any other intermediary format (SSA etc). This is mostly because you can "jump" around the AST easily just by referencing these paths since they're always absolute as they react to tree changes. |
I was asking, when would you need to do this to the |
@getify The entire thing. You may be dealing with transforms that don't care what nodes they touch (minification etc, there are many scenarios I've found where transforms are node-agnostic). Or even more commonly, you may just be dealing with |
Note that ESTree doesn't define |
@RReverser |
You pointed to |
@RReverser I was pointing at that it's not unreasonable to need the parent of a node to establish context. This is a pretty big philosophical concept of ESTree that has been discussed numerous times before and is even in the philosophy section of the README:
|
Sure, but "I don't want to check
In this case it's less obvious, but still |
That was not the crux of my reasoning. It fundamentally pollutes how my Unsure why the points I raised are still being debated when I already
I wasn't using that to justify the existence of a File node, I think I've On Friday, 12 June 2015, Ingvar Stepanyan notifications@github.com wrote:
Sebastian McKenzie |
So in order for
Program
to qualify for visiting in the common node-parent pattern, aFile
node is required in order to wrapProgram
so it can be visited. This is a node used by Babel and recast etc. Would there be any objection to including this in the ESTree specification? It doesn't necessarily have to be compulsory and can be purely optional.The text was updated successfully, but these errors were encountered: