Skip to content
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

Implement RuleVisitor #412

Closed
bartlomieju opened this issue Oct 18, 2020 · 5 comments · Fixed by #422
Closed

Implement RuleVisitor #412

bartlomieju opened this issue Oct 18, 2020 · 5 comments · Fixed by #422

Comments

@bartlomieju
Copy link
Member

Given problems from #330 it's clear that swc_ecma_visit::Visit is not a great choice for implementing rule.
We should implement RuleVisitor trait that sits on top of swc_ecma_visit::Visit and unconditionally visits
whole tree recursively. It would provide the same API but instead of requiring implementor to visit child nodes
it should visit them automatically after calling RuleVisitor::visit_<node_name>.

CC @magurotuna @kdy1

@kdy1
Copy link
Contributor

kdy1 commented Oct 19, 2020

Maybe I can provide one from swc_ecma_visit. (Or I can add feature to the proc macro)

@bartlomieju
Copy link
Member Author

@kdy1 that would be very useful, if you're fine with having it in SWC, I might look into implementing that in the coming days.

@kdy1
Copy link
Contributor

kdy1 commented Oct 19, 2020

I'm fine with it. Actually I think it's a must for visitor generator, but I was busy working on the type system.

Btw, I'm not sure about the name. Also, there are two way to go. First one is reusing Visit by creating a wrapper struct which accepts Visit as a type parameter will be enough.
Second way is creating a new trait - namely VisitAll.

I think first one would be better, but I'd like to hear opinion about it.

@bartlomieju
Copy link
Member Author

@kdy1 both of the solutions sound good to me, I guess it's a matter of your preference and which one would produce smaller binary ;)

@kdy1
Copy link
Contributor

kdy1 commented Oct 20, 2020

I've created VisitAll and VisutAllWith

See: https://swc.rs/rustdoc/swc_ecma_visit/trait.VisitAll.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants