A command-line tool that searches for identifier patterns in JavaScript files using AST parsing.
A "hello world" to familiarize the ULL PL students with AST-based code analysis. It introduces espree, estraverse, commander, regular expressions and typescript. See crguezl PL 24/25 course book, section"Introduction to Espree" for a JS version and more detailed introduction to espree and estraverse.
- Install nvm and node or open the repo in a GH codespace
- Install dependencies:
npm install
- Build the project:
npm run build
- Run the tool on the example file:
npm start
node dist/idgrep.js -p "your_pattern" file1.js file2.jsnpm run build- Compile TypeScript to JavaScriptnpm run dev- Watch mode for development (auto-recompile on changes)npm start- Run the compiled version
src/- TypeScript source files[index.ts](src/index.ts)- Main CLI applicationidgrep.ts- Search library
dist/- Output folderdist/hacky.js- Input exampletsconfig.json- TypeScript configuration with strict type checkingpackage.json- Project dependencies and scripts
Read in detail PL 24/25 course book, section"Introduction to Espree" for a JS version and more detailed introduction to espree and estraverse.