https://github.com/anvk/tree-sitter-example
My experimentation with Tree Sitter algorithm in Node.JS
https://github.com/anvk/tree-sitter-example
Last synced: about 1 month ago
JSON representation
My experimentation with Tree Sitter algorithm in Node.JS
- Host: GitHub
- URL: https://github.com/anvk/tree-sitter-example
- Owner: anvk
- License: mit
- Created: 2022-06-18T19:49:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-20T15:38:17.000Z (almost 3 years ago)
- Last Synced: 2025-02-03T12:49:00.128Z (3 months ago)
- Language: TypeScript
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-sitter-example

Small and silly parser based on the [Tree Sitter](https://tree-sitter.github.io/tree-sitter/)
JavaScript parser implementation
## What does it do
This parser will make an attempt to find a specified lib `require` statement and then will find lines in a code for every variable reference (or a particular one if specified) for the object assigned to the require statement.
For Example if you have file `test.js` in the same folder as the script:
```javascript
const path = require('path');module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'bin'),
filename: 'app.bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
filename: './index.html',
template: path.resolve(configDirs.APP_DIR_TEMPLATES, './index.prod.html'),
inject: true,
publicPath: path.join(configDirs.PUBLIC_PATH, 'public'),
}),
new HtmlWebpackInjector(),
],
};
```The following command will find `path` lib `resolve` calls
```
./bin/silly-parser -f ./test.js -l path -p resolve
```Should produce an output:
```
[]AllOccurrences of path referencing resolve:
{
const f = await fs1.readFile('/tmp/somefile.txt');
res.send(f.toString('utf-8'));
});
```Calling `./bin/silly-parser -f ../examples/example1.js -l fs/promises -p readFile` would yield no results because of the `const fs1 = fs;` line
Also more tests are required
Also it is not published to NPM. This CLI command cannot be installed using `npm install -g`
## License
MIT license; see [LICENSE](./LICENSE).