An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# tree-sitter-example

![Tree house image](https://tree-sitter.github.io/tree-sitter/assets/images/tree-sitter-small.png 'Tree house image')

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).