Giter VIP home page Giter VIP logo

Comments (2)

jedwards1211 avatar jedwards1211 commented on May 28, 2024 1

Hi @alex-from-intuita, thanks for reaching out! Your codemod studio is cool!

Yeah semgrep has a similar pattern language, it seems like it doesn't allow you to replace with patterns or do any codemodding in general though?

grit.io is interesting, I'll have to read more about it. It seems like they need to devote more attention to making a syntax for capturing zero or more AST nodes into a metavariable like astx's $$a (ordered sibling AST nodes) and $$$a (unordered sibling AST nodes). Maybe they have a way to do stuff like that, I don't immediately see one though...

The fact that they have a pattern language that's not just JS/TS is good, there are limitations to defining patterns as pure JS/TS statements or expressions, ideally you want a grammar that's a superset of the programming language's grammar where you can use special pattern language constructs in place of any grammar symbol...

It's hard to say exactly which use cases can't be handled by astx, there's a basic mode where you just find one pattern and replace with another pattern that's obviously fairly limited, but I've put a lot of work into making patterns as powerful as possible. But it also has an API you can use with arbitrary code, here's a basic example and a very complex example. I've put a lot of work into making that API as straightforward to use as I can as well. Theoretically you can do anything with this API but of course it's a question of how easy or difficult it is.

One big limitation is you can't make patterns that only match identifiers of a given TypeScript type, for example $a + $b where $a is a string...that's something I find myself wishing for, and I'm not sure I'd be able to implement anytime soon.

The biggest problem I've run into with JSCodeshift is that recast constantly lags behind the latest language features...for instance I saw recast barf on code that had a TSInstantiationExpression, which is rather new. I've been experimenting with other ways to preserve formatting without using recast, I have a branch that hijacks internal @babel/generator API to do that. I also want to experiment with using a custom Prettier printer to preserve formatting of unmodified nodes. Basically I want something that's guaranteed to just work as long as the backend (Babel or whatever) can parse your code, and I've pretty much given up on having that guarantee with recast.

from astx.

jedwards1211 avatar jedwards1211 commented on May 28, 2024 1

But yeah astx was inspired by jscodeshift and is basically intended to be a much easier-to-use version of it, in all my own codemodding work I use astx instead of jscodeshift now.

Another limitation of the API is you can only search for nodes via patterns right now, I need to add a method to get all nodes of a given type (you can then .filter) so no edge cases are more tricky than using JSCodeshift's API.

from astx.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.