KilnVM Live Labs /lab/ast-grep-structural-search-lab
Step 1 of 3 Docs Build Your Own

AST Structural Code Search and Refactoring with ast-grep

Match JavaScript function calls by syntax tree with ast-grep, inspect structured JSON matches, and rewrite legacy console.log calls to logger.info offline.

Step 1 of 3

Find real console.log AST calls across src/

src/checkout.js contains two live console.log(...) calls and one decoy inside a comment. Use ast-grep run with --json to extract only real AST calls into matches.json:

bash
ast-grep run -p 'console.log($$$ARGS)' -l javascript --json src/ > matches.json && grep -c '"file"' matches.json

Click Check Step to continue.