Comments (2)
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.
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)
- Unexpected error HOT 4
- is the CLI supposed to read ts-config.json and or babel configs? HOT 11
- 'import { Button, ...$rest } from "blah"' causes errors HOT 6
- [Feature Request] Ability to use typescript parser/generator instead of babel
- Astx.replace should use withCaptures
- Allow /**/ extraction in templates?
- /**/ extraction doesn't work in (/**/x: X) => {}
- find and replace within submatches has no effect HOT 1
- Distributed app looks to have incorrect compilation HOT 2
- Babel complains about the parser HOT 5
- TypeError: Received an unexpected value [object Array] HOT 5
- VSCode extension? HOT 13
- Allow bypassing the confirmation prompt? HOT 4
- Duplicate code appearing in output HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from astx.