2 ms·
I used multiple libs to do this: codeshift, Babel, TypeScript APIs and AST transversal code, and recently AST Grep. For what I see on the documentation, I like
by diegof79 3y ago
I used multiple libs to do this: codeshift, Babel, TypeScript APIs and AST transversal code, and recently AST Grep.
For what I see on the documentation, I like the simplicity and the Lisp like query language. Definitely I’ll try this tool.
If you are wandering what is my use case: when you maintain a design system it’s very useful to understand how the components are used across projects, so you can prioritize a migration or redesign. Querying using the AST is better than doing many RegExp searches that don’t take into account syntax variants.
- sugarfly 3y agoThank you for your response! If/when you do try it, you're welcome to join us on Discord and share your insights. The use case you describe is a prominent one. I used to write ad-hoc static analysis programs to get at this information, and every time you do this, there's a lot you have to "relearn"; whether it's changes in the spec, or all the AST patterns you need to account for, etc. Burdensome and prone to error, but necessary and ultimately very useful. And in other cases, using a RegExp search could yield thousands of results, more than a human can handle, and you might not be able to narrow them down without fear of missing positives. In both cases, an AST search comes very handy. And now it can be done very quickly too!