Replies: 1 comment
-
You can use rewriter and replace |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to match part of code with meta-variables and let
ast-grep
rewrite the variables while keeping other parts of the matched code untouched? The use case for this is syntax-aware patching where I want to match the exact AST surrounding the code I want to patch.The issue I'm facing right now is that I should rewrite the template as is to add something new in the
fix
part, instead of just modifying the variable.Consider this example (playground link):
I want to add new code after
const a = getA();
line, but beforeif (a == 333) {
. Right now to do this I had to write this config:As you can see, I had to mostly duplicate the matched code in the
fix
part. What I'd like to have is something likeedit
functionality:Does
ast-grep
support this in some way? What are my options here? Any advice would be greatly appreciated!Beta Was this translation helpful? Give feedback.
All reactions